@open-mercato/shared 0.9.1-develop.7539.1.e8130235f3 → 0.9.1-develop.7543.1.4d3d24cb1e
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/dist/lib/crud/exporters.js +1 -1
- package/dist/lib/crud/exporters.js.map +2 -2
- package/dist/lib/version.js +1 -1
- package/dist/lib/version.js.map +1 -1
- package/dist/modules/notifications/types.js +4 -0
- package/dist/modules/notifications/types.js.map +3 -3
- package/package.json +2 -2
- package/src/lib/crud/__tests__/exporters.test.ts +18 -0
- package/src/lib/crud/exporters.ts +1 -1
- package/src/modules/notifications/types.ts +7 -0
|
@@ -47,7 +47,7 @@ function escapeXmlValue(value) {
|
|
|
47
47
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
48
48
|
}
|
|
49
49
|
function serializeCsv(prepared) {
|
|
50
|
-
const headers = prepared.columns.map((col) => col.header);
|
|
50
|
+
const headers = prepared.columns.map((col) => escapeCsv(neutralizeSpreadsheetFormula(col.header)));
|
|
51
51
|
const lines = [headers.join(",")];
|
|
52
52
|
for (const row of prepared.rows) {
|
|
53
53
|
const values = prepared.columns.map((col) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/crud/exporters.ts"],
|
|
4
|
-
"sourcesContent": ["export type CrudExportFormat = 'csv' | 'json' | 'xml' | 'markdown'\n\nexport type CrudExportColumn = {\n field: string\n header: string\n}\n\nexport type PreparedExport = {\n columns: CrudExportColumn[]\n rows: Array<Record<string, unknown>>\n}\n\nexport type SerializedExport = {\n body: string\n contentType: string\n fileExtension: string\n}\n\nconst CSV_CONTENT_TYPE = 'text/csv; charset=utf-8'\nconst JSON_CONTENT_TYPE = 'application/json; charset=utf-8'\nconst XML_CONTENT_TYPE = 'application/xml; charset=utf-8'\nconst MARKDOWN_CONTENT_TYPE = 'text/markdown; charset=utf-8'\n\nfunction normalizeValue(value: unknown): string {\n if (value == null) return ''\n if (value instanceof Date) return value.toISOString()\n if (typeof value === 'bigint') return value.toString()\n if (typeof value === 'object') {\n if (Array.isArray(value)) return value.map((v) => normalizeValue(v)).filter(Boolean).join(', ')\n return JSON.stringify(value)\n }\n return String(value)\n}\n\nfunction escapeCsv(value: string): string {\n if (/[\",\\n\\r]/.test(value)) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`\n }\n return value\n}\n\nfunction neutralizeSpreadsheetFormula(value: string): string {\n if (/^[=+\\-@\\t\\r\\n]/.test(value)) {\n return `'${value}`\n }\n return value\n}\n\nfunction normalizeCsvValue(value: unknown): string {\n const normalized = normalizeValue(value)\n if (typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean') {\n return normalized\n }\n return neutralizeSpreadsheetFormula(normalized)\n}\n\nfunction escapeMarkdown(value: string): string {\n const escaped = value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r?\\n/g, '<br />')\n return escaped || ' '\n}\n\nfunction escapeXmlTag(tag: string, fallbackIndex: number): string {\n const sanitized = tag.replace(/[^A-Za-z0-9_:-]/g, '_')\n const normalized = sanitized.length > 0 ? sanitized : `field_${fallbackIndex}`\n if (/^[^A-Za-z_]/.test(normalized)) {\n return `f_${normalized}`\n }\n return normalized\n}\n\nfunction escapeXmlValue(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n\nfunction serializeCsv(prepared: PreparedExport): SerializedExport {\n const headers = prepared.columns.map((col) => col.header)\n const lines = [headers.join(',')]\n for (const row of prepared.rows) {\n const values = prepared.columns.map((col) => {\n const raw = normalizeCsvValue(row[col.field])\n return escapeCsv(raw)\n })\n lines.push(values.join(','))\n }\n return {\n body: lines.join('\\n'),\n contentType: CSV_CONTENT_TYPE,\n fileExtension: 'csv',\n }\n}\n\nfunction serializeJson(prepared: PreparedExport): SerializedExport {\n // For JSON we return objects keyed by exported field names with human headers as metadata\n const payload = prepared.rows.map((row) => {\n const obj: Record<string, unknown> = {}\n for (const column of prepared.columns) {\n obj[column.header] = row[column.field]\n }\n return obj\n })\n return {\n body: JSON.stringify(payload, null, 2),\n contentType: JSON_CONTENT_TYPE,\n fileExtension: 'json',\n }\n}\n\nfunction serializeXml(prepared: PreparedExport): SerializedExport {\n const lines: string[] = ['<?xml version=\"1.0\" encoding=\"UTF-8\"?>', '<records>']\n for (const row of prepared.rows) {\n lines.push(' <record>')\n prepared.columns.forEach((column, index) => {\n const tag = escapeXmlTag(column.field || column.header, index)\n const value = escapeXmlValue(normalizeValue(row[column.field]))\n lines.push(` <${tag}>${value}</${tag}>`)\n })\n lines.push(' </record>')\n }\n lines.push('</records>')\n return {\n body: lines.join('\\n'),\n contentType: XML_CONTENT_TYPE,\n fileExtension: 'xml',\n }\n}\n\nfunction serializeMarkdown(prepared: PreparedExport): SerializedExport {\n const headers = prepared.columns.map((col) => escapeMarkdown(col.header))\n const headerLine = `| ${headers.join(' | ')} |`\n const dividerLine = `| ${prepared.columns.map(() => '---').join(' | ')} |`\n const rows = prepared.rows.map((row) => {\n const cells = prepared.columns.map((col) => escapeMarkdown(normalizeValue(row[col.field])))\n return `| ${cells.join(' | ')} |`\n })\n const body = [headerLine, dividerLine, ...rows].join('\\n')\n return {\n body,\n contentType: MARKDOWN_CONTENT_TYPE,\n fileExtension: 'md',\n }\n}\n\nexport function serializeExport(prepared: PreparedExport, format: CrudExportFormat): SerializedExport {\n switch (format) {\n case 'csv':\n return serializeCsv(prepared)\n case 'json':\n return serializeJson(prepared)\n case 'xml':\n return serializeXml(prepared)\n case 'markdown':\n return serializeMarkdown(prepared)\n default:\n return serializeJson(prepared)\n }\n}\n\nexport function normalizeExportFormat(raw: unknown): CrudExportFormat | null {\n if (typeof raw !== 'string' || raw.trim() === '') return null\n const value = raw.toLowerCase()\n if (value === 'csv') return 'csv'\n if (value === 'json' || value === 'application/json') return 'json'\n if (value === 'xml' || value === 'application/xml') return 'xml'\n if (value === 'markdown' || value === 'md' || value === 'text/markdown') return 'markdown'\n return null\n}\n\nexport function defaultExportFilename(base: string | undefined | null, format: CrudExportFormat): string {\n const safeBase = (base && base.trim().length > 0 ? base.trim() : 'export')\n .replace(/[^a-z0-9_\\-]/gi, '_')\n const suffix = format === 'markdown' ? 'md' : format\n return `${safeBase}.${suffix}`\n}\n\nexport function toHeaderLabel(key: string): string {\n const withoutPrefix = key.replace(/^cf[:_\\-\\s]+/i, '')\n const normalized = withoutPrefix.replace(/[_\\-\\s]+/g, ' ').trim()\n if (!normalized) return 'Field'\n return normalized.replace(/\\b\\w/g, (char) => char.toUpperCase())\n}\n\nexport function ensureColumns(rows: Array<Record<string, unknown>>, hint?: CrudExportColumn[]): CrudExportColumn[] {\n if (hint && hint.length > 0) return hint\n const used = new Map<string, string>()\n rows.forEach((row) => {\n Object.keys(row || {}).forEach((key) => {\n if (!used.has(key)) used.set(key, key)\n })\n })\n if (used.size === 0) return [{ field: 'id', header: 'ID' }]\n return Array.from(used.keys()).map((key) => ({\n field: key,\n header: toHeaderLabel(key),\n }))\n}\n"],
|
|
5
|
-
"mappings": "AAkBA,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,SAAS,eAAe,OAAwB;AAC9C,MAAI,SAAS,KAAM,QAAO;AAC1B,MAAI,iBAAiB,KAAM,QAAO,MAAM,YAAY;AACpD,MAAI,OAAO,UAAU,SAAU,QAAO,MAAM,SAAS;AACrD,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,CAAC,MAAM,eAAe,CAAC,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAC9F,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AACA,SAAO,OAAO,KAAK;AACrB;AAEA,SAAS,UAAU,OAAuB;AACxC,MAAI,WAAW,KAAK,KAAK,GAAG;AAC1B,WAAO,IAAI,MAAM,QAAQ,MAAM,IAAI,CAAC;AAAA,EACtC;AACA,SAAO;AACT;AAEA,SAAS,6BAA6B,OAAuB;AAC3D,MAAI,iBAAiB,KAAK,KAAK,GAAG;AAChC,WAAO,IAAI,KAAK;AAAA,EAClB;AACA,SAAO;AACT;AAEA,SAAS,kBAAkB,OAAwB;AACjD,QAAM,aAAa,eAAe,KAAK;AACvC,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AACxF,WAAO;AAAA,EACT;AACA,SAAO,6BAA6B,UAAU;AAChD;AAEA,SAAS,eAAe,OAAuB;AAC7C,QAAM,UAAU,MACb,QAAQ,OAAO,MAAM,EACrB,QAAQ,OAAO,KAAK,EACpB,QAAQ,UAAU,QAAQ;AAC7B,SAAO,WAAW;AACpB;AAEA,SAAS,aAAa,KAAa,eAA+B;AAChE,QAAM,YAAY,IAAI,QAAQ,oBAAoB,GAAG;AACrD,QAAM,aAAa,UAAU,SAAS,IAAI,YAAY,SAAS,aAAa;AAC5E,MAAI,cAAc,KAAK,UAAU,GAAG;AAClC,WAAO,KAAK,UAAU;AAAA,EACxB;AACA,SAAO;AACT;AAEA,SAAS,eAAe,OAAuB;AAC7C,SAAO,MACJ,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ,EACtB,QAAQ,MAAM,QAAQ;AAC3B;AAEA,SAAS,aAAa,UAA4C;AAChE,QAAM,UAAU,SAAS,QAAQ,IAAI,CAAC,QAAQ,IAAI,MAAM;
|
|
4
|
+
"sourcesContent": ["export type CrudExportFormat = 'csv' | 'json' | 'xml' | 'markdown'\n\nexport type CrudExportColumn = {\n field: string\n header: string\n}\n\nexport type PreparedExport = {\n columns: CrudExportColumn[]\n rows: Array<Record<string, unknown>>\n}\n\nexport type SerializedExport = {\n body: string\n contentType: string\n fileExtension: string\n}\n\nconst CSV_CONTENT_TYPE = 'text/csv; charset=utf-8'\nconst JSON_CONTENT_TYPE = 'application/json; charset=utf-8'\nconst XML_CONTENT_TYPE = 'application/xml; charset=utf-8'\nconst MARKDOWN_CONTENT_TYPE = 'text/markdown; charset=utf-8'\n\nfunction normalizeValue(value: unknown): string {\n if (value == null) return ''\n if (value instanceof Date) return value.toISOString()\n if (typeof value === 'bigint') return value.toString()\n if (typeof value === 'object') {\n if (Array.isArray(value)) return value.map((v) => normalizeValue(v)).filter(Boolean).join(', ')\n return JSON.stringify(value)\n }\n return String(value)\n}\n\nfunction escapeCsv(value: string): string {\n if (/[\",\\n\\r]/.test(value)) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`\n }\n return value\n}\n\nfunction neutralizeSpreadsheetFormula(value: string): string {\n if (/^[=+\\-@\\t\\r\\n]/.test(value)) {\n return `'${value}`\n }\n return value\n}\n\nfunction normalizeCsvValue(value: unknown): string {\n const normalized = normalizeValue(value)\n if (typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean') {\n return normalized\n }\n return neutralizeSpreadsheetFormula(normalized)\n}\n\nfunction escapeMarkdown(value: string): string {\n const escaped = value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r?\\n/g, '<br />')\n return escaped || ' '\n}\n\nfunction escapeXmlTag(tag: string, fallbackIndex: number): string {\n const sanitized = tag.replace(/[^A-Za-z0-9_:-]/g, '_')\n const normalized = sanitized.length > 0 ? sanitized : `field_${fallbackIndex}`\n if (/^[^A-Za-z_]/.test(normalized)) {\n return `f_${normalized}`\n }\n return normalized\n}\n\nfunction escapeXmlValue(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n\nfunction serializeCsv(prepared: PreparedExport): SerializedExport {\n const headers = prepared.columns.map((col) => escapeCsv(neutralizeSpreadsheetFormula(col.header)))\n const lines = [headers.join(',')]\n for (const row of prepared.rows) {\n const values = prepared.columns.map((col) => {\n const raw = normalizeCsvValue(row[col.field])\n return escapeCsv(raw)\n })\n lines.push(values.join(','))\n }\n return {\n body: lines.join('\\n'),\n contentType: CSV_CONTENT_TYPE,\n fileExtension: 'csv',\n }\n}\n\nfunction serializeJson(prepared: PreparedExport): SerializedExport {\n // For JSON we return objects keyed by exported field names with human headers as metadata\n const payload = prepared.rows.map((row) => {\n const obj: Record<string, unknown> = {}\n for (const column of prepared.columns) {\n obj[column.header] = row[column.field]\n }\n return obj\n })\n return {\n body: JSON.stringify(payload, null, 2),\n contentType: JSON_CONTENT_TYPE,\n fileExtension: 'json',\n }\n}\n\nfunction serializeXml(prepared: PreparedExport): SerializedExport {\n const lines: string[] = ['<?xml version=\"1.0\" encoding=\"UTF-8\"?>', '<records>']\n for (const row of prepared.rows) {\n lines.push(' <record>')\n prepared.columns.forEach((column, index) => {\n const tag = escapeXmlTag(column.field || column.header, index)\n const value = escapeXmlValue(normalizeValue(row[column.field]))\n lines.push(` <${tag}>${value}</${tag}>`)\n })\n lines.push(' </record>')\n }\n lines.push('</records>')\n return {\n body: lines.join('\\n'),\n contentType: XML_CONTENT_TYPE,\n fileExtension: 'xml',\n }\n}\n\nfunction serializeMarkdown(prepared: PreparedExport): SerializedExport {\n const headers = prepared.columns.map((col) => escapeMarkdown(col.header))\n const headerLine = `| ${headers.join(' | ')} |`\n const dividerLine = `| ${prepared.columns.map(() => '---').join(' | ')} |`\n const rows = prepared.rows.map((row) => {\n const cells = prepared.columns.map((col) => escapeMarkdown(normalizeValue(row[col.field])))\n return `| ${cells.join(' | ')} |`\n })\n const body = [headerLine, dividerLine, ...rows].join('\\n')\n return {\n body,\n contentType: MARKDOWN_CONTENT_TYPE,\n fileExtension: 'md',\n }\n}\n\nexport function serializeExport(prepared: PreparedExport, format: CrudExportFormat): SerializedExport {\n switch (format) {\n case 'csv':\n return serializeCsv(prepared)\n case 'json':\n return serializeJson(prepared)\n case 'xml':\n return serializeXml(prepared)\n case 'markdown':\n return serializeMarkdown(prepared)\n default:\n return serializeJson(prepared)\n }\n}\n\nexport function normalizeExportFormat(raw: unknown): CrudExportFormat | null {\n if (typeof raw !== 'string' || raw.trim() === '') return null\n const value = raw.toLowerCase()\n if (value === 'csv') return 'csv'\n if (value === 'json' || value === 'application/json') return 'json'\n if (value === 'xml' || value === 'application/xml') return 'xml'\n if (value === 'markdown' || value === 'md' || value === 'text/markdown') return 'markdown'\n return null\n}\n\nexport function defaultExportFilename(base: string | undefined | null, format: CrudExportFormat): string {\n const safeBase = (base && base.trim().length > 0 ? base.trim() : 'export')\n .replace(/[^a-z0-9_\\-]/gi, '_')\n const suffix = format === 'markdown' ? 'md' : format\n return `${safeBase}.${suffix}`\n}\n\nexport function toHeaderLabel(key: string): string {\n const withoutPrefix = key.replace(/^cf[:_\\-\\s]+/i, '')\n const normalized = withoutPrefix.replace(/[_\\-\\s]+/g, ' ').trim()\n if (!normalized) return 'Field'\n return normalized.replace(/\\b\\w/g, (char) => char.toUpperCase())\n}\n\nexport function ensureColumns(rows: Array<Record<string, unknown>>, hint?: CrudExportColumn[]): CrudExportColumn[] {\n if (hint && hint.length > 0) return hint\n const used = new Map<string, string>()\n rows.forEach((row) => {\n Object.keys(row || {}).forEach((key) => {\n if (!used.has(key)) used.set(key, key)\n })\n })\n if (used.size === 0) return [{ field: 'id', header: 'ID' }]\n return Array.from(used.keys()).map((key) => ({\n field: key,\n header: toHeaderLabel(key),\n }))\n}\n"],
|
|
5
|
+
"mappings": "AAkBA,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAE9B,SAAS,eAAe,OAAwB;AAC9C,MAAI,SAAS,KAAM,QAAO;AAC1B,MAAI,iBAAiB,KAAM,QAAO,MAAM,YAAY;AACpD,MAAI,OAAO,UAAU,SAAU,QAAO,MAAM,S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AAQ,UAAU,gBAAiB,QAAO;AAChF,SAAO;AACT;AAEO,SAAS,sBAAsB,MAAiC,QAAkC;AACvG,QAAM,YAAY,QAAQ,KAAK,KAAK,EAAE,SAAS,IAAI,KAAK,KAAK,IAAI,UAC9D,QAAQ,kBAAkB,GAAG;AAChC,QAAM,SAAS,WAAW,aAAa,OAAO;AAC9C,SAAO,GAAG,QAAQ,IAAI,MAAM;AAC9B;AAEO,SAAS,cAAc,KAAqB;AACjD,QAAM,gBAAgB,IAAI,QAAQ,iBAAiB,EAAE;AACrD,QAAM,aAAa,cAAc,QAAQ,aAAa,GAAG,EAAE,KAAK;AAChE,MAAI,CAAC,WAAY,QAAO;AACxB,SAAO,WAAW,QAAQ,SAAS,CAAC,SAAS,KAAK,YAAY,CAAC;AACjE;AAEO,SAAS,cAAc,MAAsC,MAA+C;AACjH,MAAI,QAAQ,KAAK,SAAS,EAAG,QAAO;AACpC,QAAM,OAAO,oBAAI,IAAoB;AACrC,OAAK,QAAQ,CAAC,QAAQ;AACpB,WAAO,KAAK,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAI,CAAC,KAAK,IAAI,GAAG,EAAG,MAAK,IAAI,KAAK,GAAG;AAAA,IACvC,CAAC;AAAA,EACH,CAAC;AACD,MAAI,KAAK,SAAS,EAAG,QAAO,CAAC,EAAE,OAAO,MAAM,QAAQ,KAAK,CAAC;AAC1D,SAAO,MAAM,KAAK,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS;AAAA,IAC3C,OAAO;AAAA,IACP,QAAQ,cAAc,GAAG;AAAA,EAC3B,EAAE;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/version.js
CHANGED
package/dist/lib/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.9.1-develop.
|
|
4
|
+
"sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.9.1-develop.7543.1.4d3d24cb1e';\nexport const appVersion = APP_VERSION;\n"],
|
|
5
5
|
"mappings": "AACO,MAAM,cAAc;AACpB,MAAM,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [],
|
|
4
|
-
"sourcesContent": [],
|
|
5
|
-
"mappings": "",
|
|
3
|
+
"sources": ["../../../src/modules/notifications/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ComponentType } from 'react'\n\nexport type NotificationStatus = 'unread' | 'read' | 'actioned' | 'dismissed'\nexport type NotificationSeverity = 'info' | 'warning' | 'success' | 'error'\n\n/**\n * `code` of the 409 body `POST /api/notifications/:id/action` answers with when the notification's\n * action has already been executed. Lets a client tell that refusal apart from a 409 raised by\n * the action's own command.\n */\nexport const NOTIFICATION_ACTION_ALREADY_EXECUTED_ERROR_CODE = 'notification_action_already_executed'\n\nexport type NotificationAction = {\n id: string\n label: string\n labelKey?: string\n variant?: 'default' | 'secondary' | 'destructive' | 'outline' | 'ghost'\n icon?: string\n commandId?: string\n href?: string\n confirmRequired?: boolean\n confirmMessage?: string\n}\n\nexport type NotificationActionData = {\n actions: NotificationAction[]\n primaryActionId?: string\n}\n\nexport type NotificationTypeAction = {\n id: string\n labelKey: string\n variant?: 'default' | 'secondary' | 'destructive' | 'outline' | 'ghost'\n icon?: string\n commandId?: string\n href?: string\n confirmRequired?: boolean\n confirmMessageKey?: string\n}\n\nexport type NotificationRendererProps = {\n notification: {\n id: string\n type: string\n title: string\n body?: string | null\n titleKey?: string | null\n bodyKey?: string | null\n titleVariables?: Record<string, string> | null\n bodyVariables?: Record<string, string> | null\n icon?: string | null\n severity: string\n status: string\n sourceModule?: string | null\n sourceEntityType?: string | null\n sourceEntityId?: string | null\n linkHref?: string | null\n createdAt: string\n }\n onAction: (actionId: string) => Promise<void>\n onDismiss: () => Promise<void>\n actions: NotificationTypeAction[]\n}\n\nexport type NotificationTypeDefinition = {\n type: string\n module: string\n titleKey: string\n bodyKey?: string\n icon: string\n severity: NotificationSeverity\n actions: NotificationTypeAction[]\n primaryActionId?: string\n linkHref?: string\n Renderer?: ComponentType<NotificationRendererProps>\n expiresAfterHours?: number\n /**\n * Optional i18n key for the short type name shown in a per-channel\n * preferences UI (e.g. \"Order created\"). Distinct from `titleKey`, which is\n * the per-instance message title. Falls back to `titleKey` when omitted.\n */\n labelKey?: string\n /** Optional i18n key for helper text shown beside the type in a preferences UI. */\n descriptionKey?: string\n /**\n * Optional free-form grouping label (e.g. `security`, `orders`, `marketing`) so a\n * client \u2014 typically a mobile app \u2014 can list/group notification types under a heading.\n * Plain string, not an enum; mirrored to the `notification_types` table and returned by\n * `GET /api/notifications/types`.\n *\n * Defaults to the prefix before the first dot in `type` (`sales.order.created` \u2192\n * `sales`), resolved once during `syncNotificationTypes`. Declare it only to override\n * that default. Localize the heading by adding `notifications.categories.<key>` to YOUR\n * OWN module's `i18n/*.json` \u2014 the `notifications` module deliberately ships no category\n * labels and knows nothing about which categories exist. `GET /api/notifications/types`\n * resolves the key into `categoryLabel`, falling back to the raw key when absent.\n *\n * Clients group on `category` (stable across locales) and display `categoryLabel`.\n */\n category?: string\n /**\n * When `true`, this type's push is delivered as a silent / content-available (data-only)\n * wake-up instead of a visible alert. `silent` selects the delivery STYLE only \u2014 the\n * notification still flows through the normal `notificationService.create()` path (in-app\n * row created, per-channel preferences respected unless the type is `nonOptOut`).\n */\n silent?: boolean\n /**\n * When `true`, the recipient cannot opt out of this type: delivery ignores any\n * stored per-channel preference (security/account alerts that must always be\n * delivered). A preferences UI should render it as locked/forced-on, and\n * `setPreferences` refuses to store an opt-out row for it.\n */\n nonOptOut?: boolean\n /**\n * When `true`, this type is hidden from the client-facing catalogue: it is NOT mirrored to the\n * `notification_types` table and therefore not returned by `GET /api/notifications/types`, so a\n * mobile app's preferences screen never lists it. Used for internal/admin-only types (e.g. one-off\n * admin custom pushes) that are dispatched by the server, not toggled by users. The type still\n * lives in the in-memory registry for delivery logic (`getNotificationType`).\n */\n hiddenFromSettings?: boolean\n /**\n * Optional per-type channel eligibility: the delivery channels this type may EVER use\n * (e.g. a marketing type restricted to `['push']` so it never lands in the in-app bell).\n * The dispatcher intersects it with the per-send target, the registered strategies, and the\n * recipient's preferences via `shouldDeliver`. Omit to make the type eligible for every\n * registered channel (pre-Phase-7 behavior).\n *\n * Operators can override this set per tenant via the `notification_type_overrides` table\n * (`PATCH /api/notifications/types` / the Notification Delivery settings page): a stored\n * array replaces the code-declared one, an absent row (or `NULL`) inherits it. A channel\n * outside the effective set never delivers for the type in that tenant \u2014 the check runs\n * before both the `nonOptOut` bypass and user preferences, and the preference UIs render\n * that cell locked off.\n */\n channels?: string[]\n}\n\n/**\n * A delivery channel in the module-registered channel catalogue. Any module can contribute channels\n * by exporting `notificationChannels: NotificationChannelDefinition[]` from a `notification-channels.ts`\n * file (generator-discovered), so a preferences UI and the `/api/notifications/channels` endpoint stay\n * in sync with the actual delivery paths without a hardcoded list. `id` matches the delivery-strategy id\n * (`in_app`, `email`, `push`, \u2026) \u2014 treat it as a FROZEN contract once shipped.\n */\nexport type NotificationChannelDefinition = {\n id: string\n /** i18n key for the channel's display name in a preferences UI. */\n labelKey: string\n /** Optional i18n key for helper text shown beside the channel. */\n descriptionKey?: string\n /** Ascending display order; entries without an order sort after ordered ones, then by id. */\n order?: number\n}\n\nexport type NotificationDto = {\n id: string\n type: string\n title: string\n body?: string | null\n titleKey?: string | null\n bodyKey?: string | null\n titleVariables?: Record<string, string> | null\n bodyVariables?: Record<string, string> | null\n icon?: string | null\n severity: string\n status: string\n actions: Array<{\n id: string\n label: string\n labelKey?: string\n variant?: string\n icon?: string\n href?: string\n }>\n primaryActionId?: string\n sourceModule?: string | null\n sourceEntityType?: string | null\n sourceEntityId?: string | null\n linkHref?: string | null\n /** Arbitrary app-readable key/values attached at create time (also delivered with the push). */\n data?: Record<string, string> | null\n /** Resolved delivery channels for this notification. `null` = all channels (legacy/untargeted). */\n channels?: string[] | null\n createdAt: string\n readAt?: string | null\n actionTaken?: string | null\n}\n\nexport type NotificationPollData = {\n unreadCount: number\n recent: NotificationDto[]\n hasNew: boolean\n lastId?: string\n}\n"],
|
|
5
|
+
"mappings": "AAUO,MAAM,kDAAkD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/shared",
|
|
3
|
-
"version": "0.9.1-develop.
|
|
3
|
+
"version": "0.9.1-develop.7543.1.4d3d24cb1e",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"@mikro-orm/core": "^7.1.14",
|
|
122
122
|
"@mikro-orm/decorators": "^7.1.14",
|
|
123
123
|
"@mikro-orm/postgresql": "^7.1.14",
|
|
124
|
-
"@open-mercato/cache": "0.9.1-develop.
|
|
124
|
+
"@open-mercato/cache": "0.9.1-develop.7543.1.4d3d24cb1e",
|
|
125
125
|
"@types/html-to-text": "^9.0.4",
|
|
126
126
|
"@types/sanitize-html": "^2.16.1",
|
|
127
127
|
"dotenv": "^17.4.2",
|
|
@@ -28,4 +28,22 @@ describe('CRUD export serializers', () => {
|
|
|
28
28
|
'"\'\t=HYPERLINK(""https://example.invalid"")","\'\r+1+1",\'-7',
|
|
29
29
|
])
|
|
30
30
|
})
|
|
31
|
+
|
|
32
|
+
it('escapes and neutralizes CSV header cells the same way as data cells', () => {
|
|
33
|
+
const serialized = serializeExport({
|
|
34
|
+
columns: [
|
|
35
|
+
{ field: 'company', header: 'Name, Inc.' },
|
|
36
|
+
{ field: 'formula', header: '=HEADER' },
|
|
37
|
+
{ field: 'plain', header: 'Balance' },
|
|
38
|
+
],
|
|
39
|
+
rows: [
|
|
40
|
+
{ company: 'Acme', formula: 'ok', plain: 1 },
|
|
41
|
+
],
|
|
42
|
+
}, 'csv')
|
|
43
|
+
|
|
44
|
+
expect(serialized.body.split('\n')).toEqual([
|
|
45
|
+
'"Name, Inc.",\'=HEADER,Balance',
|
|
46
|
+
'Acme,ok,1',
|
|
47
|
+
])
|
|
48
|
+
})
|
|
31
49
|
})
|
|
@@ -81,7 +81,7 @@ function escapeXmlValue(value: string): string {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function serializeCsv(prepared: PreparedExport): SerializedExport {
|
|
84
|
-
const headers = prepared.columns.map((col) => col.header)
|
|
84
|
+
const headers = prepared.columns.map((col) => escapeCsv(neutralizeSpreadsheetFormula(col.header)))
|
|
85
85
|
const lines = [headers.join(',')]
|
|
86
86
|
for (const row of prepared.rows) {
|
|
87
87
|
const values = prepared.columns.map((col) => {
|
|
@@ -3,6 +3,13 @@ import type { ComponentType } from 'react'
|
|
|
3
3
|
export type NotificationStatus = 'unread' | 'read' | 'actioned' | 'dismissed'
|
|
4
4
|
export type NotificationSeverity = 'info' | 'warning' | 'success' | 'error'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* `code` of the 409 body `POST /api/notifications/:id/action` answers with when the notification's
|
|
8
|
+
* action has already been executed. Lets a client tell that refusal apart from a 409 raised by
|
|
9
|
+
* the action's own command.
|
|
10
|
+
*/
|
|
11
|
+
export const NOTIFICATION_ACTION_ALREADY_EXECUTED_ERROR_CODE = 'notification_action_already_executed'
|
|
12
|
+
|
|
6
13
|
export type NotificationAction = {
|
|
7
14
|
id: string
|
|
8
15
|
label: string
|