@lpdjs/firestore-repo-service 3.0.14 → 3.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/actor-context-DQZgWqj3.d.cts +117 -0
  2. package/dist/actor-context-DQZgWqj3.d.ts +117 -0
  3. package/dist/{create-servers-BwbKPcBG.d.cts → create-servers-B5Z5v2SP.d.cts} +11 -5
  4. package/dist/{create-servers-DVCB8BKC.d.ts → create-servers-p1-jJNTG.d.ts} +11 -5
  5. package/dist/history/index.cjs +1 -1
  6. package/dist/history/index.cjs.map +1 -1
  7. package/dist/history/index.d.cts +67 -7
  8. package/dist/history/index.d.ts +67 -7
  9. package/dist/history/index.js +1 -1
  10. package/dist/history/index.js.map +1 -1
  11. package/dist/index.cjs +81 -81
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +12 -10
  14. package/dist/index.d.ts +12 -10
  15. package/dist/index.js +81 -81
  16. package/dist/index.js.map +1 -1
  17. package/dist/llms-full.txt +1 -1
  18. package/dist/llms.txt +1 -1
  19. package/dist/{openapi-DZp7mW-s.d.cts → openapi-B9utXiEH.d.cts} +1 -1
  20. package/dist/{openapi-B0s5qVSg.d.ts → openapi-Bsqq2zgh.d.ts} +1 -1
  21. package/dist/{queue-aNhdaNGW.d.ts → queue-NFod6hTT.d.ts} +1 -1
  22. package/dist/{queue-B0rkiPZF.d.cts → queue-zw2B7GPx.d.cts} +1 -1
  23. package/dist/{read-15-TcgCz.d.ts → read-BPov7lws.d.ts} +30 -7
  24. package/dist/{read-B15YaPyR.d.cts → read-Dfah1PPl.d.cts} +30 -7
  25. package/dist/{rules-DNJV8yxi.d.ts → rules-18wH7Uak.d.ts} +1 -1
  26. package/dist/{rules-BV3-D08Y.d.cts → rules-oSXoV4Js.d.cts} +1 -1
  27. package/dist/servers/admin/index.cjs +5 -5
  28. package/dist/servers/admin/index.cjs.map +1 -1
  29. package/dist/servers/admin/index.d.cts +5 -4
  30. package/dist/servers/admin/index.d.ts +5 -4
  31. package/dist/servers/admin/index.js +5 -5
  32. package/dist/servers/admin/index.js.map +1 -1
  33. package/dist/servers/crud/index.cjs +2 -2
  34. package/dist/servers/crud/index.cjs.map +1 -1
  35. package/dist/servers/crud/index.d.cts +10 -9
  36. package/dist/servers/crud/index.d.ts +10 -9
  37. package/dist/servers/crud/index.js +2 -2
  38. package/dist/servers/crud/index.js.map +1 -1
  39. package/dist/servers/hono/index.cjs +14 -14
  40. package/dist/servers/hono/index.cjs.map +1 -1
  41. package/dist/servers/hono/index.d.cts +11 -3
  42. package/dist/servers/hono/index.d.ts +11 -3
  43. package/dist/servers/hono/index.js +14 -14
  44. package/dist/servers/hono/index.js.map +1 -1
  45. package/dist/servers/index.cjs +94 -94
  46. package/dist/servers/index.cjs.map +1 -1
  47. package/dist/servers/index.d.cts +13 -12
  48. package/dist/servers/index.d.ts +13 -12
  49. package/dist/servers/index.js +94 -94
  50. package/dist/servers/index.js.map +1 -1
  51. package/dist/sync/bigquery.d.cts +2 -2
  52. package/dist/sync/bigquery.d.ts +2 -2
  53. package/dist/sync/index.cjs +55 -55
  54. package/dist/sync/index.cjs.map +1 -1
  55. package/dist/sync/index.d.cts +6 -6
  56. package/dist/sync/index.d.ts +6 -6
  57. package/dist/sync/index.js +55 -55
  58. package/dist/sync/index.js.map +1 -1
  59. package/dist/sync/meilisearch.cjs +2 -2
  60. package/dist/sync/meilisearch.cjs.map +1 -1
  61. package/dist/sync/meilisearch.d.cts +2 -2
  62. package/dist/sync/meilisearch.d.ts +2 -2
  63. package/dist/sync/meilisearch.js +2 -2
  64. package/dist/sync/meilisearch.js.map +1 -1
  65. package/dist/{types-o-9qoExc.d.cts → types-BDTx8VPg.d.cts} +8 -0
  66. package/dist/{types-Cko118ZS.d.cts → types-BGh5_2fl.d.cts} +4 -4
  67. package/dist/{types-dDxiibCW.d.ts → types-B_FrzmO4.d.ts} +1 -1
  68. package/dist/{types-BuggDko0.d.ts → types-Cc6lelk1.d.ts} +4 -4
  69. package/dist/{types--RamYGF1.d.cts → types-D6zvWzRt.d.cts} +96 -2
  70. package/dist/{types--RamYGF1.d.ts → types-D6zvWzRt.d.ts} +96 -2
  71. package/dist/{types-Dvst2iLQ.d.cts → types-D78FPJeF.d.cts} +1 -1
  72. package/dist/{types-BFu2DpKn.d.cts → types-Dc3lX99O.d.cts} +1 -1
  73. package/dist/{types-BvJYEGa1.d.ts → types-DgFJLwAu.d.ts} +1 -1
  74. package/dist/{types-D3W_RaDA.d.ts → types-w1rEqs0Z.d.ts} +8 -0
  75. package/package.json +1 -1
