@stsdti/auditing-core 0.0.0-stage → 0.1.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 STSDTI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # @stsdti/auditing-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The framework-agnostic half of [laravel-auditing](../../../README.md)'s UI: what a UI derives from audits,
4
+ with no UI framework and no transport — it makes no requests; the application fetches audits.
5
+ `@stsdti/auditing-vue` renders what is derived here, and any other binding would behave the same.
6
+
7
+ ## Derivations
8
+
9
+ | export | |
10
+ |---|---|
11
+ | `AUDIT_EVENTS`, `auditEvent(code)` | tone and glyph per event; unknown events are neutral |
12
+ | `auditChanges(audit, { format })` | `[{ field, oldValue, newValue }]`, in the record's field order |
13
+ | `showsOldValues`, `showsNewValues` | a created audit has no "before", a deleted one no "after" |
14
+ | `formatValue`, `clip` | JSON pretty-printed, everything else as text; clipping |
15
+ | `groupByBatch(audits)` | consecutive audits of the same request / command / job |
16
+ | `emptyFilters`, `hasFilters`, `filterChips` | filter state and its chips |
17
+ | `toParams(filters)` | the filters as query parameters (`event[]`, `user[]`, …) |
18
+ | `pageWindow`, `pageRange` | pagination |
19
+ | `shortClassName`, `userName` | labels |
20
+
21
+ ## Dates, labels, dark mode
22
+
23
+ | export | |
24
+ |---|---|
25
+ | `setAuditingDateFormatter({ date, dateTime })`, `formatDate`, `formatDateTime`, `parseDate`, `toIsoDate` | dates (`28.10.2026 12:24:37` by default) |
26
+ | `DEFAULT_MESSAGES`, `mergeMessages`, `formatMessage`, `eventLabel` | every string on screen, in Romanian |
27
+ | `setAuditingColorScheme`, `auditingColorScheme` | dark mode (a `.dark` class) |
@@ -0,0 +1,305 @@
1
+ // src/index.js
2
+ var e = Object.freeze({
3
+ title: "Listă audit",
4
+ description: "",
5
+ event_created: "Creare",
6
+ event_updated: "Actualizare",
7
+ event_deleted: "Ștergere",
8
+ event_restored: "Restaurare",
9
+ event_attached: "Asociere",
10
+ event_detached: "Disociere",
11
+ columnEvent: "Acțiune",
12
+ columnResource: "Resursă",
13
+ columnUser: "Utilizator și data",
14
+ columnChanges: "Modificări",
15
+ columnActions: "Acțiuni",
16
+ system: "Sistem",
17
+ field: "Câmp",
18
+ oldValue: "Valoare veche",
19
+ newValue: "Valoare nouă",
20
+ noChanges: "Nu există modificări",
21
+ fieldCount: "{count} câmpuri",
22
+ fieldCountOne: "1 câmp",
23
+ showAllChanges: "Vezi toate cele {count} modificări",
24
+ changesTitle: "Modificări ({count})",
25
+ showDetails: "Vezi detaliile",
26
+ close: "Închide",
27
+ contextUrl: "URL",
28
+ contextIp: "Adresă IP",
29
+ contextUserAgent: "Browser",
30
+ contextBatch: "Acțiune (batch)",
31
+ searchPlaceholder: "Caută în valori…",
32
+ filterSearch: "Căutare",
33
+ filterEvent: "Acțiune",
34
+ filterUser: "Utilizator",
35
+ filterResource: "Resursă",
36
+ filterPeriod: "Perioadă",
37
+ filterFrom: "De la",
38
+ filterTo: "Până la",
39
+ filters: "Filtre",
40
+ filtersTitle: "Filtre avansate",
41
+ filtersDescription: "Combină mai multe criterii. Rezultatele se actualizează la aplicare.",
42
+ apply: "Aplică",
43
+ applyFilters: "Aplică filtrele",
44
+ resetShort: "Resetează",
45
+ allPlaceholder: "Toate",
46
+ removeFilter: "Elimină filtrul {filter}",
47
+ clearFilters: "Șterge filtrele",
48
+ selectSearch: "Caută…",
49
+ selectEmpty: "Niciun rezultat",
50
+ selectLoading: "Se încarcă…",
51
+ selectedCount: "{count} selectate",
52
+ loading: "Se încarcă…",
53
+ result: "rezultat",
54
+ results: "rezultate",
55
+ empty: "Nicio înregistrare găsită",
56
+ emptyHint: "Încearcă alt termen de căutare sau resetează filtrele.",
57
+ resetFilters: "Resetează filtrele",
58
+ loadFailed: "Datele nu au putut fi încărcate",
59
+ historyTitle: "Audit resursă",
60
+ historyDescription: "Modificările acestei înregistrări, cele mai noi primele.",
61
+ historyEmpty: "Nu există istoric audit resursă",
62
+ historyButton: "Istoric",
63
+ batchTitle: "Aceeași acțiune",
64
+ batchDescription: "Tot ce a scris aceeași cerere, comandă sau job.",
65
+ selectedRecord: "Înregistrare selectată",
66
+ sameBatch: "{count} modificări în aceeași acțiune",
67
+ becomes: "devine",
68
+ retry: "Reîncearcă",
69
+ refresh: "Reîmprospătează",
70
+ pagination: "Paginare",
71
+ rowsPerPage: "Rânduri pe pagină",
72
+ pageRange: "{from}–{to} din {total}",
73
+ pageRangeEmpty: "0 rezultate",
74
+ previousPage: "Pagina anterioară",
75
+ nextPage: "Pagina următoare"
76
+ });
77
+ function t(...t) {
78
+ return Object.assign({}, e, ...t.filter(Boolean));
79
+ }
80
+ function n(e, t = {}) {
81
+ return String(e ?? "").replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
82
+ }
83
+ function r(e, t) {
84
+ return e[`event_${t}`] ?? t;
85
+ }
86
+ var i = "dark";
87
+ function a(e, t = typeof document < "u" ? document.documentElement : null) {
88
+ t?.classList.toggle(i, e === "dark");
89
+ }
90
+ function o(e = typeof document < "u" ? document.documentElement : null) {
91
+ return e ? e.classList.contains("dark") ? "dark" : "light" : null;
92
+ }
93
+ var s = (e) => String(e).padStart(2, "0");
94
+ function c(e) {
95
+ if (!e) return null;
96
+ if (e instanceof Date) return Number.isNaN(e.getTime()) ? null : e;
97
+ let t = String(e), n = /^\d{4}-\d{2}-\d{2}$/.test(t) ? /* @__PURE__ */ new Date(`${t}T00:00:00`) : new Date(t.replace(" ", "T"));
98
+ return Number.isNaN(n.getTime()) ? null : n;
99
+ }
100
+ function l(e) {
101
+ return `${s(e.getDate())}.${s(e.getMonth() + 1)}.${e.getFullYear()}`;
102
+ }
103
+ function u(e) {
104
+ return `${l(e)} ${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}`;
105
+ }
106
+ var d = {
107
+ date: l,
108
+ dateTime: u
109
+ };
110
+ function f({ date: e, dateTime: t } = {}) {
111
+ d = {
112
+ date: e ?? d.date,
113
+ dateTime: t ?? d.dateTime
114
+ };
115
+ }
116
+ function p(e) {
117
+ let t = c(e);
118
+ return t ? d.date(t) : "";
119
+ }
120
+ function m(e) {
121
+ let t = c(e);
122
+ return t ? d.dateTime(t) : "";
123
+ }
124
+ function h(e) {
125
+ let t = c(e);
126
+ return t ? `${t.getFullYear()}-${s(t.getMonth() + 1)}-${s(t.getDate())}` : null;
127
+ }
128
+ var g = Object.freeze([
129
+ {
130
+ code: "created",
131
+ tone: "success",
132
+ glyph: "plus"
133
+ },
134
+ {
135
+ code: "updated",
136
+ tone: "info",
137
+ glyph: "pencil"
138
+ },
139
+ {
140
+ code: "deleted",
141
+ tone: "danger",
142
+ glyph: "trash"
143
+ },
144
+ {
145
+ code: "restored",
146
+ tone: "accent",
147
+ glyph: "restore"
148
+ },
149
+ {
150
+ code: "attached",
151
+ tone: "success",
152
+ glyph: "link"
153
+ },
154
+ {
155
+ code: "detached",
156
+ tone: "warning",
157
+ glyph: "unlink"
158
+ }
159
+ ]), _ = [
160
+ "created",
161
+ "attached",
162
+ "restored"
163
+ ], v = ["deleted", "detached"];
164
+ function y(e) {
165
+ return g.find((t) => t.code === e) ?? {
166
+ code: e,
167
+ tone: "neutral",
168
+ glyph: "dot"
169
+ };
170
+ }
171
+ function b(e) {
172
+ return e ? String(e).split("\\").pop() : "";
173
+ }
174
+ function x(e, t = "name") {
175
+ return e ? typeof t == "function" ? t(e) : e[t] ?? e.name ?? e.username ?? e.email ?? (e.id === void 0 ? null : `#${e.id}`) : null;
176
+ }
177
+ function S(e) {
178
+ if (e == null || e === "") return "";
179
+ if (typeof e == "boolean") return e ? "true" : "false";
180
+ if (Array.isArray(e) && e.every((e) => typeof e != "object" || !e)) return e.map((e) => S(e) || "—").join(", ");
181
+ if (typeof e == "object") return JSON.stringify(e, null, 2);
182
+ if (typeof e == "string" && /^[[{]/.test(e.trim())) try {
183
+ return S(JSON.parse(e));
184
+ } catch {}
185
+ return String(e);
186
+ }
187
+ function C(e, { format: t = S } = {}) {
188
+ let n = e?.old_values || {}, r = e?.new_values || {};
189
+ return [.../* @__PURE__ */ new Set([...Object.keys(r), ...Object.keys(n)])].map((i) => ({
190
+ field: i,
191
+ oldValue: t(n[i], i, e),
192
+ newValue: t(r[i], i, e)
193
+ }));
194
+ }
195
+ var w = (e) => !!e && Object.keys(e).length > 0;
196
+ function T(e) {
197
+ return _.includes(e?.event) ? !1 : w(e?.old_values) || !w(e?.new_values);
198
+ }
199
+ function E(e) {
200
+ return v.includes(e?.event) ? !1 : w(e?.new_values) || !w(e?.old_values);
201
+ }
202
+ function D(e, t) {
203
+ let n = String(e ?? "");
204
+ return t && n.length > t ? `${n.slice(0, t - 1)}…` : n;
205
+ }
206
+ function O(e = []) {
207
+ let t = [];
208
+ for (let n of e) {
209
+ let e = t[t.length - 1];
210
+ e && n.batch && e.batch === n.batch ? e.audits.push(n) : t.push({
211
+ batch: n.batch ?? null,
212
+ audits: [n]
213
+ });
214
+ }
215
+ return t;
216
+ }
217
+ function k() {
218
+ return {
219
+ search: "",
220
+ event: [],
221
+ user: [],
222
+ auditable_type: [],
223
+ start_date: null,
224
+ end_date: null
225
+ };
226
+ }
227
+ function A(e = {}) {
228
+ return !!(e.search || e.event?.length || e.user?.length || e.auditable_type?.length || e.start_date || e.end_date);
229
+ }
230
+ function j(e, { messages: t, userLabel: n = "name", typeLabel: i = b } = {}) {
231
+ let a = [], o = (e, t) => (n) => ({
232
+ ...n,
233
+ [e]: n[e].filter(t)
234
+ });
235
+ e.search && a.push({
236
+ key: "search",
237
+ field: t.filterSearch,
238
+ label: e.search,
239
+ remove: (e) => ({
240
+ ...e,
241
+ search: ""
242
+ })
243
+ });
244
+ for (let n of e.event ?? []) a.push({
245
+ key: `event-${n}`,
246
+ field: t.filterEvent,
247
+ label: r(t, n),
248
+ remove: o("event", (e) => e !== n)
249
+ });
250
+ for (let r of e.user ?? []) a.push({
251
+ key: `user-${r.id}`,
252
+ field: t.filterUser,
253
+ label: x(r, n),
254
+ remove: o("user", (e) => e.id !== r.id)
255
+ });
256
+ for (let n of e.auditable_type ?? []) a.push({
257
+ key: `type-${n}`,
258
+ field: t.filterResource,
259
+ label: i(n),
260
+ remove: o("auditable_type", (e) => e !== n)
261
+ });
262
+ return e.start_date && a.push({
263
+ key: "start",
264
+ field: t.filterFrom,
265
+ label: p(e.start_date),
266
+ remove: (e) => ({
267
+ ...e,
268
+ start_date: null
269
+ })
270
+ }), e.end_date && a.push({
271
+ key: "end",
272
+ field: t.filterTo,
273
+ label: p(e.end_date),
274
+ remove: (e) => ({
275
+ ...e,
276
+ end_date: null
277
+ })
278
+ }), a;
279
+ }
280
+ function M(e, t, n = 5) {
281
+ let r = Math.max(1, Math.min(e - Math.floor(n / 2), t - n + 1)), i = Math.min(t, r + n - 1);
282
+ return Array.from({ length: i - r + 1 }, (e, t) => r + t);
283
+ }
284
+ function N(e, t, n) {
285
+ return n ? {
286
+ from: (e - 1) * t + 1,
287
+ to: Math.min(e * t, n),
288
+ total: n
289
+ } : null;
290
+ }
291
+ function P(e = {}) {
292
+ return {
293
+ search: e.search || null,
294
+ event: e.event ?? [],
295
+ user: (e.user ?? []).map((e) => typeof e == "object" ? e.id : e),
296
+ auditable_type: e.auditable_type ?? [],
297
+ auditable_id: e.auditable_id ?? null,
298
+ batch: e.batch ?? null,
299
+ start_date: e.start_date || null,
300
+ end_date: e.end_date || null
301
+ };
302
+ }
303
+ export { i as AUDITING_DARK_CLASS, g as AUDIT_EVENTS, e as DEFAULT_MESSAGES, C as auditChanges, y as auditEvent, o as auditingColorScheme, D as clip, l as defaultDateFormatter, u as defaultDateTimeFormatter, k as emptyFilters, r as eventLabel, j as filterChips, p as formatDate, m as formatDateTime, n as formatMessage, S as formatValue, O as groupByBatch, A as hasFilters, t as mergeMessages, N as pageRange, M as pageWindow, c as parseDate, a as setAuditingColorScheme, f as setAuditingDateFormatter, b as shortClassName, E as showsNewValues, T as showsOldValues, h as toIsoDate, P as toParams, x as userName };
304
+
305
+ //# sourceMappingURL=auditing-core.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auditing-core.mjs","names":["DEFAULT_MESSAGES","mergeMessages","sources","formatMessage","template","values","match","key","eventLabel","messages","code","AUDITING_DARK_CLASS","setAuditingColorScheme","scheme","root","auditingColorScheme","pad","number","parseDate","value","text","date","defaultDateFormatter","defaultDateTimeFormatter","formatters","setAuditingDateFormatter","dateTime","formatDate","formatDateTime","toIsoDate","AUDIT_EVENTS","WITHOUT_OLD_VALUES","WITHOUT_NEW_VALUES","auditEvent","event","shortClassName","type","userName","user","userLabel","formatValue","raw","item","auditChanges","audit","format","oldValues","newValues","field","hasValues","showsOldValues","showsNewValues","clip","maxLength","groupByBatch","audits","groups","last","emptyFilters","hasFilters","filters","filterChips","typeLabel","chips","without","predicate","current","other","pageWindow","page","lastPage","size","start","end","_","index","pageRange","perPage","total","toParams"],"sources":["../src/index.js"],"sourcesContent":["export const DEFAULT_MESSAGES = Object.freeze({\n title: 'Listă audit',\n description: '',\n\n event_created: 'Creare',\n event_updated: 'Actualizare',\n event_deleted: 'Ștergere',\n event_restored: 'Restaurare',\n event_attached: 'Asociere',\n event_detached: 'Disociere',\n\n columnEvent: 'Acțiune',\n columnResource: 'Resursă',\n columnUser: 'Utilizator și data',\n columnChanges: 'Modificări',\n columnActions: 'Acțiuni',\n system: 'Sistem',\n\n field: 'Câmp',\n oldValue: 'Valoare veche',\n newValue: 'Valoare nouă',\n noChanges: 'Nu există modificări',\n fieldCount: '{count} câmpuri',\n fieldCountOne: '1 câmp',\n showAllChanges: 'Vezi toate cele {count} modificări',\n changesTitle: 'Modificări ({count})',\n showDetails: 'Vezi detaliile',\n close: 'Închide',\n contextUrl: 'URL',\n contextIp: 'Adresă IP',\n contextUserAgent: 'Browser',\n contextBatch: 'Acțiune (batch)',\n\n searchPlaceholder: 'Caută în valori…',\n filterSearch: 'Căutare',\n filterEvent: 'Acțiune',\n filterUser: 'Utilizator',\n filterResource: 'Resursă',\n filterPeriod: 'Perioadă',\n filterFrom: 'De la',\n filterTo: 'Până la',\n filters: 'Filtre',\n filtersTitle: 'Filtre avansate',\n filtersDescription: 'Combină mai multe criterii. Rezultatele se actualizează la aplicare.',\n apply: 'Aplică',\n applyFilters: 'Aplică filtrele',\n resetShort: 'Resetează',\n allPlaceholder: 'Toate',\n removeFilter: 'Elimină filtrul {filter}',\n clearFilters: 'Șterge filtrele',\n\n selectSearch: 'Caută…',\n selectEmpty: 'Niciun rezultat',\n selectLoading: 'Se încarcă…',\n selectedCount: '{count} selectate',\n\n loading: 'Se încarcă…',\n result: 'rezultat',\n results: 'rezultate',\n empty: 'Nicio înregistrare găsită',\n emptyHint: 'Încearcă alt termen de căutare sau resetează filtrele.',\n resetFilters: 'Resetează filtrele',\n loadFailed: 'Datele nu au putut fi încărcate',\n\n historyTitle: 'Audit resursă',\n historyDescription: 'Modificările acestei înregistrări, cele mai noi primele.',\n historyEmpty: 'Nu există istoric audit resursă',\n historyButton: 'Istoric',\n batchTitle: 'Aceeași acțiune',\n batchDescription: 'Tot ce a scris aceeași cerere, comandă sau job.',\n selectedRecord: 'Înregistrare selectată',\n sameBatch: '{count} modificări în aceeași acțiune',\n becomes: 'devine',\n\n retry: 'Reîncearcă',\n refresh: 'Reîmprospătează',\n\n pagination: 'Paginare',\n rowsPerPage: 'Rânduri pe pagină',\n pageRange: '{from}–{to} din {total}',\n pageRangeEmpty: '0 rezultate',\n previousPage: 'Pagina anterioară',\n nextPage: 'Pagina următoare'\n})\n\nexport function mergeMessages(...sources) {\n return Object.assign({}, DEFAULT_MESSAGES, ...sources.filter(Boolean))\n}\n\nexport function formatMessage(template, values = {}) {\n return String(template ?? '').replace(/\\{(\\w+)\\}/g, (match, key) => (key in values ? String(values[key]) : match))\n}\n\nexport function eventLabel(messages, code) {\n return messages[`event_${code}`] ?? code\n}\n\nexport const AUDITING_DARK_CLASS = 'dark'\n\nexport function setAuditingColorScheme(scheme, root = typeof document !== 'undefined' ? document.documentElement : null) {\n root?.classList.toggle(AUDITING_DARK_CLASS, scheme === 'dark')\n}\n\nexport function auditingColorScheme(root = typeof document !== 'undefined' ? document.documentElement : null) {\n if (!root) {\n return null\n }\n return root.classList.contains(AUDITING_DARK_CLASS) ? 'dark' : 'light'\n}\n\nconst pad = (number) => String(number).padStart(2, '0')\n\nexport function parseDate(value) {\n if (!value) {\n return null\n }\n if (value instanceof Date) {\n return Number.isNaN(value.getTime()) ? null : value\n }\n const text = String(value)\n const date = /^\\d{4}-\\d{2}-\\d{2}$/.test(text) ? new Date(`${text}T00:00:00`) : new Date(text.replace(' ', 'T'))\n return Number.isNaN(date.getTime()) ? null : date\n}\n\nexport function defaultDateFormatter(date) {\n return `${pad(date.getDate())}.${pad(date.getMonth() + 1)}.${date.getFullYear()}`\n}\n\nexport function defaultDateTimeFormatter(date) {\n return `${defaultDateFormatter(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`\n}\n\nlet formatters = { date: defaultDateFormatter, dateTime: defaultDateTimeFormatter }\n\nexport function setAuditingDateFormatter({ date, dateTime } = {}) {\n formatters = { date: date ?? formatters.date, dateTime: dateTime ?? formatters.dateTime }\n}\n\nexport function formatDate(value) {\n const date = parseDate(value)\n return date ? formatters.date(date) : ''\n}\n\nexport function formatDateTime(value) {\n const date = parseDate(value)\n return date ? formatters.dateTime(date) : ''\n}\n\nexport function toIsoDate(value) {\n const date = parseDate(value)\n return date ? `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` : null\n}\n\nexport const AUDIT_EVENTS = Object.freeze([\n { code: 'created', tone: 'success', glyph: 'plus' },\n { code: 'updated', tone: 'info', glyph: 'pencil' },\n { code: 'deleted', tone: 'danger', glyph: 'trash' },\n { code: 'restored', tone: 'accent', glyph: 'restore' },\n { code: 'attached', tone: 'success', glyph: 'link' },\n { code: 'detached', tone: 'warning', glyph: 'unlink' }\n])\n\nconst WITHOUT_OLD_VALUES = ['created', 'attached', 'restored']\nconst WITHOUT_NEW_VALUES = ['deleted', 'detached']\n\nexport function auditEvent(code) {\n return AUDIT_EVENTS.find((event) => event.code === code) ?? { code, tone: 'neutral', glyph: 'dot' }\n}\n\nexport function shortClassName(type) {\n return type ? String(type).split('\\\\').pop() : ''\n}\n\nexport function userName(user, userLabel = 'name') {\n if (!user) {\n return null\n }\n if (typeof userLabel === 'function') {\n return userLabel(user)\n }\n return user[userLabel] ?? user.name ?? user.username ?? user.email ?? (user.id !== undefined ? `#${user.id}` : null)\n}\n\nexport function formatValue(raw) {\n if (raw === null || raw === undefined || raw === '') {\n return ''\n }\n if (typeof raw === 'boolean') {\n return raw ? 'true' : 'false'\n }\n if (Array.isArray(raw) && raw.every((item) => item === null || typeof item !== 'object')) {\n return raw.map((item) => formatValue(item) || '—').join(', ')\n }\n if (typeof raw === 'object') {\n return JSON.stringify(raw, null, 2)\n }\n if (typeof raw === 'string' && /^[[{]/.test(raw.trim())) {\n try {\n return formatValue(JSON.parse(raw))\n } catch {\n }\n }\n return String(raw)\n}\n\nexport function auditChanges(audit, { format = formatValue } = {}) {\n const oldValues = audit?.old_values || {}\n const newValues = audit?.new_values || {}\n const fields = [...new Set([...Object.keys(newValues), ...Object.keys(oldValues)])]\n\n return fields.map((field) => ({\n field,\n oldValue: format(oldValues[field], field, audit),\n newValue: format(newValues[field], field, audit)\n }))\n}\n\nconst hasValues = (values) => Boolean(values) && Object.keys(values).length > 0\n\nexport function showsOldValues(audit) {\n if (WITHOUT_OLD_VALUES.includes(audit?.event)) {\n return false\n }\n return hasValues(audit?.old_values) || !hasValues(audit?.new_values)\n}\n\nexport function showsNewValues(audit) {\n if (WITHOUT_NEW_VALUES.includes(audit?.event)) {\n return false\n }\n return hasValues(audit?.new_values) || !hasValues(audit?.old_values)\n}\n\nexport function clip(text, maxLength) {\n const value = String(text ?? '')\n return maxLength && value.length > maxLength ? `${value.slice(0, maxLength - 1)}…` : value\n}\n\nexport function groupByBatch(audits = []) {\n const groups = []\n\n for (const audit of audits) {\n const last = groups[groups.length - 1]\n if (last && audit.batch && last.batch === audit.batch) {\n last.audits.push(audit)\n } else {\n groups.push({ batch: audit.batch ?? null, audits: [audit] })\n }\n }\n\n return groups\n}\n\nexport function emptyFilters() {\n return { search: '', event: [], user: [], auditable_type: [], start_date: null, end_date: null }\n}\n\nexport function hasFilters(filters = {}) {\n return Boolean(\n filters.search\n || filters.event?.length\n || filters.user?.length\n || filters.auditable_type?.length\n || filters.start_date\n || filters.end_date\n )\n}\n\nexport function filterChips(filters, { messages, userLabel = 'name', typeLabel = shortClassName } = {}) {\n const chips = []\n const without = (key, predicate) => (current) => ({ ...current, [key]: current[key].filter(predicate) })\n\n if (filters.search) {\n chips.push({ key: 'search', field: messages.filterSearch, label: filters.search, remove: (current) => ({ ...current, search: '' }) })\n }\n for (const code of filters.event ?? []) {\n chips.push({ key: `event-${code}`, field: messages.filterEvent, label: eventLabel(messages, code), remove: without('event', (other) => other !== code) })\n }\n for (const user of filters.user ?? []) {\n chips.push({ key: `user-${user.id}`, field: messages.filterUser, label: userName(user, userLabel), remove: without('user', (other) => other.id !== user.id) })\n }\n for (const type of filters.auditable_type ?? []) {\n chips.push({ key: `type-${type}`, field: messages.filterResource, label: typeLabel(type), remove: without('auditable_type', (other) => other !== type) })\n }\n if (filters.start_date) {\n chips.push({ key: 'start', field: messages.filterFrom, label: formatDate(filters.start_date), remove: (current) => ({ ...current, start_date: null }) })\n }\n if (filters.end_date) {\n chips.push({ key: 'end', field: messages.filterTo, label: formatDate(filters.end_date), remove: (current) => ({ ...current, end_date: null }) })\n }\n\n return chips\n}\n\nexport function pageWindow(page, lastPage, size = 5) {\n const start = Math.max(1, Math.min(page - Math.floor(size / 2), lastPage - size + 1))\n const end = Math.min(lastPage, start + size - 1)\n return Array.from({ length: end - start + 1 }, (_, index) => start + index)\n}\n\nexport function pageRange(page, perPage, total) {\n if (!total) {\n return null\n }\n return { from: (page - 1) * perPage + 1, to: Math.min(page * perPage, total), total }\n}\n\nexport function toParams(filters = {}) {\n return {\n search: filters.search || null,\n event: filters.event ?? [],\n user: (filters.user ?? []).map((user) => (typeof user === 'object' ? user.id : user)),\n auditable_type: filters.auditable_type ?? [],\n auditable_id: filters.auditable_id ?? null,\n batch: filters.batch ?? null,\n start_date: filters.start_date || null,\n end_date: filters.end_date || null\n }\n}\n"],"mappings":";AAAA,IAAaA,IAAmB,OAAO,OAAO;CAC5C,OAAO;CACP,aAAa;CAEb,eAAe;CACf,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAEhB,aAAa;CACb,gBAAgB;CAChB,YAAY;CACZ,eAAe;CACf,eAAe;CACf,QAAQ;CAER,OAAO;CACP,UAAU;CACV,UAAU;CACV,WA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AI9C,OAHKA,IAGE;EAAE,OAAOT,IAAO,KAAKQ,IAAU;EAAG,IAAI,KAAK,IAAIR,IAAOQ,GAASC,CAAK;EAAGA;CAAM,IAF3E;AAGX;AAEA,SAAgBC,EAASnB,IAAU,CAAC,GAAG;CACrC,OAAO;EACL,QAAQA,EAAQ,UAAU;EAC1B,OAAOA,EAAQ,SAAS,CAAC;EACzB,OAAOA,EAAQ,QAAQ,CAAC,EAAA,CAAG,KAAKtB,MAAU,OAAOA,KAAS,WAAWA,EAAK,KAAKA,CAAK;EACpF,gBAAgBsB,EAAQ,kBAAkB,CAAC;EAC3C,cAAcA,EAAQ,gBAAgB;EACtC,OAAOA,EAAQ,SAAS;EACxB,YAAYA,EAAQ,cAAc;EAClC,UAAUA,EAAQ,YAAY;CAChC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@stsdti/auditing-core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "version": "0.1.5",
5
+ "description": "Framework-agnostic client, domain helpers and view-model derivations for laravel-auditing.",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/stsdti/laravel-auditing/tree/main/packages/frontends/core",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/stsdti/laravel-auditing.git",
11
+ "directory": "packages/frontends/core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/stsdti/laravel-auditing/issues"
15
+ },
16
+ "keywords": [
17
+ "laravel",
18
+ "audit",
19
+ "auditing"
20
+ ],
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": "./dist/auditing-core.mjs",
24
+ "./src/*": "./src/*",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "module": "./dist/auditing-core.mjs",
28
+ "files": [
29
+ "LICENSE",
30
+ "README.md",
31
+ "dist",
32
+ "src"
33
+ ],
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "scripts": {
38
+ "build": "vite build",
39
+ "build:watch": "vite build --watch",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "devDependencies": {
43
+ "vite": "^8.4.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }
package/src/index.js ADDED
@@ -0,0 +1,319 @@
1
+ export const DEFAULT_MESSAGES = Object.freeze({
2
+ title: 'Listă audit',
3
+ description: '',
4
+
5
+ event_created: 'Creare',
6
+ event_updated: 'Actualizare',
7
+ event_deleted: 'Ștergere',
8
+ event_restored: 'Restaurare',
9
+ event_attached: 'Asociere',
10
+ event_detached: 'Disociere',
11
+
12
+ columnEvent: 'Acțiune',
13
+ columnResource: 'Resursă',
14
+ columnUser: 'Utilizator și data',
15
+ columnChanges: 'Modificări',
16
+ columnActions: 'Acțiuni',
17
+ system: 'Sistem',
18
+
19
+ field: 'Câmp',
20
+ oldValue: 'Valoare veche',
21
+ newValue: 'Valoare nouă',
22
+ noChanges: 'Nu există modificări',
23
+ fieldCount: '{count} câmpuri',
24
+ fieldCountOne: '1 câmp',
25
+ showAllChanges: 'Vezi toate cele {count} modificări',
26
+ changesTitle: 'Modificări ({count})',
27
+ showDetails: 'Vezi detaliile',
28
+ close: 'Închide',
29
+ contextUrl: 'URL',
30
+ contextIp: 'Adresă IP',
31
+ contextUserAgent: 'Browser',
32
+ contextBatch: 'Acțiune (batch)',
33
+
34
+ searchPlaceholder: 'Caută în valori…',
35
+ filterSearch: 'Căutare',
36
+ filterEvent: 'Acțiune',
37
+ filterUser: 'Utilizator',
38
+ filterResource: 'Resursă',
39
+ filterPeriod: 'Perioadă',
40
+ filterFrom: 'De la',
41
+ filterTo: 'Până la',
42
+ filters: 'Filtre',
43
+ filtersTitle: 'Filtre avansate',
44
+ filtersDescription: 'Combină mai multe criterii. Rezultatele se actualizează la aplicare.',
45
+ apply: 'Aplică',
46
+ applyFilters: 'Aplică filtrele',
47
+ resetShort: 'Resetează',
48
+ allPlaceholder: 'Toate',
49
+ removeFilter: 'Elimină filtrul {filter}',
50
+ clearFilters: 'Șterge filtrele',
51
+
52
+ selectSearch: 'Caută…',
53
+ selectEmpty: 'Niciun rezultat',
54
+ selectLoading: 'Se încarcă…',
55
+ selectedCount: '{count} selectate',
56
+
57
+ loading: 'Se încarcă…',
58
+ result: 'rezultat',
59
+ results: 'rezultate',
60
+ empty: 'Nicio înregistrare găsită',
61
+ emptyHint: 'Încearcă alt termen de căutare sau resetează filtrele.',
62
+ resetFilters: 'Resetează filtrele',
63
+ loadFailed: 'Datele nu au putut fi încărcate',
64
+
65
+ historyTitle: 'Audit resursă',
66
+ historyDescription: 'Modificările acestei înregistrări, cele mai noi primele.',
67
+ historyEmpty: 'Nu există istoric audit resursă',
68
+ historyButton: 'Istoric',
69
+ batchTitle: 'Aceeași acțiune',
70
+ batchDescription: 'Tot ce a scris aceeași cerere, comandă sau job.',
71
+ selectedRecord: 'Înregistrare selectată',
72
+ sameBatch: '{count} modificări în aceeași acțiune',
73
+ becomes: 'devine',
74
+
75
+ retry: 'Reîncearcă',
76
+ refresh: 'Reîmprospătează',
77
+
78
+ pagination: 'Paginare',
79
+ rowsPerPage: 'Rânduri pe pagină',
80
+ pageRange: '{from}–{to} din {total}',
81
+ pageRangeEmpty: '0 rezultate',
82
+ previousPage: 'Pagina anterioară',
83
+ nextPage: 'Pagina următoare'
84
+ })
85
+
86
+ export function mergeMessages(...sources) {
87
+ return Object.assign({}, DEFAULT_MESSAGES, ...sources.filter(Boolean))
88
+ }
89
+
90
+ export function formatMessage(template, values = {}) {
91
+ return String(template ?? '').replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match))
92
+ }
93
+
94
+ export function eventLabel(messages, code) {
95
+ return messages[`event_${code}`] ?? code
96
+ }
97
+
98
+ export const AUDITING_DARK_CLASS = 'dark'
99
+
100
+ export function setAuditingColorScheme(scheme, root = typeof document !== 'undefined' ? document.documentElement : null) {
101
+ root?.classList.toggle(AUDITING_DARK_CLASS, scheme === 'dark')
102
+ }
103
+
104
+ export function auditingColorScheme(root = typeof document !== 'undefined' ? document.documentElement : null) {
105
+ if (!root) {
106
+ return null
107
+ }
108
+ return root.classList.contains(AUDITING_DARK_CLASS) ? 'dark' : 'light'
109
+ }
110
+
111
+ const pad = (number) => String(number).padStart(2, '0')
112
+
113
+ export function parseDate(value) {
114
+ if (!value) {
115
+ return null
116
+ }
117
+ if (value instanceof Date) {
118
+ return Number.isNaN(value.getTime()) ? null : value
119
+ }
120
+ const text = String(value)
121
+ const date = /^\d{4}-\d{2}-\d{2}$/.test(text) ? new Date(`${text}T00:00:00`) : new Date(text.replace(' ', 'T'))
122
+ return Number.isNaN(date.getTime()) ? null : date
123
+ }
124
+
125
+ export function defaultDateFormatter(date) {
126
+ return `${pad(date.getDate())}.${pad(date.getMonth() + 1)}.${date.getFullYear()}`
127
+ }
128
+
129
+ export function defaultDateTimeFormatter(date) {
130
+ return `${defaultDateFormatter(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
131
+ }
132
+
133
+ let formatters = { date: defaultDateFormatter, dateTime: defaultDateTimeFormatter }
134
+
135
+ export function setAuditingDateFormatter({ date, dateTime } = {}) {
136
+ formatters = { date: date ?? formatters.date, dateTime: dateTime ?? formatters.dateTime }
137
+ }
138
+
139
+ export function formatDate(value) {
140
+ const date = parseDate(value)
141
+ return date ? formatters.date(date) : ''
142
+ }
143
+
144
+ export function formatDateTime(value) {
145
+ const date = parseDate(value)
146
+ return date ? formatters.dateTime(date) : ''
147
+ }
148
+
149
+ export function toIsoDate(value) {
150
+ const date = parseDate(value)
151
+ return date ? `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` : null
152
+ }
153
+
154
+ export const AUDIT_EVENTS = Object.freeze([
155
+ { code: 'created', tone: 'success', glyph: 'plus' },
156
+ { code: 'updated', tone: 'info', glyph: 'pencil' },
157
+ { code: 'deleted', tone: 'danger', glyph: 'trash' },
158
+ { code: 'restored', tone: 'accent', glyph: 'restore' },
159
+ { code: 'attached', tone: 'success', glyph: 'link' },
160
+ { code: 'detached', tone: 'warning', glyph: 'unlink' }
161
+ ])
162
+
163
+ const WITHOUT_OLD_VALUES = ['created', 'attached', 'restored']
164
+ const WITHOUT_NEW_VALUES = ['deleted', 'detached']
165
+
166
+ export function auditEvent(code) {
167
+ return AUDIT_EVENTS.find((event) => event.code === code) ?? { code, tone: 'neutral', glyph: 'dot' }
168
+ }
169
+
170
+ export function shortClassName(type) {
171
+ return type ? String(type).split('\\').pop() : ''
172
+ }
173
+
174
+ export function userName(user, userLabel = 'name') {
175
+ if (!user) {
176
+ return null
177
+ }
178
+ if (typeof userLabel === 'function') {
179
+ return userLabel(user)
180
+ }
181
+ return user[userLabel] ?? user.name ?? user.username ?? user.email ?? (user.id !== undefined ? `#${user.id}` : null)
182
+ }
183
+
184
+ export function formatValue(raw) {
185
+ if (raw === null || raw === undefined || raw === '') {
186
+ return ''
187
+ }
188
+ if (typeof raw === 'boolean') {
189
+ return raw ? 'true' : 'false'
190
+ }
191
+ if (Array.isArray(raw) && raw.every((item) => item === null || typeof item !== 'object')) {
192
+ return raw.map((item) => formatValue(item) || '—').join(', ')
193
+ }
194
+ if (typeof raw === 'object') {
195
+ return JSON.stringify(raw, null, 2)
196
+ }
197
+ if (typeof raw === 'string' && /^[[{]/.test(raw.trim())) {
198
+ try {
199
+ return formatValue(JSON.parse(raw))
200
+ } catch {
201
+ }
202
+ }
203
+ return String(raw)
204
+ }
205
+
206
+ export function auditChanges(audit, { format = formatValue } = {}) {
207
+ const oldValues = audit?.old_values || {}
208
+ const newValues = audit?.new_values || {}
209
+ const fields = [...new Set([...Object.keys(newValues), ...Object.keys(oldValues)])]
210
+
211
+ return fields.map((field) => ({
212
+ field,
213
+ oldValue: format(oldValues[field], field, audit),
214
+ newValue: format(newValues[field], field, audit)
215
+ }))
216
+ }
217
+
218
+ const hasValues = (values) => Boolean(values) && Object.keys(values).length > 0
219
+
220
+ export function showsOldValues(audit) {
221
+ if (WITHOUT_OLD_VALUES.includes(audit?.event)) {
222
+ return false
223
+ }
224
+ return hasValues(audit?.old_values) || !hasValues(audit?.new_values)
225
+ }
226
+
227
+ export function showsNewValues(audit) {
228
+ if (WITHOUT_NEW_VALUES.includes(audit?.event)) {
229
+ return false
230
+ }
231
+ return hasValues(audit?.new_values) || !hasValues(audit?.old_values)
232
+ }
233
+
234
+ export function clip(text, maxLength) {
235
+ const value = String(text ?? '')
236
+ return maxLength && value.length > maxLength ? `${value.slice(0, maxLength - 1)}…` : value
237
+ }
238
+
239
+ export function groupByBatch(audits = []) {
240
+ const groups = []
241
+
242
+ for (const audit of audits) {
243
+ const last = groups[groups.length - 1]
244
+ if (last && audit.batch && last.batch === audit.batch) {
245
+ last.audits.push(audit)
246
+ } else {
247
+ groups.push({ batch: audit.batch ?? null, audits: [audit] })
248
+ }
249
+ }
250
+
251
+ return groups
252
+ }
253
+
254
+ export function emptyFilters() {
255
+ return { search: '', event: [], user: [], auditable_type: [], start_date: null, end_date: null }
256
+ }
257
+
258
+ export function hasFilters(filters = {}) {
259
+ return Boolean(
260
+ filters.search
261
+ || filters.event?.length
262
+ || filters.user?.length
263
+ || filters.auditable_type?.length
264
+ || filters.start_date
265
+ || filters.end_date
266
+ )
267
+ }
268
+
269
+ export function filterChips(filters, { messages, userLabel = 'name', typeLabel = shortClassName } = {}) {
270
+ const chips = []
271
+ const without = (key, predicate) => (current) => ({ ...current, [key]: current[key].filter(predicate) })
272
+
273
+ if (filters.search) {
274
+ chips.push({ key: 'search', field: messages.filterSearch, label: filters.search, remove: (current) => ({ ...current, search: '' }) })
275
+ }
276
+ for (const code of filters.event ?? []) {
277
+ chips.push({ key: `event-${code}`, field: messages.filterEvent, label: eventLabel(messages, code), remove: without('event', (other) => other !== code) })
278
+ }
279
+ for (const user of filters.user ?? []) {
280
+ chips.push({ key: `user-${user.id}`, field: messages.filterUser, label: userName(user, userLabel), remove: without('user', (other) => other.id !== user.id) })
281
+ }
282
+ for (const type of filters.auditable_type ?? []) {
283
+ chips.push({ key: `type-${type}`, field: messages.filterResource, label: typeLabel(type), remove: without('auditable_type', (other) => other !== type) })
284
+ }
285
+ if (filters.start_date) {
286
+ chips.push({ key: 'start', field: messages.filterFrom, label: formatDate(filters.start_date), remove: (current) => ({ ...current, start_date: null }) })
287
+ }
288
+ if (filters.end_date) {
289
+ chips.push({ key: 'end', field: messages.filterTo, label: formatDate(filters.end_date), remove: (current) => ({ ...current, end_date: null }) })
290
+ }
291
+
292
+ return chips
293
+ }
294
+
295
+ export function pageWindow(page, lastPage, size = 5) {
296
+ const start = Math.max(1, Math.min(page - Math.floor(size / 2), lastPage - size + 1))
297
+ const end = Math.min(lastPage, start + size - 1)
298
+ return Array.from({ length: end - start + 1 }, (_, index) => start + index)
299
+ }
300
+
301
+ export function pageRange(page, perPage, total) {
302
+ if (!total) {
303
+ return null
304
+ }
305
+ return { from: (page - 1) * perPage + 1, to: Math.min(page * perPage, total), total }
306
+ }
307
+
308
+ export function toParams(filters = {}) {
309
+ return {
310
+ search: filters.search || null,
311
+ event: filters.event ?? [],
312
+ user: (filters.user ?? []).map((user) => (typeof user === 'object' ? user.id : user)),
313
+ auditable_type: filters.auditable_type ?? [],
314
+ auditable_id: filters.auditable_id ?? null,
315
+ batch: filters.batch ?? null,
316
+ start_date: filters.start_date || null,
317
+ end_date: filters.end_date || null
318
+ }
319
+ }