@beignet/core 0.0.1 → 0.0.3
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/CHANGELOG.md +27 -0
- package/README.md +202 -8
- package/dist/application/index.d.ts +93 -9
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +11 -11
- package/dist/application/index.js.map +1 -1
- package/dist/client/client.d.ts +73 -12
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +37 -12
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +69 -8
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +84 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +36 -0
- package/dist/config/index.js.map +1 -1
- package/dist/contracts/contract-builder.d.ts +49 -22
- package/dist/contracts/contract-builder.d.ts.map +1 -1
- package/dist/contracts/contract-builder.js +48 -21
- package/dist/contracts/contract-builder.js.map +1 -1
- package/dist/contracts/contract-group.d.ts +35 -19
- package/dist/contracts/contract-group.d.ts.map +1 -1
- package/dist/contracts/contract-group.js +35 -19
- package/dist/contracts/contract-group.js.map +1 -1
- package/dist/contracts/contract-like.d.ts +4 -4
- package/dist/contracts/contract-like.d.ts.map +1 -1
- package/dist/contracts/contract-like.js +2 -1
- package/dist/contracts/contract-like.js.map +1 -1
- package/dist/contracts/index.d.ts +28 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +12 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/openapi-meta.d.ts +8 -8
- package/dist/contracts/openapi-meta.d.ts.map +1 -1
- package/dist/contracts/path-template.d.ts +27 -0
- package/dist/contracts/path-template.d.ts.map +1 -1
- package/dist/contracts/path-template.js +6 -0
- package/dist/contracts/path-template.js.map +1 -1
- package/dist/contracts/types.d.ts +104 -10
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/types.js +15 -0
- package/dist/contracts/types.js.map +1 -1
- package/dist/contracts/utils.d.ts +6 -0
- package/dist/contracts/utils.d.ts.map +1 -1
- package/dist/contracts/utils.js +6 -0
- package/dist/contracts/utils.js.map +1 -1
- package/dist/domain/entity.d.ts +22 -11
- package/dist/domain/entity.d.ts.map +1 -1
- package/dist/domain/entity.js +5 -1
- package/dist/domain/entity.js.map +1 -1
- package/dist/domain/events.d.ts +5 -2
- package/dist/domain/events.d.ts.map +1 -1
- package/dist/domain/events.js +4 -1
- package/dist/domain/events.js.map +1 -1
- package/dist/domain/value-object.d.ts +19 -9
- package/dist/domain/value-object.d.ts.map +1 -1
- package/dist/domain/value-object.js +5 -1
- package/dist/domain/value-object.js.map +1 -1
- package/dist/errors/catalog.d.ts +40 -16
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +18 -7
- package/dist/errors/catalog.js.map +1 -1
- package/dist/errors/response.d.ts +16 -4
- package/dist/errors/response.d.ts.map +1 -1
- package/dist/errors/response.js +3 -3
- package/dist/errors/response.js.map +1 -1
- package/dist/errors/validation.d.ts +10 -1
- package/dist/errors/validation.d.ts.map +1 -1
- package/dist/errors/validation.js +3 -0
- package/dist/errors/validation.js.map +1 -1
- package/dist/events/index.d.ts +133 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +30 -0
- package/dist/events/index.js.map +1 -1
- package/dist/idempotency/index.d.ts +355 -0
- package/dist/idempotency/index.d.ts.map +1 -0
- package/dist/idempotency/index.js +360 -0
- package/dist/idempotency/index.js.map +1 -0
- package/dist/jobs/index.d.ts +248 -4
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +183 -1
- package/dist/jobs/index.js.map +1 -1
- package/dist/mail/index.d.ts +149 -0
- package/dist/mail/index.d.ts.map +1 -1
- package/dist/mail/index.js +30 -0
- package/dist/mail/index.js.map +1 -1
- package/dist/notifications/index.d.ts +369 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +310 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/openapi/index.d.ts +132 -16
- package/dist/openapi/index.d.ts.map +1 -1
- package/dist/openapi/index.js +1 -1
- package/dist/openapi/index.js.map +1 -1
- package/dist/outbox/index.d.ts +474 -0
- package/dist/outbox/index.d.ts.map +1 -0
- package/dist/outbox/index.js +538 -0
- package/dist/outbox/index.js.map +1 -0
- package/dist/pagination/index.d.ts +166 -0
- package/dist/pagination/index.d.ts.map +1 -0
- package/dist/pagination/index.js +96 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/ports/audit.d.ts +271 -0
- package/dist/ports/audit.d.ts.map +1 -1
- package/dist/ports/audit.js +128 -0
- package/dist/ports/audit.js.map +1 -1
- package/dist/ports/auth.d.ts +70 -0
- package/dist/ports/auth.d.ts.map +1 -1
- package/dist/ports/auth.js +30 -0
- package/dist/ports/auth.js.map +1 -1
- package/dist/ports/cache.d.ts +41 -0
- package/dist/ports/cache.d.ts.map +1 -1
- package/dist/ports/cache.js +10 -0
- package/dist/ports/cache.js.map +1 -1
- package/dist/ports/clock.d.ts +38 -0
- package/dist/ports/clock.d.ts.map +1 -1
- package/dist/ports/clock.js +20 -0
- package/dist/ports/clock.js.map +1 -1
- package/dist/ports/id-generator.d.ts +37 -0
- package/dist/ports/id-generator.d.ts.map +1 -1
- package/dist/ports/id-generator.js +22 -0
- package/dist/ports/id-generator.js.map +1 -1
- package/dist/ports/index.d.ts +83 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +41 -5
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/logger.d.ts +56 -0
- package/dist/ports/logger.d.ts.map +1 -1
- package/dist/ports/logger.js +17 -0
- package/dist/ports/logger.js.map +1 -1
- package/dist/ports/policy.d.ts +132 -0
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +45 -0
- package/dist/ports/policy.js.map +1 -1
- package/dist/ports/rate-limit.d.ts +25 -0
- package/dist/ports/rate-limit.d.ts.map +1 -1
- package/dist/ports/rate-limit.js +10 -0
- package/dist/ports/rate-limit.js.map +1 -1
- package/dist/ports/redaction.d.ts +101 -0
- package/dist/ports/redaction.d.ts.map +1 -1
- package/dist/ports/redaction.js +59 -0
- package/dist/ports/redaction.js.map +1 -1
- package/dist/ports/storage.d.ts +100 -0
- package/dist/ports/storage.d.ts.map +1 -1
- package/dist/ports/storage.js +10 -0
- package/dist/ports/storage.js.map +1 -1
- package/dist/ports/testing.d.ts +47 -0
- package/dist/ports/testing.d.ts.map +1 -1
- package/dist/ports/testing.js +23 -0
- package/dist/ports/testing.js.map +1 -1
- package/dist/ports/unit-of-work.d.ts +60 -3
- package/dist/ports/unit-of-work.d.ts.map +1 -1
- package/dist/ports/unit-of-work.js +11 -2
- package/dist/ports/unit-of-work.js.map +1 -1
- package/dist/providers/instrumentation.d.ts +205 -1
- package/dist/providers/instrumentation.d.ts.map +1 -1
- package/dist/providers/instrumentation.js +14 -0
- package/dist/providers/instrumentation.js.map +1 -1
- package/dist/providers/provider.d.ts +14 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js.map +1 -1
- package/dist/schedules/index.d.ts +246 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +27 -0
- package/dist/schedules/index.js.map +1 -1
- package/dist/server/health.d.ts +14 -5
- package/dist/server/health.d.ts.map +1 -1
- package/dist/server/health.js +5 -2
- package/dist/server/health.js.map +1 -1
- package/dist/server/hooks/auth.d.ts +68 -26
- package/dist/server/hooks/auth.d.ts.map +1 -1
- package/dist/server/hooks/auth.js +44 -55
- package/dist/server/hooks/auth.js.map +1 -1
- package/dist/server/hooks/cors.d.ts +27 -0
- package/dist/server/hooks/cors.d.ts.map +1 -1
- package/dist/server/hooks/cors.js +12 -0
- package/dist/server/hooks/cors.js.map +1 -1
- package/dist/server/hooks/errors.d.ts +15 -6
- package/dist/server/hooks/errors.d.ts.map +1 -1
- package/dist/server/hooks/errors.js.map +1 -1
- package/dist/server/hooks/index.d.ts +4 -1
- package/dist/server/hooks/index.d.ts.map +1 -1
- package/dist/server/hooks/index.js +3 -0
- package/dist/server/hooks/index.js.map +1 -1
- package/dist/server/hooks/logging.d.ts +36 -0
- package/dist/server/hooks/logging.d.ts.map +1 -1
- package/dist/server/hooks/logging.js +6 -0
- package/dist/server/hooks/logging.js.map +1 -1
- package/dist/server/hooks/rate-limit.d.ts +33 -0
- package/dist/server/hooks/rate-limit.d.ts.map +1 -1
- package/dist/server/hooks/rate-limit.js +11 -0
- package/dist/server/hooks/rate-limit.js.map +1 -1
- package/dist/server/http.d.ts +222 -0
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +20 -1
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +19 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/openapi.d.ts +5 -3
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/openapi.js +4 -2
- package/dist/server/openapi.js.map +1 -1
- package/dist/server/providers/loadProviderConfig.d.ts +9 -0
- package/dist/server/providers/loadProviderConfig.d.ts.map +1 -1
- package/dist/server/providers/loadProviderConfig.js +9 -0
- package/dist/server/providers/loadProviderConfig.js.map +1 -1
- package/dist/server/server.d.ts +159 -19
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +72 -31
- package/dist/server/server.js.map +1 -1
- package/dist/testing/index.d.ts +171 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +127 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/uploads/client.d.ts +278 -0
- package/dist/uploads/client.d.ts.map +1 -0
- package/dist/uploads/client.js +428 -0
- package/dist/uploads/client.js.map +1 -0
- package/dist/uploads/index.d.ts +361 -0
- package/dist/uploads/index.d.ts.map +1 -0
- package/dist/uploads/index.js +543 -0
- package/dist/uploads/index.js.map +1 -0
- package/package.json +31 -2
- package/src/application/index.ts +85 -22
- package/src/client/client.ts +73 -12
- package/src/client/index.ts +12 -0
- package/src/client/types.ts +70 -9
- package/src/config/index.ts +86 -0
- package/src/contracts/contract-builder.ts +49 -22
- package/src/contracts/contract-group.ts +35 -19
- package/src/contracts/contract-like.ts +4 -4
- package/src/contracts/index.ts +28 -1
- package/src/contracts/openapi-meta.ts +8 -8
- package/src/contracts/path-template.ts +27 -0
- package/src/contracts/types.ts +111 -10
- package/src/contracts/utils.ts +6 -0
- package/src/domain/entity.ts +22 -11
- package/src/domain/events.ts +5 -2
- package/src/domain/value-object.ts +19 -9
- package/src/errors/catalog.ts +40 -16
- package/src/errors/response.ts +16 -4
- package/src/errors/validation.ts +10 -1
- package/src/events/index.ts +134 -0
- package/src/idempotency/index.ts +767 -0
- package/src/jobs/index.ts +437 -5
- package/src/mail/index.ts +149 -0
- package/src/notifications/index.ts +771 -0
- package/src/openapi/index.ts +133 -16
- package/src/outbox/index.ts +1104 -0
- package/src/pagination/index.ts +278 -0
- package/src/ports/audit.ts +271 -0
- package/src/ports/auth.ts +70 -0
- package/src/ports/cache.ts +41 -0
- package/src/ports/clock.ts +38 -0
- package/src/ports/id-generator.ts +37 -0
- package/src/ports/index.ts +106 -11
- package/src/ports/logger.ts +56 -0
- package/src/ports/policy.ts +133 -0
- package/src/ports/rate-limit.ts +25 -0
- package/src/ports/redaction.ts +101 -0
- package/src/ports/storage.ts +100 -0
- package/src/ports/testing.ts +47 -0
- package/src/ports/unit-of-work.ts +60 -3
- package/src/providers/instrumentation.ts +211 -1
- package/src/providers/provider.ts +14 -1
- package/src/schedules/index.ts +247 -0
- package/src/server/health.ts +14 -5
- package/src/server/hooks/auth.ts +105 -120
- package/src/server/hooks/cors.ts +27 -0
- package/src/server/hooks/errors.ts +15 -6
- package/src/server/hooks/index.ts +4 -5
- package/src/server/hooks/logging.ts +36 -0
- package/src/server/hooks/rate-limit.ts +33 -0
- package/src/server/http.ts +249 -1
- package/src/server/index.ts +19 -1
- package/src/server/openapi.ts +5 -3
- package/src/server/providers/loadProviderConfig.ts +9 -0
- package/src/server/server.ts +296 -30
- package/src/testing/index.ts +348 -0
- package/src/uploads/client.ts +861 -0
- package/src/uploads/index.ts +1067 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sort direction for list queries.
|
|
3
|
+
*/
|
|
4
|
+
export type SortDirection = "asc" | "desc";
|
|
5
|
+
/**
|
|
6
|
+
* Sort option for a whitelisted field.
|
|
7
|
+
*/
|
|
8
|
+
export type SortOption<Field extends string = string> = {
|
|
9
|
+
/**
|
|
10
|
+
* Field to sort by.
|
|
11
|
+
*/
|
|
12
|
+
field: Field;
|
|
13
|
+
/**
|
|
14
|
+
* Sort direction.
|
|
15
|
+
*/
|
|
16
|
+
direction: SortDirection;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Normalized offset pagination request.
|
|
20
|
+
*/
|
|
21
|
+
export interface OffsetPage {
|
|
22
|
+
/**
|
|
23
|
+
* Pagination mode.
|
|
24
|
+
*/
|
|
25
|
+
readonly kind: "offset";
|
|
26
|
+
/**
|
|
27
|
+
* Page size after defaulting and max-limit clamping.
|
|
28
|
+
*/
|
|
29
|
+
readonly limit: number;
|
|
30
|
+
/**
|
|
31
|
+
* Zero-based item offset.
|
|
32
|
+
*/
|
|
33
|
+
readonly offset: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Normalized cursor pagination request.
|
|
37
|
+
*/
|
|
38
|
+
export interface CursorPage {
|
|
39
|
+
/**
|
|
40
|
+
* Pagination mode.
|
|
41
|
+
*/
|
|
42
|
+
readonly kind: "cursor";
|
|
43
|
+
/**
|
|
44
|
+
* Page size after defaulting and max-limit clamping.
|
|
45
|
+
*/
|
|
46
|
+
readonly limit: number;
|
|
47
|
+
/**
|
|
48
|
+
* Cursor for the current page, or null for the first page.
|
|
49
|
+
*/
|
|
50
|
+
readonly cursor: string | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Normalized pagination request.
|
|
54
|
+
*/
|
|
55
|
+
export type Page = OffsetPage | CursorPage;
|
|
56
|
+
/**
|
|
57
|
+
* Offset pagination response metadata.
|
|
58
|
+
*/
|
|
59
|
+
export type OffsetPageInfo = OffsetPage & {
|
|
60
|
+
/**
|
|
61
|
+
* Total item count.
|
|
62
|
+
*/
|
|
63
|
+
readonly total: number;
|
|
64
|
+
/**
|
|
65
|
+
* Whether another page exists.
|
|
66
|
+
*/
|
|
67
|
+
readonly hasMore: boolean;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Cursor pagination response metadata.
|
|
71
|
+
*/
|
|
72
|
+
export type CursorPageInfo = CursorPage & {
|
|
73
|
+
/**
|
|
74
|
+
* Cursor for the next page, or null when there is no next page.
|
|
75
|
+
*/
|
|
76
|
+
readonly nextCursor: string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Whether another page exists.
|
|
79
|
+
*/
|
|
80
|
+
readonly hasMore: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Pagination response metadata.
|
|
84
|
+
*/
|
|
85
|
+
export type PageInfo = OffsetPageInfo | CursorPageInfo;
|
|
86
|
+
/**
|
|
87
|
+
* Paginated list result.
|
|
88
|
+
*/
|
|
89
|
+
export interface PageResult<TItem, TPage extends PageInfo = PageInfo> {
|
|
90
|
+
/**
|
|
91
|
+
* Page items. Result helpers clone the input array.
|
|
92
|
+
*/
|
|
93
|
+
readonly items: TItem[];
|
|
94
|
+
/**
|
|
95
|
+
* Page metadata.
|
|
96
|
+
*/
|
|
97
|
+
readonly page: TPage;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Options for normalizing pagination input.
|
|
101
|
+
*/
|
|
102
|
+
export interface NormalizePageOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Limit used when the caller does not provide one.
|
|
105
|
+
*/
|
|
106
|
+
readonly defaultLimit: number;
|
|
107
|
+
/**
|
|
108
|
+
* Maximum allowed limit. Larger caller values are clamped.
|
|
109
|
+
*/
|
|
110
|
+
readonly maxLimit: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Raw offset pagination input.
|
|
114
|
+
*/
|
|
115
|
+
export interface OffsetPageInput {
|
|
116
|
+
/**
|
|
117
|
+
* Requested page size.
|
|
118
|
+
*/
|
|
119
|
+
readonly limit?: number | null;
|
|
120
|
+
/**
|
|
121
|
+
* Requested zero-based offset.
|
|
122
|
+
*/
|
|
123
|
+
readonly offset?: number | null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Raw cursor pagination input.
|
|
127
|
+
*/
|
|
128
|
+
export interface CursorPageInput {
|
|
129
|
+
/**
|
|
130
|
+
* Requested page size.
|
|
131
|
+
*/
|
|
132
|
+
readonly limit?: number | null;
|
|
133
|
+
/**
|
|
134
|
+
* Requested cursor.
|
|
135
|
+
*/
|
|
136
|
+
readonly cursor?: string | null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Error thrown when pagination input is invalid.
|
|
140
|
+
*/
|
|
141
|
+
export declare class PaginationError extends Error {
|
|
142
|
+
constructor(message: string);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Normalize offset pagination input.
|
|
146
|
+
*
|
|
147
|
+
* The limit is defaulted and clamped to `maxLimit`; offset must be a
|
|
148
|
+
* non-negative integer.
|
|
149
|
+
*/
|
|
150
|
+
export declare function normalizeOffsetPage(input: OffsetPageInput, options: NormalizePageOptions): OffsetPage;
|
|
151
|
+
/**
|
|
152
|
+
* Normalize cursor pagination input.
|
|
153
|
+
*
|
|
154
|
+
* The limit is defaulted and clamped to `maxLimit`; cursor must be a string or
|
|
155
|
+
* null.
|
|
156
|
+
*/
|
|
157
|
+
export declare function normalizeCursorPage(input: CursorPageInput, options: NormalizePageOptions): CursorPage;
|
|
158
|
+
/**
|
|
159
|
+
* Create an offset page result and derive `hasMore`.
|
|
160
|
+
*/
|
|
161
|
+
export declare function offsetPageResult<TItem>(items: readonly TItem[], page: OffsetPage, total: number): PageResult<TItem, OffsetPageInfo>;
|
|
162
|
+
/**
|
|
163
|
+
* Create a cursor page result and derive `hasMore` from `nextCursor`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function cursorPageResult<TItem>(items: readonly TItem[], page: CursorPage, nextCursor: string | null): PageResult<TItem, CursorPageInfo>;
|
|
166
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pagination/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;IACtD;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;OAEG;IACH,SAAS,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IACxC;;OAEG;IACH,QAAQ,CAAC,KAAK,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e,EACtB,OAAO,EAAE,oBAAoB,GAC5B,UAAU,CAaZ;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,oBAAoB,GAC5B,UAAU,CAaZ;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,GACZ,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,CAanC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,CAanC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when pagination input is invalid.
|
|
3
|
+
*/
|
|
4
|
+
export class PaginationError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "PaginationError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function assertPositiveInteger(name, value) {
|
|
11
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
12
|
+
throw new PaginationError(`${name} must be a positive integer.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function normalizeLimit(input, options) {
|
|
16
|
+
assertPositiveInteger("defaultLimit", options.defaultLimit);
|
|
17
|
+
assertPositiveInteger("maxLimit", options.maxLimit);
|
|
18
|
+
if (options.defaultLimit > options.maxLimit) {
|
|
19
|
+
throw new PaginationError("defaultLimit must be less than or equal to maxLimit.");
|
|
20
|
+
}
|
|
21
|
+
if (input == null)
|
|
22
|
+
return options.defaultLimit;
|
|
23
|
+
if (!Number.isInteger(input) || input < 1) {
|
|
24
|
+
throw new PaginationError("limit must be a positive integer.");
|
|
25
|
+
}
|
|
26
|
+
return Math.min(input, options.maxLimit);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalize offset pagination input.
|
|
30
|
+
*
|
|
31
|
+
* The limit is defaulted and clamped to `maxLimit`; offset must be a
|
|
32
|
+
* non-negative integer.
|
|
33
|
+
*/
|
|
34
|
+
export function normalizeOffsetPage(input, options) {
|
|
35
|
+
const limit = normalizeLimit(input.limit, options);
|
|
36
|
+
const offset = input.offset ?? 0;
|
|
37
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
38
|
+
throw new PaginationError("offset must be a non-negative integer.");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
kind: "offset",
|
|
42
|
+
limit,
|
|
43
|
+
offset,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Normalize cursor pagination input.
|
|
48
|
+
*
|
|
49
|
+
* The limit is defaulted and clamped to `maxLimit`; cursor must be a string or
|
|
50
|
+
* null.
|
|
51
|
+
*/
|
|
52
|
+
export function normalizeCursorPage(input, options) {
|
|
53
|
+
const limit = normalizeLimit(input.limit, options);
|
|
54
|
+
const cursor = input.cursor ?? null;
|
|
55
|
+
if (cursor !== null && typeof cursor !== "string") {
|
|
56
|
+
throw new PaginationError("cursor must be a string or null.");
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
kind: "cursor",
|
|
60
|
+
limit,
|
|
61
|
+
cursor,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create an offset page result and derive `hasMore`.
|
|
66
|
+
*/
|
|
67
|
+
export function offsetPageResult(items, page, total) {
|
|
68
|
+
if (!Number.isInteger(total) || total < 0) {
|
|
69
|
+
throw new PaginationError("total must be a non-negative integer.");
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
items: [...items],
|
|
73
|
+
page: {
|
|
74
|
+
...page,
|
|
75
|
+
total,
|
|
76
|
+
hasMore: page.offset + items.length < total,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a cursor page result and derive `hasMore` from `nextCursor`.
|
|
82
|
+
*/
|
|
83
|
+
export function cursorPageResult(items, page, nextCursor) {
|
|
84
|
+
if (nextCursor !== null && typeof nextCursor !== "string") {
|
|
85
|
+
throw new PaginationError("nextCursor must be a string or null.");
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
items: [...items],
|
|
89
|
+
page: {
|
|
90
|
+
...page,
|
|
91
|
+
nextCursor,
|
|
92
|
+
hasMore: nextCursor !== null,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pagination/index.ts"],"names":[],"mappings":"AAqJA;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAE,KAAa;IACxD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,8BAA8B,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CACrB,KAAgC,EAChC,OAA6B;IAE7B,qBAAqB,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpD,IAAI,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,eAAe,CACvB,sDAAsD,CACvD,CAAC;IACJ,C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,EACvB,IAAgB,EAChB,KAAa;IAEb,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,eAAe,CAAC,uCAAuC,CAAC,CAAC;IACrE,CAAC;IAED,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;QACjB,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,KAAK;YACL,OAAO,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,KAAK;SAC5C;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAuB,EACvB,IAAgB,EAChB,UAAyB;IAEzB,IAAI,UAAU,KAAK,IAAI,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC1D,MAAM,IAAI,eAAe,CAAC,sCAAsC,CAAC,CAAC;IACpE,CAAC;IAED,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;QACjB,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,UAAU;YACV,OAAO,EAAE,UAAU,KAAK,IAAI;SAC7B;KACF,CAAC;AACJ,CAAC"}
|
package/dist/ports/audit.d.ts
CHANGED
|
@@ -1,58 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The normalized category of actor that caused application activity.
|
|
3
|
+
*
|
|
4
|
+
* Actors describe who or what performed work for request context,
|
|
5
|
+
* authorization, audit logs, and diagnostics. They do not authenticate the
|
|
6
|
+
* request by themselves.
|
|
7
|
+
*/
|
|
1
8
|
export type ActivityActorType = "anonymous" | "service" | "system" | "user";
|
|
9
|
+
/**
|
|
10
|
+
* Whether an audited activity completed successfully or intentionally records
|
|
11
|
+
* a failed attempt.
|
|
12
|
+
*/
|
|
2
13
|
export type AuditOutcome = "success" | "failure";
|
|
14
|
+
/**
|
|
15
|
+
* JSON-like metadata values accepted by activity and audit descriptors.
|
|
16
|
+
*
|
|
17
|
+
* Metadata should stay intentionally small. Prefer stable IDs and short labels
|
|
18
|
+
* over full request bodies, secrets, PHI, or PII.
|
|
19
|
+
*/
|
|
3
20
|
export type ActivityMetadataValue = ActivityMetadataValue[] | boolean | null | number | string | {
|
|
4
21
|
[key: string]: ActivityMetadataValue | undefined;
|
|
5
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Additional structured metadata attached to actors, tenants, resources, or
|
|
25
|
+
* audit entries.
|
|
26
|
+
*/
|
|
6
27
|
export type ActivityMetadata = Record<string, ActivityMetadataValue | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* A normalized descriptor for the person, service, or system process that
|
|
30
|
+
* caused application activity.
|
|
31
|
+
*
|
|
32
|
+
* Store this on application context as `ctx.actor` so routes, use cases, jobs,
|
|
33
|
+
* policies, audit logs, and devtools share one identity shape.
|
|
34
|
+
*/
|
|
7
35
|
export interface ActivityActor {
|
|
36
|
+
/**
|
|
37
|
+
* The actor category.
|
|
38
|
+
*/
|
|
8
39
|
type: ActivityActorType;
|
|
40
|
+
/**
|
|
41
|
+
* Stable application ID for this actor, when known.
|
|
42
|
+
*/
|
|
9
43
|
id?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Human-readable label for diagnostics and audit views.
|
|
46
|
+
*/
|
|
10
47
|
displayName?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Small, redaction-safe metadata about the actor.
|
|
50
|
+
*/
|
|
11
51
|
metadata?: ActivityMetadata;
|
|
12
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A normalized tenant/account/workspace scope for activity.
|
|
55
|
+
*
|
|
56
|
+
* This is a context value used by audit logs, authorization, and diagnostics.
|
|
57
|
+
* It does not create, load, or persist a tenant record.
|
|
58
|
+
*/
|
|
13
59
|
export interface ActivityTenant {
|
|
60
|
+
/**
|
|
61
|
+
* Stable tenant/account/workspace ID.
|
|
62
|
+
*/
|
|
14
63
|
id: string;
|
|
64
|
+
/**
|
|
65
|
+
* Optional human-readable tenant slug.
|
|
66
|
+
*/
|
|
15
67
|
slug?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Small, redaction-safe metadata about the tenant.
|
|
70
|
+
*/
|
|
16
71
|
metadata?: ActivityMetadata;
|
|
17
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* A normalized descriptor for the business object affected by an audit entry.
|
|
75
|
+
*/
|
|
18
76
|
export interface ActivityResource {
|
|
77
|
+
/**
|
|
78
|
+
* Resource type, usually a singular domain noun such as "post", "invoice",
|
|
79
|
+
* or "appointment".
|
|
80
|
+
*/
|
|
19
81
|
type: string;
|
|
82
|
+
/**
|
|
83
|
+
* Stable resource ID, when known.
|
|
84
|
+
*/
|
|
20
85
|
id?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Human-readable resource label for audit views.
|
|
88
|
+
*/
|
|
21
89
|
name?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Small, redaction-safe metadata about the resource.
|
|
92
|
+
*/
|
|
22
93
|
metadata?: ActivityMetadata;
|
|
23
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* A normalized audit/activity log entry.
|
|
97
|
+
*
|
|
98
|
+
* Application code usually creates these through an app-owned helper such as
|
|
99
|
+
* `auditEntry(ctx, { action, resource })` so actor, tenant, request ID, and
|
|
100
|
+
* trace ID are copied from context consistently. Durability depends on the
|
|
101
|
+
* `AuditLogPort` implementation.
|
|
102
|
+
*/
|
|
24
103
|
export interface AuditLogEntry {
|
|
104
|
+
/**
|
|
105
|
+
* Stable action name, usually namespaced by feature and workflow.
|
|
106
|
+
*
|
|
107
|
+
* @example "posts.publish"
|
|
108
|
+
*/
|
|
25
109
|
action: string;
|
|
110
|
+
/**
|
|
111
|
+
* Actor that caused the activity.
|
|
112
|
+
*/
|
|
26
113
|
actor: ActivityActor;
|
|
114
|
+
/**
|
|
115
|
+
* Timestamp assigned when the activity occurred.
|
|
116
|
+
*/
|
|
27
117
|
occurredAt: Date;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the activity succeeded or records a failed attempt.
|
|
120
|
+
*/
|
|
28
121
|
outcome: AuditOutcome;
|
|
122
|
+
/**
|
|
123
|
+
* Small, redaction-safe metadata about the activity.
|
|
124
|
+
*/
|
|
29
125
|
metadata?: ActivityMetadata;
|
|
126
|
+
/**
|
|
127
|
+
* Optional human-readable audit message.
|
|
128
|
+
*/
|
|
30
129
|
message?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Request correlation ID, when the activity originated from a request or
|
|
132
|
+
* background context.
|
|
133
|
+
*/
|
|
31
134
|
requestId?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Business resource affected by the activity.
|
|
137
|
+
*/
|
|
32
138
|
resource?: ActivityResource;
|
|
139
|
+
/**
|
|
140
|
+
* Tenant/account/workspace scope for the activity.
|
|
141
|
+
*/
|
|
33
142
|
tenant?: ActivityTenant;
|
|
143
|
+
/**
|
|
144
|
+
* Trace correlation ID, when tracing is enabled.
|
|
145
|
+
*/
|
|
34
146
|
traceId?: string;
|
|
35
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Input accepted by `AuditLogPort.record(...)`.
|
|
150
|
+
*
|
|
151
|
+
* `occurredAt` and `outcome` are optional at call sites. Adapters that store
|
|
152
|
+
* audit entries should call `normalizeAuditLogEntry(...)` before persistence or
|
|
153
|
+
* otherwise apply equivalent defaults.
|
|
154
|
+
*/
|
|
36
155
|
export type AuditLogEntryInput = Omit<AuditLogEntry, "occurredAt" | "outcome"> & {
|
|
37
156
|
occurredAt?: Date;
|
|
38
157
|
outcome?: AuditOutcome;
|
|
39
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* App-facing port for audit/activity logging.
|
|
161
|
+
*
|
|
162
|
+
* Production implementations should usually write to a durable database table,
|
|
163
|
+
* append-only log, or external audit service. Tests can use an in-memory
|
|
164
|
+
* adapter. Application code should depend on this interface, not on a concrete
|
|
165
|
+
* audit provider.
|
|
166
|
+
*/
|
|
40
167
|
export interface AuditLogPort {
|
|
168
|
+
/**
|
|
169
|
+
* Persist or capture an audit entry.
|
|
170
|
+
*/
|
|
41
171
|
record(entry: AuditLogEntryInput): Promise<void> | void;
|
|
42
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* In-memory audit log port used by tests and local examples.
|
|
175
|
+
*/
|
|
43
176
|
export interface MemoryAuditLogPort extends AuditLogPort {
|
|
177
|
+
/**
|
|
178
|
+
* Captured, normalized, redacted audit entries.
|
|
179
|
+
*/
|
|
44
180
|
entries: AuditLogEntry[];
|
|
45
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Options shared by audit log wrappers and in-memory audit adapters.
|
|
184
|
+
*/
|
|
46
185
|
export interface AuditLogOptions {
|
|
186
|
+
/**
|
|
187
|
+
* Optional final redaction/customization step applied after Beignet's default
|
|
188
|
+
* metadata redaction.
|
|
189
|
+
*/
|
|
47
190
|
redact?: (entry: AuditLogEntry) => AuditLogEntry;
|
|
48
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Create an anonymous actor descriptor for unauthenticated activity.
|
|
194
|
+
*
|
|
195
|
+
* This helper only creates a normalized context value. It does not perform
|
|
196
|
+
* authentication.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const actor = createAnonymousActor();
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @param options - Optional display name or metadata to include.
|
|
204
|
+
* @returns An activity actor with `type: "anonymous"`.
|
|
205
|
+
*/
|
|
49
206
|
export declare function createAnonymousActor(options?: Omit<ActivityActor, "type">): ActivityActor;
|
|
207
|
+
/**
|
|
208
|
+
* Create a service actor descriptor for work initiated by another service or
|
|
209
|
+
* integration.
|
|
210
|
+
*
|
|
211
|
+
* This is useful for webhooks, internal service calls, or integration-driven
|
|
212
|
+
* background jobs.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const actor = createServiceActor("stripe-webhook");
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @param id - Stable service or integration ID.
|
|
220
|
+
* @param options - Optional display name or metadata to include.
|
|
221
|
+
* @returns An activity actor with `type: "service"`.
|
|
222
|
+
*/
|
|
50
223
|
export declare function createServiceActor(id: string, options?: Omit<ActivityActor, "type" | "id">): ActivityActor;
|
|
224
|
+
/**
|
|
225
|
+
* Create a system actor descriptor for framework or app-owned background work.
|
|
226
|
+
*
|
|
227
|
+
* Use this for scheduled tasks, scripts, maintenance jobs, and other work that
|
|
228
|
+
* is not directly caused by a user or external service.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* const actor = createSystemActor("nightly-maintenance");
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @param id - Stable system actor ID. Defaults to `"system"`.
|
|
236
|
+
* @param options - Optional display name or metadata to include.
|
|
237
|
+
* @returns An activity actor with `type: "system"`.
|
|
238
|
+
*/
|
|
51
239
|
export declare function createSystemActor(id?: string, options?: Omit<ActivityActor, "type" | "id">): ActivityActor;
|
|
240
|
+
/**
|
|
241
|
+
* Create a user actor descriptor for authenticated user activity.
|
|
242
|
+
*
|
|
243
|
+
* This helper only normalizes a known user ID for context, authorization,
|
|
244
|
+
* audit, and diagnostics. It does not verify a session or load a user record.
|
|
245
|
+
* Resolve authentication first, then call this helper with the authenticated
|
|
246
|
+
* user ID.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* const actor = createUserActor(session.user.id, {
|
|
251
|
+
* displayName: session.user.name,
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @param id - Stable application user ID.
|
|
256
|
+
* @param options - Optional display name or metadata to include.
|
|
257
|
+
* @returns An activity actor with `type: "user"`.
|
|
258
|
+
*/
|
|
52
259
|
export declare function createUserActor(id: string, options?: Omit<ActivityActor, "type" | "id">): ActivityActor;
|
|
260
|
+
/**
|
|
261
|
+
* Create a tenant/account/workspace descriptor for request or background
|
|
262
|
+
* context.
|
|
263
|
+
*
|
|
264
|
+
* This helper only creates a normalized context value used by audit,
|
|
265
|
+
* authorization, logs, and diagnostics. It does not create, load, or persist a
|
|
266
|
+
* tenant record.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* const tenant = createTenant(session.organizationId, {
|
|
271
|
+
* slug: session.organizationSlug,
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @param id - Stable tenant/account/workspace ID.
|
|
276
|
+
* @param options - Optional slug or metadata to include.
|
|
277
|
+
* @returns A normalized activity tenant descriptor.
|
|
278
|
+
*/
|
|
53
279
|
export declare function createTenant(id: string, options?: Omit<ActivityTenant, "id">): ActivityTenant;
|
|
280
|
+
/**
|
|
281
|
+
* Fill default audit fields for an input entry.
|
|
282
|
+
*
|
|
283
|
+
* @param entry - Partial audit entry accepted by `AuditLogPort.record(...)`.
|
|
284
|
+
* @returns A complete audit entry with `occurredAt` and `outcome` populated.
|
|
285
|
+
*/
|
|
54
286
|
export declare function normalizeAuditLogEntry(entry: AuditLogEntryInput): AuditLogEntry;
|
|
287
|
+
/**
|
|
288
|
+
* Redact metadata on an already-normalized audit entry.
|
|
289
|
+
*
|
|
290
|
+
* This redacts metadata values on the entry, actor, tenant, and resource using
|
|
291
|
+
* the default redaction rules from `redactValue(...)`.
|
|
292
|
+
*
|
|
293
|
+
* @param entry - Audit entry to redact.
|
|
294
|
+
* @returns A shallow copy with redacted metadata fields.
|
|
295
|
+
*/
|
|
55
296
|
export declare function redactAuditLogEntry(entry: AuditLogEntry): AuditLogEntry;
|
|
297
|
+
/**
|
|
298
|
+
* Wrap an audit log port with default audit metadata redaction.
|
|
299
|
+
*
|
|
300
|
+
* Use this around durable adapters so application code can record entries
|
|
301
|
+
* without each call site remembering to redact metadata.
|
|
302
|
+
*
|
|
303
|
+
* @param audit - Underlying audit log port to write to after redaction.
|
|
304
|
+
* @param options - Optional final redaction/customization hook.
|
|
305
|
+
* @returns An audit log port that normalizes and redacts before writing.
|
|
306
|
+
*/
|
|
56
307
|
export declare function createRedactedAuditLog(audit: AuditLogPort, options?: AuditLogOptions): AuditLogPort;
|
|
308
|
+
/**
|
|
309
|
+
* Create an in-memory audit log for tests and local examples.
|
|
310
|
+
*
|
|
311
|
+
* Entries are normalized and redacted before being pushed into the shared
|
|
312
|
+
* `entries` array.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const audit = createMemoryAuditLog();
|
|
317
|
+
* await audit.record({
|
|
318
|
+
* action: "posts.publish",
|
|
319
|
+
* actor: createUserActor("user_1"),
|
|
320
|
+
* });
|
|
321
|
+
* expect(audit.entries).toHaveLength(1);
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @param entries - Optional backing array, useful when tests need shared state.
|
|
325
|
+
* @param options - Optional final redaction/customization hook.
|
|
326
|
+
* @returns An in-memory audit log port with captured `entries`.
|
|
327
|
+
*/
|
|
57
328
|
export declare function createMemoryAuditLog(entries?: AuditLogEntry[], options?: AuditLogOptions): MemoryAuditLogPort;
|
|
58
329
|
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/ports/audit.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAC7B,qBAAqB,EAAE,GACvB,OAAO,GACP,IAAI,GACJ,MAAM,GACN,MAAM,GACN;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAA;CAAE,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,MAAM,EACN,qBAAqB,GAAG,SAAS,CAClC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