@@ -16,7 +16,32 @@ import { DocumentOptions, onDocumentWritten } from 'firebase-functions/v2/firest
16
16
  */
17
17
  type TriggerOptions = Omit<DocumentOptions, "document">;
18
18
  type HistoryTriggerOptions = TriggerOptions;
19
- type HistoryOperation = "create" | "update" | "delete";
19
+ type HistoryOperation = "create" | "update" | "delete" | "custom";
20
+ /**
21
+ * Structured payload attached to `operation: "custom"` history entries
22
+ * (business actions independent of model fields, e.g. manual invoice creation,
23
+ * PDF export, email sent, etc.).
24
+ */
25
+ interface HistoryCustomData {
26
+ /** Human-readable title (e.g. `"Création de la facture"`). */
27
+ title: string;
28
+ /** Optional human-readable description (e.g. `"Facture #F-2026-042 créée manuellement"`). */
29
+ description?: string;
30
+ /** Optional business action key for filtering/grouping/icons (e.g. `"invoice_create_manually"`). */
31
+ key?: string;
32
+ /** Optional front-end visibility flag (default: `true`). */
33
+ display?: boolean;
34
+ /** Optional arbitrary structured business payload (e.g. `{ invoiceId, amount }`). */
35
+ data?: Record<string, unknown>;
36
+ }
37
+ /** Input payload accepted by `repo.history.recordCustom(...)`. */
38
+ interface HistoryCustomInput extends HistoryCustomData {
39
+ /**
40
+ * Optional metadata overrides (`reason`, `comment`, `extras`, `userId`,
41
+ * `userEmail`). Automatically merged on top of the active ALS actor.
42
+ */
43
+ meta?: HistoryMeta;
44
+ }
20
45
  /**
21
46
  * Detected JS/Firestore type of a value as stored in a history entry.
22
47
  * Matches the values returned by {@link valueType}.
@@ -57,6 +82,8 @@ interface HistoryEntry<T = Record<string, unknown>> {
57
82
  operation: HistoryOperation;
58
83
  /** Captured author / context information. */
59
84
  meta: HistoryMeta;
85
+ /** Present on `operation: "custom"` entries (business actions independent of model fields). */
86
+ custom?: HistoryCustomData;
60
87
  /** Per-field changes. Keys are field names of T. */
