pgkiln 0.71.0 → 0.73.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.
- package/db/migrations/139_opentelemetry.sql +36 -0
- package/db/migrations/140_item_region_types.sql +27 -0
- package/docs/apex-feature-parity.md +86 -9
- package/docs/guide/01-installation.md +108 -0
- package/docs/guide/03-builder.md +9 -0
- package/docs/guide/04-pages-and-regions.md +41 -1
- package/docs/guide/05-items.md +43 -3
- package/docs/guide/09-reference.md +3 -0
- package/docs/guide/11-from-apex.md +3 -0
- package/docs/guide/12-development.md +23 -2
- package/examples/hr/hr_75_item_region_types.sql +81 -0
- package/package.json +1 -1
- package/public/app.css +48 -0
- package/public/app.js +427 -1
- package/public/builder.css +3 -0
- package/src/ai/service.ts +14 -0
- package/src/app.ts +10 -0
- package/src/builder/advisor.ts +5 -1
- package/src/builder/arrange.ts +7 -0
- package/src/builder/components.ts +5 -5
- package/src/builder/designer.ts +8 -2
- package/src/builder/home.ts +1 -0
- package/src/builder/i18n/de.ts +8 -0
- package/src/builder/i18n/en.ts +8 -0
- package/src/builder/i18n/es.ts +8 -0
- package/src/builder/i18n/fr.ts +8 -0
- package/src/builder/i18n/it.ts +8 -0
- package/src/builder/i18n/ja.ts +8 -0
- package/src/builder/i18n/ko.ts +8 -0
- package/src/builder/i18n/nl.ts +8 -0
- package/src/builder/i18n/pt.ts +8 -0
- package/src/builder/i18n/zh-cn.ts +8 -0
- package/src/builder/i18n/zh-tw.ts +8 -0
- package/src/builder/region-help.ts +8 -2
- package/src/builder/telemetry.ts +206 -0
- package/src/builder/workspaces.ts +2 -1
- package/src/i18n/ar.ts +13 -0
- package/src/i18n/cs.ts +13 -0
- package/src/i18n/da.ts +13 -0
- package/src/i18n/de.ts +13 -0
- package/src/i18n/el.ts +13 -0
- package/src/i18n/es.ts +13 -0
- package/src/i18n/fi.ts +13 -0
- package/src/i18n/fr.ts +13 -0
- package/src/i18n/he.ts +13 -0
- package/src/i18n/it.ts +13 -0
- package/src/i18n/ja.ts +13 -0
- package/src/i18n/ko.ts +13 -0
- package/src/i18n/nb.ts +13 -0
- package/src/i18n/pl.ts +13 -0
- package/src/i18n/pt.ts +13 -0
- package/src/i18n/ru.ts +13 -0
- package/src/i18n/sv.ts +13 -0
- package/src/i18n/tr.ts +13 -0
- package/src/i18n/uk.ts +13 -0
- package/src/i18n/zh.ts +13 -0
- package/src/i18n.ts +26 -0
- package/src/instance-checks.ts +11 -4
- package/src/layout.ts +2 -1
- package/src/mail/mail.ts +14 -0
- package/src/metadata.ts +5 -2
- package/src/runtime/ai-agents.ts +9 -0
- package/src/runtime/items.ts +32 -3
- package/src/runtime/page-regions.ts +50 -0
- package/src/runtime/region-cache.ts +1 -1
- package/src/runtime/regions.ts +11 -0
- package/src/runtime/render.ts +3 -17
- package/src/runtime/report.ts +55 -3
- package/src/runtime/routes.ts +3 -0
- package/src/session.ts +26 -0
- package/src/telemetry/browser.ts +91 -0
- package/src/telemetry/config.ts +342 -0
- package/src/telemetry/export.ts +484 -0
- package/src/telemetry/http.ts +126 -0
- package/src/telemetry/trace.ts +456 -0
- package/src/webclient.ts +25 -0
- package/src/workflow.ts +14 -7
package/src/i18n/zh.ts
CHANGED
|
@@ -424,6 +424,19 @@ export const zh: Record<MessageKey, string> = {
|
|
|
424
424
|
'lov.loading': "正在加载更多…",
|
|
425
425
|
'da.wait': "请稍候…",
|
|
426
426
|
'lov.no_rows': "未找到任何内容。",
|
|
427
|
+
'shuttle.available': "可选",
|
|
428
|
+
'shuttle.chosen': "已选",
|
|
429
|
+
'shuttle.move': "移入",
|
|
430
|
+
'shuttle.move_all': "全部移入",
|
|
431
|
+
'shuttle.remove': "移除",
|
|
432
|
+
'shuttle.remove_all': "全部移除",
|
|
433
|
+
'shuttle.up': "上移",
|
|
434
|
+
'shuttle.down': "下移",
|
|
435
|
+
'shuttle.top': "移到顶部",
|
|
436
|
+
'shuttle.bottom': "移到底部",
|
|
437
|
+
'shuttle.filter': "筛选",
|
|
438
|
+
'region.breadcrumb': "面包屑导航",
|
|
439
|
+
'region.no_help': "此页面没有帮助信息。",
|
|
427
440
|
'search.did_you_mean': "您是不是要找:",
|
|
428
441
|
'error.lov_value': "{label}:请从列表中选择一个值。",
|
|
429
442
|
'item.yes': "是",
|
package/src/i18n.ts
CHANGED
|
@@ -451,6 +451,19 @@ const en = {
|
|
|
451
451
|
'lov.loading': 'Loading more…',
|
|
452
452
|
'da.wait': 'Please wait…',
|
|
453
453
|
'lov.no_rows': 'Nothing found.',
|
|
454
|
+
'shuttle.available': 'Available',
|
|
455
|
+
'shuttle.chosen': 'Selected',
|
|
456
|
+
'shuttle.move': 'Move',
|
|
457
|
+
'shuttle.move_all': 'Move all',
|
|
458
|
+
'shuttle.remove': 'Remove',
|
|
459
|
+
'shuttle.remove_all': 'Remove all',
|
|
460
|
+
'shuttle.up': 'Move up',
|
|
461
|
+
'shuttle.down': 'Move down',
|
|
462
|
+
'shuttle.top': 'Move to top',
|
|
463
|
+
'shuttle.bottom': 'Move to bottom',
|
|
464
|
+
'shuttle.filter': 'Filter',
|
|
465
|
+
'region.breadcrumb': 'Breadcrumb',
|
|
466
|
+
'region.no_help': 'No help is available for this page.',
|
|
454
467
|
'search.did_you_mean': 'Did you mean:',
|
|
455
468
|
'error.lov_value': '{label}: choose a value from the list.',
|
|
456
469
|
'item.yes': 'Yes',
|
|
@@ -1319,6 +1332,19 @@ const nl: Record<MessageKey, string> = {
|
|
|
1319
1332
|
'lov.loading': 'Meer laden…',
|
|
1320
1333
|
'da.wait': 'Even geduld…',
|
|
1321
1334
|
'lov.no_rows': 'Niets gevonden.',
|
|
1335
|
+
'shuttle.available': 'Beschikbaar',
|
|
1336
|
+
'shuttle.chosen': 'Gekozen',
|
|
1337
|
+
'shuttle.move': 'Verplaatsen',
|
|
1338
|
+
'shuttle.move_all': 'Alles verplaatsen',
|
|
1339
|
+
'shuttle.remove': 'Verwijderen',
|
|
1340
|
+
'shuttle.remove_all': 'Alles verwijderen',
|
|
1341
|
+
'shuttle.up': 'Omhoog',
|
|
1342
|
+
'shuttle.down': 'Omlaag',
|
|
1343
|
+
'shuttle.top': 'Bovenaan',
|
|
1344
|
+
'shuttle.bottom': 'Onderaan',
|
|
1345
|
+
'shuttle.filter': 'Filteren',
|
|
1346
|
+
'region.breadcrumb': 'Kruimelpad',
|
|
1347
|
+
'region.no_help': 'Er is geen help voor deze pagina.',
|
|
1322
1348
|
'search.did_you_mean': 'Bedoelde u:',
|
|
1323
1349
|
'error.lov_value': '{label}: kies een waarde uit de lijst.',
|
|
1324
1350
|
'item.yes': 'Ja',
|
package/src/instance-checks.ts
CHANGED
|
@@ -36,16 +36,23 @@ export interface SecretColumn {
|
|
|
36
36
|
schema: string;
|
|
37
37
|
table: string;
|
|
38
38
|
column: string;
|
|
39
|
+
/** (sprint 139) only the rows that match (meta.setting: the settings named *_enc) */
|
|
40
|
+
where?: string;
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
/** (sprint 139) instance settings that hold a secret: meta.instance_setting rows named *_enc (otel_headers_enc) */
|
|
44
|
+
const SETTING_SECRETS: SecretColumn = { schema: 'meta', table: 'instance_setting', column: 'value', where: `name like '%\\_enc'` };
|
|
45
|
+
|
|
41
46
|
export async function encryptedColumns(): Promise<SecretColumn[]> {
|
|
42
|
-
return (await owner.query<SecretColumn>(
|
|
47
|
+
return [...(await owner.query<SecretColumn>(
|
|
43
48
|
`select table_schema as schema, table_name as table, column_name as column from information_schema.columns
|
|
44
49
|
where table_schema = 'meta' and data_type = 'text'
|
|
45
50
|
and (column_name like '%\\_enc' or (table_name = 'push_key' and column_name = 'private_key'))
|
|
46
|
-
order by 2, 3`)).rows;
|
|
51
|
+
order by 2, 3`)).rows, SETTING_SECRETS];
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
const rowsOf = (c: SecretColumn) => `${quoteIdent(c.column)} is not null${c.where ? ` and (${c.where})` : ''}`;
|
|
55
|
+
|
|
49
56
|
const quoteIdent = (s: string) => `"${s.replace(/"/g, '""')}"`;
|
|
50
57
|
const tableOf = (c: SecretColumn) => `${quoteIdent(c.schema)}.${quoteIdent(c.table)}`;
|
|
51
58
|
|
|
@@ -54,7 +61,7 @@ export async function secretStatus(withKey?: string) {
|
|
|
54
61
|
const out: (SecretColumn & { stored: number; unreadable: number })[] = [];
|
|
55
62
|
const usable = (withKey ?? process.env.PGKILN_SECRET_KEY ?? '').length >= 32;
|
|
56
63
|
for (const c of await encryptedColumns()) {
|
|
57
|
-
const rows = (await owner.query<{ v: string }>(`select ${quoteIdent(c.column)} as v from ${tableOf(c)} where ${
|
|
64
|
+
const rows = (await owner.query<{ v: string }>(`select ${quoteIdent(c.column)} as v from ${tableOf(c)} where ${rowsOf(c)}`)).rows;
|
|
58
65
|
let unreadable = 0;
|
|
59
66
|
for (const r of rows) {
|
|
60
67
|
try {
|
|
@@ -228,7 +235,7 @@ export async function rotateKey(oldKey: string, newKey: string, { dryRun = false
|
|
|
228
235
|
const failed: string[] = [];
|
|
229
236
|
for (const col of cols) {
|
|
230
237
|
const rows = (await c.query<{ ctid: string; v: string }>(
|
|
231
|
-
`select ctid::text as ctid, ${quoteIdent(col.column)} as v from ${tableOf(col)} where ${
|
|
238
|
+
`select ctid::text as ctid, ${quoteIdent(col.column)} as v from ${tableOf(col)} where ${rowsOf(col)} for update`)).rows;
|
|
232
239
|
let rotated = 0;
|
|
233
240
|
let already = 0;
|
|
234
241
|
for (const r of rows) {
|
package/src/layout.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html, type Raw } from './html.ts';
|
|
2
2
|
import { staticUrl } from './static-version.ts';
|
|
3
|
+
import { browserTraceMeta } from './telemetry/browser.ts';
|
|
3
4
|
|
|
4
5
|
/** Attributes of <html>: language, text direction and a fixed theme (light/dark; absent = follow the OS). */
|
|
5
6
|
export interface RootAttrs {
|
|
@@ -20,7 +21,7 @@ export function documentShell(title: string, body: Raw, bodyClass = '', data: Re
|
|
|
20
21
|
<title>${title}</title>
|
|
21
22
|
<link rel="stylesheet" href="${staticUrl('app.css')}">
|
|
22
23
|
<script src="${staticUrl('app.js')}" defer></script>
|
|
23
|
-
${head}
|
|
24
|
+
${browserTraceMeta()}${head}
|
|
24
25
|
</head>
|
|
25
26
|
<body class="${bodyClass}"${attrs}>
|
|
26
27
|
${body}
|
package/src/mail/mail.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { owner } from '../db.ts';
|
|
|
14
14
|
import { decryptSecret } from '../secrets.ts';
|
|
15
15
|
import { mailHostAddress, scopeForWorkspace } from '../network-acl.ts';
|
|
16
16
|
import { deliver, MailError, verifyConnection, type OutgoingMail, type Provider, type ServiceSettings } from './providers.ts';
|
|
17
|
+
import { count, markError, rootSpan, setAttrs, traceApp } from '../telemetry/trace.ts';
|
|
17
18
|
|
|
18
19
|
export interface MailService {
|
|
19
20
|
id: number;
|
|
@@ -95,6 +96,14 @@ interface Claimed {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
async function sendOne(m: Claimed) {
|
|
99
|
+
// (sprint 139, AP-6) each attempt a trace of its own (or a span of the request that sends at once)
|
|
100
|
+
return rootSpan('mail send', { 'pgkiln.mail.id': String(m.id), 'pgkiln.mail.attempt': m.attempts }, async () => {
|
|
101
|
+
traceApp({ appId: m.app_id });
|
|
102
|
+
await sendOneTraced(m);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function sendOneTraced(m: Claimed) {
|
|
98
107
|
// the application's service, else (sprint 118) its workspace's own
|
|
99
108
|
const service = await owner.one<MailService>(`select s.* from meta.mail_service s where s.id = meta.mail_service_for_app($1)`, [m.app_id]);
|
|
100
109
|
const t0 = performance.now();
|
|
@@ -112,10 +121,15 @@ async function sendOne(m: Claimed) {
|
|
|
112
121
|
await owner.query(`update meta.mail_queue set status = 'sent', sent_at = now(), provider_id = $2, service = $3, message = null,
|
|
113
122
|
last_attempt_at = now(), duration_ms = $4, provider = $5 where id = $1`,
|
|
114
123
|
[m.id, id ? String(id).slice(0, 500) : null, service.name, ms, provider]);
|
|
124
|
+
setAttrs({ 'pgkiln.mail.provider': provider, 'pgkiln.mail.service': service.name });
|
|
125
|
+
count('pgkiln.mail.sent', { status: 'sent' });
|
|
115
126
|
} catch (e) {
|
|
116
127
|
const retry = e instanceof MailError ? e.retry : true;
|
|
117
128
|
const message = (e as Error).message.slice(0, 2000);
|
|
118
129
|
const [ms, provider] = timing();
|
|
130
|
+
setAttrs({ 'pgkiln.mail.provider': provider, 'pgkiln.mail.service': service?.name ?? null, 'pgkiln.mail.retry': retry && m.attempts < ATTEMPTS });
|
|
131
|
+
markError(message);
|
|
132
|
+
count('pgkiln.mail.sent', { status: retry && m.attempts < ATTEMPTS ? 'retry' : 'error' });
|
|
119
133
|
if (retry && m.attempts < ATTEMPTS)
|
|
120
134
|
await owner.query(`update meta.mail_queue set status = 'queued', not_before = now() + make_interval(mins => $2), message = $3, service = $4,
|
|
121
135
|
last_attempt_at = now(), duration_ms = $5, provider = $6 where id = $1`,
|
package/src/metadata.ts
CHANGED
|
@@ -159,7 +159,7 @@ export interface Region {
|
|
|
159
159
|
title: string | null;
|
|
160
160
|
/** (0.31, 073) optional, unique on the page */
|
|
161
161
|
static_id?: string | null;
|
|
162
|
-
type: 'login' | 'report' | 'form' | 'chart' | 'cards' | 'static' | 'grid' | 'calendar' | 'dynamic' | 'facets' | 'tasks' | 'workflows' | 'map' | 'tree' | 'template_component' | 'smart_filters' | 'display_selector' | 'list' | 'data_reporter' | 'ai_assistant' | 'plugin' | 'url' | 'search' | 'form_designer';
|
|
162
|
+
type: 'login' | 'report' | 'form' | 'chart' | 'cards' | 'static' | 'grid' | 'calendar' | 'dynamic' | 'facets' | 'tasks' | 'workflows' | 'map' | 'tree' | 'template_component' | 'smart_filters' | 'display_selector' | 'list' | 'data_reporter' | 'ai_assistant' | 'plugin' | 'url' | 'search' | 'form_designer' | 'classic_report' | 'breadcrumb' | 'help_text';
|
|
163
163
|
source: string | null;
|
|
164
164
|
table_name: string | null;
|
|
165
165
|
pk_column: string | null;
|
|
@@ -182,6 +182,7 @@ export type ItemType =
|
|
|
182
182
|
| 'checkbox' | 'switch' | 'hidden' | 'display' | 'password'
|
|
183
183
|
| 'checkbox_group' | 'multiselect' | 'popup_lov' | 'email' | 'tel' | 'url' | 'color' | 'file' | 'location'
|
|
184
184
|
| 'richtext' | 'markdown' | 'rating' | 'combobox' | 'daterange' | 'qrcode' | 'plugin'
|
|
185
|
+
| 'shuttle' | 'select_one' | 'select_many'
|
|
185
186
|
// (086) display image, geocoded address
|
|
186
187
|
| 'image' | 'address';
|
|
187
188
|
|
|
@@ -363,6 +364,8 @@ export interface Page extends PageSummary {
|
|
|
363
364
|
warn_unsaved: boolean;
|
|
364
365
|
/** (087) 'minimal': no header and navigation */
|
|
365
366
|
page_template: 'standard' | 'minimal' | 'left_side_column' | 'right_side_column';
|
|
367
|
+
/** (140) the page's help text (Markdown), shown by a help_text region */
|
|
368
|
+
help: string | null;
|
|
366
369
|
}
|
|
367
370
|
|
|
368
371
|
/** The static files a list of names refers to, in that order, with their version. */
|
|
@@ -406,7 +409,7 @@ export async function loadApp(alias: string) {
|
|
|
406
409
|
export async function loadPage(appId: number, pageNo: number) {
|
|
407
410
|
return runtime.one<Page>(
|
|
408
411
|
`select p.id, p.app_id, p.page_no, p.name, p.title, p.requires_auth, p.parent_page, p.mode,
|
|
409
|
-
p.protection, p.authz, p.warn_unsaved, p.page_template,
|
|
412
|
+
p.protection, p.authz, p.warn_unsaved, p.page_template, p.help,
|
|
410
413
|
${agg('meta.region', 'page_id', 'p', 'p.app_id')} as regions,
|
|
411
414
|
${agg('meta.item', 'page_id', 'p', 'p.app_id')} as items,
|
|
412
415
|
${agg('meta.button', 'page_id', 'p', 'p.app_id')} as buttons,
|
package/src/runtime/ai-agents.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { isAuthorized, pageAllowed } from './authz.ts';
|
|
|
8
8
|
import { bindValues, dbg, publicError, stripSemicolon, type PageContext } from './context.ts';
|
|
9
9
|
import { txContext } from './routes.ts';
|
|
10
10
|
import { retrieve } from './search.ts';
|
|
11
|
+
import { recordSpan } from '../telemetry/trace.ts';
|
|
11
12
|
|
|
12
13
|
// AI agents and AI tools (migration 121; APEX 26.1 / 26.2: Shared Components
|
|
13
14
|
// → AI Agents). Both are lists in meta.app (ai_agents, ai_tools), exported
|
|
@@ -397,6 +398,14 @@ export async function logToolCall(
|
|
|
397
398
|
ctx: PageContext, regionId: number, agent: string | null, tool: string, type: string, input: Record<string, unknown>, out: AgentOutcome, ms: number,
|
|
398
399
|
) {
|
|
399
400
|
const status = out.refused ? 'refused' : out.isError ? 'error' : 'ok';
|
|
401
|
+
// (sprint 139, AP-6) the tool call as a span of the page's trace (its arguments only where values are included)
|
|
402
|
+
recordSpan(`AI tool ${tool}`.slice(0, 120), {
|
|
403
|
+
ms,
|
|
404
|
+
kind: 1,
|
|
405
|
+
attrs: { 'gen_ai.operation.name': 'execute_tool', 'gen_ai.tool.name': tool, 'gen_ai.tool.type': type, 'pgkiln.ai.agent': agent, 'pgkiln.ai.tool.status': status },
|
|
406
|
+
vals: { 'gen_ai.tool.call.arguments': JSON.stringify(input ?? {}).slice(0, 2000) },
|
|
407
|
+
error: status === 'ok' ? null : status,
|
|
408
|
+
});
|
|
400
409
|
let args = JSON.stringify(input ?? {});
|
|
401
410
|
if (args.length > MAX_ARG_CHARS) args = JSON.stringify({ cut_off: args.slice(0, MAX_ARG_CHARS) });
|
|
402
411
|
dbg(ctx, 4, 'ai', () => `AI tool ${tool} (${type}${agent ? `, agent ${agent}` : ''}) ${args} → ${status} in ${Math.round(ms)} ms${out.isError ? `: ${out.content.slice(0, 300)}` : ''}`);
|
package/src/runtime/items.ts
CHANGED
|
@@ -159,7 +159,7 @@ export async function lovContains(ctx: PageContext, lov: string | null, values:
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/** Item types whose posted value must come from their list of values (a combobox takes free text by design). */
|
|
162
|
-
export const LOV_CHECKED = new Set(['select', 'radio', 'checkbox_group', 'multiselect', 'popup_lov']);
|
|
162
|
+
export const LOV_CHECKED = new Set(['select', 'radio', 'checkbox_group', 'multiselect', 'popup_lov', 'shuttle', 'select_one', 'select_many']);
|
|
163
163
|
|
|
164
164
|
/** Rows a list of values reads when its item sets no config.max_rows (1 to 50,000). */
|
|
165
165
|
export const LOV_MAX_ROWS = 5000;
|
|
@@ -168,9 +168,10 @@ export const lovMax = (item: Item, settings?: ComponentSettings) => {
|
|
|
168
168
|
return Number.isFinite(n) && n >= 1 ? Math.min(n, 50_000) : settings ? componentSetting(settings, 'lov_max_rows') : LOV_MAX_ROWS;
|
|
169
169
|
};
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
/** Item types that show a list of values (the Page Designer's "List of values"). */
|
|
172
|
+
export const LOV_TYPES = new Set(['select', 'radio', 'checkbox_group', 'multiselect', 'popup_lov', 'combobox', 'shuttle', 'select_one', 'select_many']);
|
|
172
173
|
const hasLov = (item: Item) => LOV_TYPES.has(item.type) || (item.type === 'display' && !!item.lov);
|
|
173
|
-
export const MULTI_VALUE = new Set(['checkbox_group', 'multiselect']);
|
|
174
|
+
export const MULTI_VALUE = new Set(['checkbox_group', 'multiselect', 'shuttle', 'select_many']);
|
|
174
175
|
/** Multi-value items store their values colon-separated, as in APEX. */
|
|
175
176
|
export const splitValues = (v: string) => (v ? v.split(':') : []);
|
|
176
177
|
|
|
@@ -324,6 +325,34 @@ export async function renderItem(ctx: PageContext, item: Item, hiddenByDa = fals
|
|
|
324
325
|
</select>`;
|
|
325
326
|
break;
|
|
326
327
|
}
|
|
328
|
+
case 'shuttle': {
|
|
329
|
+
// (140; APEX: Shuttle) a <select multiple> that works without JavaScript; app.js turns it into two lists
|
|
330
|
+
// (available, chosen) with move and order buttons. The chosen values keep their order: they come first.
|
|
331
|
+
const chosen = splitValues(value);
|
|
332
|
+
const set = new Set(chosen);
|
|
333
|
+
const indexed = options.map((o, i) => ({ ...o, i }));
|
|
334
|
+
const ordered = [...chosen.flatMap((v) => indexed.filter((o) => o.value === v).slice(0, 1)), ...indexed.filter((o) => !set.has(o.value))];
|
|
335
|
+
const t = ctx.locale.t;
|
|
336
|
+
control = html`<div class="shuttle" data-shuttle="${id}" data-filter-label="${t('shuttle.filter')}" data-available-label="${t('shuttle.available')}" data-chosen-label="${t('shuttle.chosen')}" data-move-label="${t('shuttle.move')}" data-move-all-label="${t('shuttle.move_all')}" data-remove-label="${t('shuttle.remove')}" data-remove-all-label="${t('shuttle.remove_all')}" data-up-label="${t('shuttle.up')}" data-down-label="${t('shuttle.down')}" data-top-label="${t('shuttle.top')}" data-bottom-label="${t('shuttle.bottom')}">
|
|
337
|
+
<select id="${id}" name="${id}" multiple size="${Math.min(Math.max(options.length, 4), 10)}"${aria}>
|
|
338
|
+
${ordered.map((o) => html`<option value="${o.value}" data-i="${o.i}"${set.has(o.value) ? raw(' selected') : ''}>${o.display}</option>`)}
|
|
339
|
+
</select></div>`;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case 'select_one':
|
|
343
|
+
case 'select_many': {
|
|
344
|
+
// (140; APEX 24.2: Select One, Select Many) a <select> (or <select multiple>) that works without JavaScript;
|
|
345
|
+
// app.js adds a search field with a list box that filters the options as one types, and chips for the chosen values
|
|
346
|
+
const many = item.type === 'select_many';
|
|
347
|
+
const chosen = new Set(many ? splitValues(value) : value ? [value] : []);
|
|
348
|
+
const t = ctx.locale.t;
|
|
349
|
+
control = html`<div class="select-pick" data-select-pick="${many ? 'many' : 'one'}" data-search-label="${t('lov.search')}" data-none-label="${t('lov.no_rows')}" data-remove-label="${t('item.tag_remove')}">
|
|
350
|
+
<select id="${id}" name="${id}"${many ? html` multiple size="${Math.min(Math.max(options.length, 3), 8)}"` : ''}${aria}>
|
|
351
|
+
${many || item.config?.null_label === false ? '' : html`<option value="">${item.config?.null_label ?? t('lov.none')}</option>`}
|
|
352
|
+
${options.map((o) => html`<option value="${o.value}"${chosen.has(o.value) ? raw(' selected') : ''}>${o.display}</option>`)}
|
|
353
|
+
</select></div>`;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
327
356
|
case 'popup_lov': {
|
|
328
357
|
// a select list (the LOV's first max_rows rows) that works without JavaScript; app.js
|
|
329
358
|
// turns it into a field with a button that searches the whole LOV on the server
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// (140) Two region types about the page itself: breadcrumb (APEX: Breadcrumb) shows the page's
|
|
2
|
+
// breadcrumb trail, the pages above it by "Breadcrumb parent" (else Home), and help_text (APEX: Help
|
|
3
|
+
// Text) shows the page's help text. The page's title bar shows the trail too, unless the page has a
|
|
4
|
+
// breadcrumb region of its own.
|
|
5
|
+
|
|
6
|
+
import { html, raw, type Raw } from '../html.ts';
|
|
7
|
+
import type { Region } from '../metadata.ts';
|
|
8
|
+
import { markdownHtml } from '../richtext.ts';
|
|
9
|
+
import { pageAllowed } from './authz.ts';
|
|
10
|
+
import { substitute, type PageContext } from './context.ts';
|
|
11
|
+
import { expandShortcuts } from './shortcuts.ts';
|
|
12
|
+
|
|
13
|
+
/** The pages above the current one (at most six), as links the user may follow. */
|
|
14
|
+
export async function breadcrumbLinks(ctx: PageContext): Promise<Raw[]> {
|
|
15
|
+
const trail: { page_no: number; name: string }[] = [];
|
|
16
|
+
let p = ctx.app.pages.find((x) => x.page_no === ctx.page.parent_page);
|
|
17
|
+
for (let guard = 0; p && guard < 6; guard++) {
|
|
18
|
+
trail.unshift(p);
|
|
19
|
+
p = ctx.app.pages.find((x) => x.page_no === p!.parent_page);
|
|
20
|
+
}
|
|
21
|
+
if (!trail.length && ctx.page.page_no !== ctx.app.home_page) {
|
|
22
|
+
const home = ctx.app.pages.find((x) => x.page_no === ctx.app.home_page);
|
|
23
|
+
if (home) trail.push(home);
|
|
24
|
+
}
|
|
25
|
+
const links = [];
|
|
26
|
+
for (const t of trail) if (await pageAllowed(ctx, t.page_no)) links.push(html`<li><a href="${ctx.base}/${t.page_no}">${t.name}</a></li>`);
|
|
27
|
+
return links;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether the page shows a breadcrumb region (then its title bar leaves the trail out). */
|
|
31
|
+
export const hasBreadcrumbRegion = (ctx: PageContext) => ctx.page.regions.some((r) => r.type === 'breadcrumb' && ctx.vis?.regions.has(r.id));
|
|
32
|
+
|
|
33
|
+
/** A breadcrumb region: the trail and ({"current": false} leaves it out) the current page. */
|
|
34
|
+
export async function renderBreadcrumbRegion(ctx: PageContext, r: Region): Promise<Raw> {
|
|
35
|
+
const links = await breadcrumbLinks(ctx);
|
|
36
|
+
const title = substitute(ctx.page.title ?? ctx.page.name, ctx, (v) => v);
|
|
37
|
+
const current = r.config?.current === false ? '' : html`<li><span aria-current="page">${title}</span></li>`;
|
|
38
|
+
return html`<nav class="region-crumbs" aria-label="${r.title || ctx.locale.t('region.breadcrumb')}"><ol class="crumbs">${links}${current}</ol></nav>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Markdown's punctuation, escaped in item values put into a help text (they stay text). */
|
|
42
|
+
const mdEscape = (v: string) => v.replace(/[\\`*_{}[\]()#+\-.!~>|]/g, '\\$&');
|
|
43
|
+
|
|
44
|
+
/** A help text region: the page's help text (Markdown with &ITEM. substitutions), else {"empty": "…"} or "No help…". */
|
|
45
|
+
export async function renderHelpTextRegion(ctx: PageContext, r: Region): Promise<Raw> {
|
|
46
|
+
const help = ctx.page.help?.trim();
|
|
47
|
+
if (!help) return html`<p class="muted help-text-none">${typeof r.config?.empty === 'string' ? r.config.empty : ctx.locale.t('region.no_help')}</p>`;
|
|
48
|
+
const text = substitute(await expandShortcuts(ctx, help, 'text'), ctx, mdEscape);
|
|
49
|
+
return html`<div class="help-text rich-text">${raw(markdownHtml(text))}</div>`;
|
|
50
|
+
}
|
|
@@ -23,7 +23,7 @@ import { bindValues, type PageContext } from './context.ts';
|
|
|
23
23
|
// the placeholder is a link that renders the page with the region (r<id>_load=1).
|
|
24
24
|
|
|
25
25
|
/** Region types that can be cached or loaded lazily (no form state of their own). */
|
|
26
|
-
export const DEFERRABLE = new Set<Region['type']>(['report', 'chart', 'cards', 'dynamic', 'tree', 'template_component']);
|
|
26
|
+
export const DEFERRABLE = new Set<Region['type']>(['report', 'classic_report', 'chart', 'cards', 'dynamic', 'tree', 'template_component']);
|
|
27
27
|
|
|
28
28
|
export interface CacheSetting {
|
|
29
29
|
scope: 'user' | 'session' | 'all';
|
package/src/runtime/regions.ts
CHANGED
|
@@ -37,6 +37,7 @@ import { renderPluginRegion } from './plugins.ts';
|
|
|
37
37
|
import { renderUrlRegion } from './url-region.ts';
|
|
38
38
|
import { renderSearch } from './search.ts';
|
|
39
39
|
import { renderLoginRegion } from './signin.ts';
|
|
40
|
+
import { renderBreadcrumbRegion, renderHelpTextRegion } from './page-regions.ts';
|
|
40
41
|
|
|
41
42
|
// ---------------------------------------------------------------- buttons
|
|
42
43
|
|
|
@@ -335,6 +336,16 @@ async function renderBody(ctx: PageContext, r: Region, hidden: Set<string>): Pro
|
|
|
335
336
|
case 'report':
|
|
336
337
|
body = html`${await renderAiFilter(ctx, r)}${await renderReport(ctx, r, await renderItems(ctx, items, hidden))}`;
|
|
337
338
|
break;
|
|
339
|
+
case 'classic_report':
|
|
340
|
+
// (140) the report renderer without the interactive features (report.ts: classic)
|
|
341
|
+
body = await renderReport(ctx, r, await renderItems(ctx, items, hidden));
|
|
342
|
+
break;
|
|
343
|
+
case 'breadcrumb':
|
|
344
|
+
body = await renderBreadcrumbRegion(ctx, r);
|
|
345
|
+
break;
|
|
346
|
+
case 'help_text':
|
|
347
|
+
body = await renderHelpTextRegion(ctx, r);
|
|
348
|
+
break;
|
|
338
349
|
case 'form':
|
|
339
350
|
body = html`<div class="form-grid">${await renderItems(ctx, items, hidden)}</div>`;
|
|
340
351
|
break;
|
package/src/runtime/render.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { buttonsFor, renderRegion } from './regions.ts';
|
|
|
20
20
|
import { listTree, navbarMarkup, navMarkup } from './lists.ts';
|
|
21
21
|
import { aiInputs, aiOutputs, aiProcessOf } from './ai.ts';
|
|
22
22
|
import { frameOrigins } from './url-region.ts';
|
|
23
|
+
import { breadcrumbLinks, hasBreadcrumbRegion } from './page-regions.ts';
|
|
23
24
|
import { devbarHtml } from './devbar.ts';
|
|
24
25
|
import { feedbackNode } from './feedback.ts';
|
|
25
26
|
import { sessionLimits } from '../session.ts';
|
|
@@ -121,22 +122,6 @@ async function navTree(ctx: PageContext, topNav = false) {
|
|
|
121
122
|
return render(null);
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
async function breadcrumb(ctx: PageContext) {
|
|
125
|
-
const trail: { page_no: number; name: string }[] = [];
|
|
126
|
-
let p = ctx.app.pages.find((x) => x.page_no === ctx.page.parent_page);
|
|
127
|
-
for (let guard = 0; p && guard < 6; guard++) {
|
|
128
|
-
trail.unshift(p);
|
|
129
|
-
p = ctx.app.pages.find((x) => x.page_no === p!.parent_page);
|
|
130
|
-
}
|
|
131
|
-
if (!trail.length && ctx.page.page_no !== ctx.app.home_page) {
|
|
132
|
-
const home = ctx.app.pages.find((x) => x.page_no === ctx.app.home_page);
|
|
133
|
-
if (home) trail.push(home);
|
|
134
|
-
}
|
|
135
|
-
const links = [];
|
|
136
|
-
for (const t of trail) if (await pageAllowed(ctx, t.page_no)) links.push(html`<li><a href="${ctx.base}/${t.page_no}">${t.name}</a></li>`);
|
|
137
|
-
return links;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
125
|
// ---------------------------------------------------------------- theme
|
|
141
126
|
|
|
142
127
|
/** Per-app colours (Theme Roller) and the style variant in use. Only checked values reach the CSS (styles.ts). */
|
|
@@ -392,7 +377,8 @@ export async function renderPage(ctx: PageContext) {
|
|
|
392
377
|
// (078) the origins of the page's URL regions (also those a refresh or lazy load shows later)
|
|
393
378
|
for (const o of frameOrigins(ctx.page.regions.filter((r) => ctx.vis!.regions.has(r.id)))) ctx.frameSrc?.add(o);
|
|
394
379
|
const title = substitute(ctx.page.title ?? ctx.page.name, ctx, (v) => v);
|
|
395
|
-
|
|
380
|
+
// (140) a page with a breadcrumb region shows the trail there instead
|
|
381
|
+
const crumbs = ctx.dialog || hasBreadcrumbRegion(ctx) ? [] : await breadcrumbLinks(ctx);
|
|
396
382
|
const das = dynamicActionsJson(ctx);
|
|
397
383
|
|
|
398
384
|
const main = html`
|
package/src/runtime/report.ts
CHANGED
|
@@ -239,7 +239,10 @@ export function selectionOf(page: { items: { name: string }[] }, r: Region) {
|
|
|
239
239
|
|
|
240
240
|
export function reportState(ctx: PageContext, r: Region): ReportState {
|
|
241
241
|
const p = ctx.params;
|
|
242
|
-
|
|
242
|
+
// (140) a classic report: no rows-per-page choice; "pagination": "none" shows its rows on one page
|
|
243
|
+
const classic = r.type === 'classic_report';
|
|
244
|
+
const size = classic && r.config.pagination === 'none' ? Math.min(maxRows(r, 500) ?? 500, 500)
|
|
245
|
+
: (!classic && parseInt(p.get(key(r, 'n')) ?? '', 10)) || Number(r.config.page_size) || componentSetting(ctx.app.component_settings, 'report_rows');
|
|
243
246
|
const st: ReportState = {
|
|
244
247
|
search: (p.get(key(r, 'q')) ?? '').trim(),
|
|
245
248
|
searchCol: (p.get(key(r, 'qc')) ?? '').trim() || null,
|
|
@@ -288,6 +291,13 @@ export function reportState(ctx: PageContext, r: Region): ReportState {
|
|
|
288
291
|
seek: null as Seek | null,
|
|
289
292
|
};
|
|
290
293
|
st.seek = parseSeek(ctx, r, st);
|
|
294
|
+
// (140) a classic report has none of an interactive report's settings: sorting, paging and (when searchable) the search only
|
|
295
|
+
if (classic) {
|
|
296
|
+
Object.assign(st, { searchCol: null, hideCols: [], filters: [], breakCol: null, aggregates: [], highlights: [], computations: [], view: 'report',
|
|
297
|
+
groupBy: { columns: [], functions: [] }, pivot: null, chart: null, area: null, near: null });
|
|
298
|
+
if (r.config.searchable !== true) st.search = '';
|
|
299
|
+
if (r.config.pagination === 'none') st.page = 1;
|
|
300
|
+
}
|
|
291
301
|
return st;
|
|
292
302
|
}
|
|
293
303
|
|
|
@@ -814,8 +824,10 @@ export async function renderReport(ctx: PageContext, r: Region, filterItems: Raw
|
|
|
814
824
|
const t = ctx.locale.t;
|
|
815
825
|
const c = ctx.client!;
|
|
816
826
|
const st = reportState(ctx, r);
|
|
817
|
-
|
|
818
|
-
const
|
|
827
|
+
// (140; APEX: Classic Report) no Actions menu, column menus or saved reports; a search field only with {"searchable": true}
|
|
828
|
+
const classic = r.type === 'classic_report';
|
|
829
|
+
const searchable = classic ? r.config.searchable === true : r.config.searchable !== false;
|
|
830
|
+
const interactive = !classic && r.config.interactive !== false && searchable;
|
|
819
831
|
// (sprint 78; APEX: a faceted search's results have no search bar) one search field: the facets'
|
|
820
832
|
const searchBox = !ctx.page.regions.some((x) => x.type === 'facets' && x.config.search === true && Number(x.config.report) === r.id && ctx.vis?.regions.has(x.id) !== false);
|
|
821
833
|
|
|
@@ -1193,6 +1205,17 @@ export async function renderReport(ctx: PageContext, r: Region, filterItems: Raw
|
|
|
1193
1205
|
? html`<p class="sel-count muted" data-sel-count="${r.id}" aria-live="polite">${selected.size ? t('report.selected_count', { n: selected.size }) : ''}</p>
|
|
1194
1206
|
${elsewhere.map((v) => html`<input type="hidden" name="${selection!.item}" value="${v}" data-sel-other>`)}`
|
|
1195
1207
|
: '';
|
|
1208
|
+
if (classic) {
|
|
1209
|
+
const pager = r.config.pagination === 'none'
|
|
1210
|
+
? (info.more ? html`<p class="region-limit">${t('region.first_rows', { n: st.size })}</p>` : '')
|
|
1211
|
+
: info.more || info.page > 1 || searchable ? pagerNav(ctx, r, info) : '';
|
|
1212
|
+
const shaped = classicTemplate(ctx, r, cols, info.rows, fmtOf, linkIdx >= 0 ? (row) => linkAttrs(ctx, link!.page, rowItems(row)) : null);
|
|
1213
|
+
if (shaped) return html`${toolbar}${shaped}${pager}`;
|
|
1214
|
+
return html`${toolbar}<div class="table-wrap"><table class="report report-classic${r.config.mobile === 'scroll' ? '' : ' report-reflow'}">
|
|
1215
|
+
<thead><tr>${header}</tr></thead>
|
|
1216
|
+
<tbody>${body.length ? body : html`<tr><td colspan="${cols.length + lead || 1}" class="empty">${empty}</td></tr>`}</tbody>
|
|
1217
|
+
</table></div>${pager}`;
|
|
1218
|
+
}
|
|
1196
1219
|
return html`${toolbar}${switcher}${errors}${selectionNote}
|
|
1197
1220
|
<div class="table-wrap"><table class="report${r.config.mobile === 'scroll' ? '' : ' report-reflow'}"${selIdx >= 0 ? raw(` data-sel-region="${r.id}"`) : ''}>
|
|
1198
1221
|
<thead><tr>${header}</tr></thead>
|
|
@@ -1201,3 +1224,32 @@ export async function renderReport(ctx: PageContext, r: Region, filterItems: Raw
|
|
|
1201
1224
|
</table></div>
|
|
1202
1225
|
${info.more || info.page > 1 || searchable ? pagerNav(ctx, r, info) : ''}`;
|
|
1203
1226
|
}
|
|
1227
|
+
|
|
1228
|
+
/** (140) A classic report's templates besides the table ({"report_template": …}). */
|
|
1229
|
+
export const CLASSIC_TEMPLATES = ['standard', 'value_pairs', 'badges', 'media_list'] as const;
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* (140; APEX: the classic report templates Value Attribute Pairs, Badge List and Media List) The rows in another shape
|
|
1233
|
+
* than a table; null for the table ("standard"). value_pairs: each row as headings and values; badges: the first column
|
|
1234
|
+
* as the label and the second as the value; media_list: a title (column title, else the first) and a text (column
|
|
1235
|
+
* description, text or body, else the second), the title a link when the report has one.
|
|
1236
|
+
*/
|
|
1237
|
+
function classicTemplate(ctx: PageContext, r: Region, cols: { f: pg.FieldDef; i: number }[], rows: unknown[][], fmtOf: (name: string) => Formatter,
|
|
1238
|
+
linkOf: ((row: unknown[]) => Raw) | null): Raw | null {
|
|
1239
|
+
const tpl = r.config.report_template;
|
|
1240
|
+
if (!tpl || tpl === 'standard' || !(CLASSIC_TEMPLATES as readonly string[]).includes(tpl)) return null;
|
|
1241
|
+
const text = (row: unknown[], c: { f: pg.FieldDef; i: number } | undefined) => (c ? cell(row[c.i], c.f.dataTypeID, fmtOf(c.f.name)) : '');
|
|
1242
|
+
if (!rows.length) return html`<p class="empty">${r.config.empty ?? ctx.locale.t('report.no_data')}</p>`;
|
|
1243
|
+
if (tpl === 'value_pairs')
|
|
1244
|
+
return html`<div class="cr-pairs">${rows.map((row) => html`<dl>${cols.map((c) => html`<dt>${headingOf(r, c.f.name, ctx.locale.tr)}</dt><dd>${text(row, c)}</dd>`)}</dl>`)}</div>`;
|
|
1245
|
+
if (tpl === 'badges')
|
|
1246
|
+
return html`<ul class="cr-badges">${rows.map((row) => {
|
|
1247
|
+
const inner = html`<span class="cr-badge-value">${text(row, cols[1] ?? cols[0])}</span><span class="cr-badge-label">${cols[1] ? text(row, cols[0]) : ''}</span>`;
|
|
1248
|
+
return html`<li>${linkOf ? html`<a ${linkOf(row)}>${inner}</a>` : inner}</li>`;
|
|
1249
|
+
})}</ul>`;
|
|
1250
|
+
const named = (...names: string[]) => cols.find((c) => names.includes(c.f.name.toLowerCase()));
|
|
1251
|
+
const titleCol = named('title') ?? cols[0];
|
|
1252
|
+
const textCol = named('description', 'text', 'body') ?? cols.find((c) => c !== titleCol);
|
|
1253
|
+
return html`<ul class="cr-media">${rows.map((row) => html`<li><div class="cr-media-title">${linkOf ? html`<a ${linkOf(row)}>${text(row, titleCol)}</a>` : text(row, titleCol)}</div>${
|
|
1254
|
+
textCol ? html`<p class="cr-media-text">${text(row, textCol)}</p>` : ''}</li>`)}</ul>`;
|
|
1255
|
+
}
|
package/src/runtime/routes.ts
CHANGED
|
@@ -55,6 +55,7 @@ import { availabilityRefusal } from './availability.ts';
|
|
|
55
55
|
import { feedbackRoutes } from './feedback.ts';
|
|
56
56
|
import { dataItemRoutes, loadPreferences, savePreferences } from './data-items.ts';
|
|
57
57
|
import { ajaxRoutes } from './ajax.ts';
|
|
58
|
+
import { traceApp } from '../telemetry/trace.ts';
|
|
58
59
|
|
|
59
60
|
const XLSX_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
60
61
|
|
|
@@ -266,6 +267,8 @@ export async function loadContext(req: Req, reply: FastifyReply, { json = false,
|
|
|
266
267
|
if (!page) return simplePage(reply, 404, locale.t('error.not_found'), locale.t('error.page_not_found', { page: req.params.page, app: app.name }), base, locale), null;
|
|
267
268
|
if (locale.lang !== app.language) translatePage(page, locale.tr);
|
|
268
269
|
const user = app.authentication === 'none' ? 'nobody' : (session.username ?? 'nobody');
|
|
270
|
+
// (sprint 139, AP-6) the request's trace: which application (its workspace decides where it goes), page and user
|
|
271
|
+
await traceApp({ appId: app.id, alias: app.alias, page: page.page_no, user });
|
|
269
272
|
|
|
270
273
|
if (app.authentication !== 'none' && (page.requires_auth || fixedPage) && !session.username) {
|
|
271
274
|
if (json) reply.code(401).send({ error: locale.t('error.session_ended') });
|
package/src/session.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import { count, emitLog } from './telemetry/trace.ts';
|
|
3
|
+
import { appOf } from './telemetry/config.ts';
|
|
2
4
|
import { runtime, sharedRuntime } from './db.ts';
|
|
3
5
|
import { runtimeForApp } from './workspace-db.ts';
|
|
4
6
|
import { hashToken, loginMaxFailuresPerIp, loginMaxFailuresPerUser, loginWindowMinutes, newToken } from './security.ts';
|
|
@@ -121,6 +123,7 @@ export async function logActivity(entry: {
|
|
|
121
123
|
elapsedMs?: number;
|
|
122
124
|
detail?: string;
|
|
123
125
|
}) {
|
|
126
|
+
activityTelemetry(entry);
|
|
124
127
|
try {
|
|
125
128
|
// (090) on the connection of the entry's application (an isolated workspace's own); without one, the shared one
|
|
126
129
|
const db = entry.appId != null ? await runtimeForApp(entry.appId) : sharedRuntime;
|
|
@@ -152,3 +155,26 @@ export async function loginThrottled(appId: number | null, username: string, ip:
|
|
|
152
155
|
);
|
|
153
156
|
return !!counts && (counts.user_fails >= loginMaxFailuresPerUser() || counts.ip_fails >= loginMaxFailuresPerIp());
|
|
154
157
|
}
|
|
158
|
+
|
|
159
|
+
// (sprint 139, AP-6) errors, refusals and failed sign-ins as OpenTelemetry logs and metrics
|
|
160
|
+
const OTEL_EVENTS: Record<string, ['ERROR' | 'WARN', string]> = {
|
|
161
|
+
error: ['ERROR', 'pgkiln.errors'],
|
|
162
|
+
forbidden: ['WARN', 'pgkiln.access_denied'],
|
|
163
|
+
login_failed: ['WARN', 'pgkiln.signin_failures'],
|
|
164
|
+
login_locked: ['WARN', 'pgkiln.signin_failures'],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function activityTelemetry(e: { appId?: number | null; pageNo?: number | null; username?: string | null; event: string; detail?: string }) {
|
|
168
|
+
const known = OTEL_EVENTS[e.event];
|
|
169
|
+
if (!known) return;
|
|
170
|
+
const app = e.appId == null ? 'builder' : appOf(e.appId)?.[0] ?? 'unknown';
|
|
171
|
+
count(known[1], e.event === 'login_locked' ? { app, reason: 'locked' } : { app });
|
|
172
|
+
emitLog({
|
|
173
|
+
severity: known[0],
|
|
174
|
+
body: e.event,
|
|
175
|
+
detail: e.detail,
|
|
176
|
+
attrs: { 'pgkiln.event': e.event, 'pgkiln.app.id': e.appId ?? null, 'pgkiln.app.alias': e.appId == null ? null : app, 'pgkiln.page': e.pageNo == null ? null : String(e.pageNo) },
|
|
177
|
+
appId: e.appId ?? null,
|
|
178
|
+
user: e.username ?? null,
|
|
179
|
+
});
|
|
180
|
+
}
|