61
88
  changes: {
62
89
  [K in keyof T & string]?: HistoryFieldChange;
@@ -72,6 +99,8 @@ interface V2HistoryDoc {
72
99
  historySetAt: Timestamp;
73
100
  operation: HistoryOperation;
74
101
  meta: HistoryMeta;
102
+ /** Present on `operation: "custom"` entries. */
103
+ custom?: HistoryCustomData;
75
104
  changes: Record<string, HistoryFieldChange>;
76
105
  /** Optional TTL marker (Firestore deletes the doc after this date). */
77
106
  expiresAt?: Timestamp;
@@ -105,6 +134,49 @@ interface V1HistoryDoc {
105
134
  extraContentKeys?: Record<string, unknown> | null;
106
135
  objectType?: string;
107
136
  }
137
+ /** Default top-level shadow field name stored on Firestore documents for auto-injected history metadata. */
138
+ declare const DEFAULT_HISTORY_SHADOW_KEY = "_historyMeta";
139
+ /**
140
+ * Customize (or disable via `false`) the sub-field names stored inside the
141
+ * shadow metadata object on Firestore documents.
142
+ */
143
+ interface HistoryShadowFieldsConfig {
144
+ /** Key inside the shadow object for author userId, or `false` to omit. Default: `"userId"`. */
145
+ userId?: string | false;
146
+ /** Key inside the shadow object for author userEmail, or `false` to omit. Default: `"userEmail"`. */
147
+ userEmail?: string | false;
148
+ /** Key inside the shadow object for change reason, or `false` to omit. Default: `"reason"`. */
149
+ reason?: string | false;
150
+ /** Key inside the shadow object for change comment, or `false` to omit. Default: `"comment"`. */
151
+ comment?: string | false;
152
+ /** Key inside the shadow object for extras map, or `false` to omit. Default: `"extras"`. */
153
+ extras?: string | false;
154
+ }
155
+ /**
156
+ * Configuration for the internal shadow field used to transport actor metadata
157
+ * to Firestore `onDocumentWritten` triggers without modifying Zod schemas.
158
+ */
159
+ interface HistoryShadowConfig {
160
+ /**
161
+ * Top-level field name stored on the Firestore document (not required in the
162
+ * Zod schema, automatically excluded from diffs and sync, and stripped on read).
163
+ * Default: `"_historyMeta"`.
164
+ */
165
+ key?: string;
166
+ /**
167
+ * Customize or disable individual sub-field names inside the shadow object.
168
+ * Default: `{ userId: "userId", userEmail: "userEmail", reason: "reason", comment: "comment", extras: "extras" }`.
169
+ */
170
+ fields?: HistoryShadowFieldsConfig;
171
+ }
172
+ /**
173
+ * Fallback author values written when no actor is active in `AsyncLocalStorage`
174
+ * (crons, scripts, admin UI, public routes).
175
+ */
176
+ interface HistoryFallbackActor {
177
+ userId?: string | null;
178
+ userEmail?: string | null;
179
+ }
108
180
  /**
109
181
  * Per-repo history configuration. Attached on the repository config under
110
182
  * the `history` key. All meta sub-keys must reference fields that exist on
@@ -115,6 +187,27 @@ interface HistoryConfigBase {
115
187
  enabled: boolean;
116
188
  /** Subcollection name used to store history docs. Default: "history". */
117
189
  subcollection?: string;
190
+ /**
191
+ * Automatically inject actor metadata from `AsyncLocalStorage` into the
192
+ * shadow field on repository writes (`create`, `set`, `update`, `batch`,
193
+ * `transaction`, `bulk`). Default: `true` when `enabled: true`.
194
+ */
195
+ autoInjectMeta?: boolean;
196
+ /**
197
+ * Shadow field configuration (zero Zod schema changes).
198
+ *
199
+ * - Omitted or `true` (when `meta` is absent): uses `"_historyMeta"` with default sub-fields.
200
+ * - `string`: shorthand for `{ key: "<customKey>" }`.
201
+ * - `HistoryShadowConfig`: customize both `key` and nested `fields`.
202
+ * - `false`: disable shadow metadata injection/reading.
203
+ */
204
+ shadow?: boolean | string | HistoryShadowConfig;
205
+ /**
206
+ * Fallback actor written when no actor is active in `AsyncLocalStorage` so
207
+ * previous author metadata never leaks onto subsequent writes.
208
+ * Default: `{ userId: null, userEmail: null }`.
209
+ */
210
+ fallbackActor?: HistoryFallbackActor;
118
211
  /**
119
212
  * Optional Firestore TTL configuration. When set, every written history doc
120
213
  * gets an `expiresAt` Timestamp at `now + days`. You still need to enable
@@ -219,4 +312,5 @@ interface HistoryTriggersConfig<M = Record<string, any>> {
219
312
  repos?: Partial<Record<keyof M & string, HistoryTriggerRepoOverride>>;
220
313
  }
221
314
 
222
- export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryConfigForModel as g, HistoryFieldChange as h, HistoryValueType as i, HistoryConfigBase as j, HistoryFirestoreTriggersDep as k, HistoryTriggerOptions as l, HistoryTriggerRepoOverride as m };
315
+ export { DEFAULT_HISTORY_SHADOW_KEY as D };
316
+ export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryCustomData as g, HistoryCustomInput as h, HistoryConfigForModel as i, HistoryFieldChange as j, HistoryValueType as k, HistoryConfigBase as l, HistoryFallbackActor as m, HistoryFirestoreTriggersDep as n, HistoryShadowConfig as o, HistoryShadowFieldsConfig as p, HistoryTriggerOptions as q, HistoryTriggerRepoOverride as r };
@@ -3,7 +3,7 @@ import { onDocumentWritten, DocumentOptions } from 'firebase-functions/v2/firest
3
3
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
4
4
  import { onMessagePublished, PubSubOptions } from 'firebase-functions/v2/pubsub';
5
5
  import { z } from 'zod';
6
- import { F as FieldPath } from './types-BFu2DpKn.cjs';
6
+ import { F as FieldPath } from './types-Dc3lX99O.cjs';
7
7
 
8
8
  /**
9
9
  * Cloud Functions v2 options forwarded to `onDocumentWritten()` for every
@@ -1,4 +1,4 @@
1
- import { g as HistoryConfigForModel } from './types--RamYGF1.cjs';
1
+ import { i as HistoryConfigForModel } from './types-D6zvWzRt.cjs';
2
2
  import * as zod from 'zod';
3
3
  import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
4
 
@@ -1,4 +1,4 @@
1
- import { g as HistoryConfigForModel } from './types--RamYGF1.js';
1
+ import { i as HistoryConfigForModel } from './types-D6zvWzRt.js';
2
2
  import * as zod from 'zod';
3
3
  import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
4
 
@@ -1,6 +1,7 @@
1
1
  import { z, ZodError } from 'zod';
2
2
  import { Env, Context, MiddlewareHandler } from 'hono';
3
3
  import { F as FirebaseAdminAuthLike, D as DecodedIdTokenLike } from './firebase-auth-nG3prKoj.js';
4
+ import { A as ActorResolverOption } from './actor-context-DQZgWqj3.js';
4
5
 
5
6
  /**
6
7
  * Global DI services container for the Hono server.
@@ -855,6 +856,13 @@ interface HonoServerOptions<TEnv extends Env = Env> {
855
856
  * project — declare it once and pass it to {@link createApiRegistry}.
856
857
  */
857
858
  services?: AnyServicesContainer;
859
+ /**
860
+ * Optional resolver (function or declarative field config) used to extract
861
+ * the authenticated actor from the Hono `Context` for automatic history
862
+ * shadow metadata injection. Defaults to {@link defaultActorResolver}
863
+ * (`c.get("user") ?? c.get("docsUser")`).
864
+ */
865
+ actorResolver?: ActorResolverOption;
858
866
  }
859
867
 
860
868
  export { basicAuth as N, createRequestContextMiddleware as Q, createServices as T, defineRoutes as U, ValidationError as V, firebaseBearerAuth as W, firebaseDocsAuth as X, isDocsAuthExtension as Y, withRequestContext as Z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdjs/firestore-repo-service",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "workspaces": [
5
5
  "test/functions"
6
6
  ],