@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
package/dist/ports/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - `EventBusPort` – interface for event bus implementations
|
|
11
11
|
* - `JobDispatcherPort` – interface for job dispatch implementations
|
|
12
12
|
* - `UnitOfWorkPort` – interface for app-owned transaction boundaries
|
|
13
|
+
* - `OutboxPort` – interface for durable event/job delivery storage
|
|
14
|
+
* - `IdempotencyPort` – interface for retry-safe command/key storage
|
|
13
15
|
* - `AuthPort` – interface for request authentication implementations
|
|
14
16
|
* - `AuditLogPort` – interface for audit/activity log implementations
|
|
15
17
|
* - `ClockPort` – interface for deterministic time
|
|
@@ -21,7 +23,10 @@
|
|
|
21
23
|
* - `StoragePort` – interface for object/file storage implementations
|
|
22
24
|
*
|
|
23
25
|
* Dedicated framework areas own their capability-specific APIs:
|
|
26
|
+
* - `@beignet/core/idempotency` owns idempotency helpers and test adapters
|
|
24
27
|
* - `@beignet/core/mail` owns `MailerPort` and mail test adapters
|
|
28
|
+
* - `@beignet/core/notifications` owns notification helpers and test adapters
|
|
29
|
+
* - `@beignet/core/outbox` owns durable outbox helpers and test adapters
|
|
25
30
|
* - `@beignet/core/schedules` owns scheduled task definitions and runners
|
|
26
31
|
*/
|
|
27
32
|
/**
|
|
@@ -73,26 +78,104 @@ export declare function definePorts<P extends AnyPorts>(ports: P): P;
|
|
|
73
78
|
export interface PortsContext<P extends AnyPorts = AnyPorts> {
|
|
74
79
|
ports: P;
|
|
75
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Idempotency port exports.
|
|
83
|
+
*/
|
|
84
|
+
export type { IdempotencyCompleteInput, IdempotencyFailInput, IdempotencyPort, IdempotencyReservation, IdempotencyReserveInput, } from "../idempotency";
|
|
85
|
+
/**
|
|
86
|
+
* Notification port exports.
|
|
87
|
+
*/
|
|
88
|
+
export type { MemoryNotificationDelivery, MemoryNotificationPort, NotificationChannelResult, NotificationPort, SendNotificationOptions, SendNotificationResult, } from "../notifications";
|
|
89
|
+
/**
|
|
90
|
+
* Transactional outbox port exports.
|
|
91
|
+
*/
|
|
92
|
+
export type { ClaimedOutboxMessage, OutboxClaimBatchOptions, OutboxEnqueueInput, OutboxMarkDeliveredInput, OutboxMarkFailedInput, OutboxMessage, OutboxMessageKind, OutboxMessageStatus, OutboxPort, } from "../outbox";
|
|
93
|
+
/**
|
|
94
|
+
* Audit log port exports.
|
|
95
|
+
*/
|
|
76
96
|
export type { ActivityActor, ActivityActorType, ActivityMetadata, ActivityMetadataValue, ActivityResource, ActivityTenant, AuditLogEntry, AuditLogEntryInput, AuditLogOptions, AuditLogPort, AuditOutcome, MemoryAuditLogPort, } from "./audit";
|
|
97
|
+
/**
|
|
98
|
+
* Audit log helper exports.
|
|
99
|
+
*/
|
|
77
100
|
export { createAnonymousActor, createMemoryAuditLog, createRedactedAuditLog, createServiceActor, createSystemActor, createTenant, createUserActor, normalizeAuditLogEntry, redactAuditLogEntry, } from "./audit";
|
|
101
|
+
/**
|
|
102
|
+
* Auth port exports.
|
|
103
|
+
*/
|
|
78
104
|
export type { AuthPort, AuthRequestLike, AuthSession, StaticAuthSessionFactory, } from "./auth";
|
|
105
|
+
/**
|
|
106
|
+
* Auth helper exports.
|
|
107
|
+
*/
|
|
79
108
|
export { AuthUnauthorizedError, createAnonymousAuth, createStaticAuth, } from "./auth";
|
|
109
|
+
/**
|
|
110
|
+
* Ports builder exports.
|
|
111
|
+
*/
|
|
80
112
|
export { createPortsBuilder, type PortsBuilder, type PortsOf, } from "./builder";
|
|
113
|
+
/**
|
|
114
|
+
* Cache port exports.
|
|
115
|
+
*/
|
|
81
116
|
export type { CachePort, CacheSetOptions } from "./cache";
|
|
117
|
+
/**
|
|
118
|
+
* Cache helper exports.
|
|
119
|
+
*/
|
|
82
120
|
export { createMemoryCache } from "./cache";
|
|
121
|
+
/**
|
|
122
|
+
* Clock port exports.
|
|
123
|
+
*/
|
|
83
124
|
export type { ClockPort, FrozenClockPort } from "./clock";
|
|
125
|
+
/**
|
|
126
|
+
* Clock helper exports.
|
|
127
|
+
*/
|
|
84
128
|
export { createFrozenClock, createSystemClock } from "./clock";
|
|
129
|
+
/**
|
|
130
|
+
* Event bus and job dispatcher port exports.
|
|
131
|
+
*/
|
|
85
132
|
export type { DomainEventDef, EventBusPort, InferEventPayload, InferJobPayload, JobDef, JobDispatcherPort, } from "./events";
|
|
133
|
+
/**
|
|
134
|
+
* ID generator port exports.
|
|
135
|
+
*/
|
|
86
136
|
export type { IdGeneratorPort, SequenceIdGeneratorPort } from "./id-generator";
|
|
137
|
+
/**
|
|
138
|
+
* ID generator helper exports.
|
|
139
|
+
*/
|
|
87
140
|
export { createSequenceIdGenerator, createUuidIdGenerator, } from "./id-generator";
|
|
141
|
+
/**
|
|
142
|
+
* Logger port exports.
|
|
143
|
+
*/
|
|
88
144
|
export type { LoggerPort, LogLevel, MemoryLogEntry, MemoryLoggerPort, } from "./logger";
|
|
145
|
+
/**
|
|
146
|
+
* Logger helper exports.
|
|
147
|
+
*/
|
|
89
148
|
export { createMemoryLogger, createNoopLogger } from "./logger";
|
|
149
|
+
/**
|
|
150
|
+
* Policy and authorization gate type exports.
|
|
151
|
+
*/
|
|
90
152
|
export type { BoundGate, CreateGateOptions, GateAllowedDecision, GateDecision, GateDeniedDecision, GateDenyHandler, GatePolicyResult, GatePort, PolicyContextFromDefinitions, PolicyDefinition, PolicyMapFromDefinitions, PolicyResolver, PolicySubjectArgs, } from "./policy";
|
|
153
|
+
/**
|
|
154
|
+
* Policy and authorization gate helper exports.
|
|
155
|
+
*/
|
|
91
156
|
export { allow, createGate, definePolicy, deny, GateAuthorizationError, } from "./policy";
|
|
157
|
+
/**
|
|
158
|
+
* Rate limit port exports.
|
|
159
|
+
*/
|
|
92
160
|
export type { RateLimitHitOptions, RateLimitPort, RateLimitResult, } from "./rate-limit";
|
|
161
|
+
/**
|
|
162
|
+
* Rate limit helper exports.
|
|
163
|
+
*/
|
|
93
164
|
export { createMemoryRateLimiter } from "./rate-limit";
|
|
165
|
+
/**
|
|
166
|
+
* Redaction helper exports.
|
|
167
|
+
*/
|
|
94
168
|
export { createRedactor, DEFAULT_CIRCULAR_VALUE, DEFAULT_REDACTED_VALUE, DEFAULT_SENSITIVE_KEY_TERMS, DEFAULT_SENSITIVE_KEYS, DEFAULT_TRUNCATED_VALUE, isSensitiveKey, type RedactableHeaders, type RedactionDecisionContext, type RedactionOptions, type Redactor, redactHeaders, redactValue, } from "./redaction";
|
|
169
|
+
/**
|
|
170
|
+
* Storage port exports.
|
|
171
|
+
*/
|
|
95
172
|
export type { MemoryStorageOptions, StorageBody, StorageMetadata, StorageObject, StorageObjectBody, StoragePort, StoragePutOptions, StorageVisibility, } from "./storage";
|
|
173
|
+
/**
|
|
174
|
+
* Storage helper exports.
|
|
175
|
+
*/
|
|
96
176
|
export { createMemoryStorage } from "./storage";
|
|
177
|
+
/**
|
|
178
|
+
* Unit of Work port exports.
|
|
179
|
+
*/
|
|
97
180
|
export { type BufferedDomainEventRecorder, createDomainEventRecorder, createNoopUnitOfWork, type DomainEventRecorderPort, type NoopUnitOfWorkOptions, type RecordedDomainEvent, type UnitOfWorkCallback, type UnitOfWorkPort, } from "./unit-of-work";
|
|
98
181
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAA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MAAM,cAAc,CAAC;AACtB;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD;;GAEG;AACH,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,aAAa,EACb,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB;;GAEG;AACH,YAAY,EACV,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD;;GAEG;AACH,OAAO,EACL,KAAK,2BAA2B,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC"}
|
package/dist/ports/index.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - `EventBusPort` – interface for event bus implementations
|
|
11
11
|
* - `JobDispatcherPort` – interface for job dispatch implementations
|
|
12
12
|
* - `UnitOfWorkPort` – interface for app-owned transaction boundaries
|
|
13
|
+
* - `OutboxPort` – interface for durable event/job delivery storage
|
|
14
|
+
* - `IdempotencyPort` – interface for retry-safe command/key storage
|
|
13
15
|
* - `AuthPort` – interface for request authentication implementations
|
|
14
16
|
* - `AuditLogPort` – interface for audit/activity log implementations
|
|
15
17
|
* - `ClockPort` – interface for deterministic time
|
|
@@ -21,7 +23,10 @@
|
|
|
21
23
|
* - `StoragePort` – interface for object/file storage implementations
|
|
22
24
|
*
|
|
23
25
|
* Dedicated framework areas own their capability-specific APIs:
|
|
26
|
+
* - `@beignet/core/idempotency` owns idempotency helpers and test adapters
|
|
24
27
|
* - `@beignet/core/mail` owns `MailerPort` and mail test adapters
|
|
28
|
+
* - `@beignet/core/notifications` owns notification helpers and test adapters
|
|
29
|
+
* - `@beignet/core/outbox` owns durable outbox helpers and test adapters
|
|
25
30
|
* - `@beignet/core/schedules` owns scheduled task definitions and runners
|
|
26
31
|
*/
|
|
27
32
|
/**
|
|
@@ -47,21 +52,52 @@
|
|
|
47
52
|
export function definePorts(ports) {
|
|
48
53
|
return ports;
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Audit log helper exports.
|
|
57
|
+
*/
|
|
50
58
|
export { createAnonymousActor, createMemoryAuditLog, createRedactedAuditLog, createServiceActor, createSystemActor, createTenant, createUserActor, normalizeAuditLogEntry, redactAuditLogEntry, } from "./audit";
|
|
59
|
+
/**
|
|
60
|
+
* Auth helper exports.
|
|
61
|
+
*/
|
|
51
62
|
export { AuthUnauthorizedError, createAnonymousAuth, createStaticAuth, } from "./auth";
|
|
52
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Ports builder exports.
|
|
65
|
+
*/
|
|
53
66
|
export { createPortsBuilder, } from "./builder";
|
|
54
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Cache helper exports.
|
|
69
|
+
*/
|
|
55
70
|
export { createMemoryCache } from "./cache";
|
|
71
|
+
/**
|
|
72
|
+
* Clock helper exports.
|
|
73
|
+
*/
|
|
56
74
|
export { createFrozenClock, createSystemClock } from "./clock";
|
|
75
|
+
/**
|
|
76
|
+
* ID generator helper exports.
|
|
77
|
+
*/
|
|
57
78
|
export { createSequenceIdGenerator, createUuidIdGenerator, } from "./id-generator";
|
|
79
|
+
/**
|
|
80
|
+
* Logger helper exports.
|
|
81
|
+
*/
|
|
58
82
|
export { createMemoryLogger, createNoopLogger } from "./logger";
|
|
83
|
+
/**
|
|
84
|
+
* Policy and authorization gate helper exports.
|
|
85
|
+
*/
|
|
59
86
|
export { allow, createGate, definePolicy, deny, GateAuthorizationError, } from "./policy";
|
|
60
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Rate limit helper exports.
|
|
89
|
+
*/
|
|
61
90
|
export { createMemoryRateLimiter } from "./rate-limit";
|
|
62
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Redaction helper exports.
|
|
93
|
+
*/
|
|
63
94
|
export { createRedactor, DEFAULT_CIRCULAR_VALUE, DEFAULT_REDACTED_VALUE, DEFAULT_SENSITIVE_KEY_TERMS, DEFAULT_SENSITIVE_KEYS, DEFAULT_TRUNCATED_VALUE, isSensitiveKey, redactHeaders, redactValue, } from "./redaction";
|
|
95
|
+
/**
|
|
96
|
+
* Storage helper exports.
|
|
97
|
+
*/
|
|
64
98
|
export { createMemoryStorage } from "./storage";
|
|
65
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Unit of Work port exports.
|
|
101
|
+
*/
|
|
66
102
|
export { createDomainEventRecorder, createNoopUnitOfWork, } from "./unit-of-work";
|
|
67
103
|
//# sourceMappingURL=index.js.map
|
package/dist/ports/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAWH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CAAqB,KAAQ;IACtD,OAAO,KAAK,CAAC;AACf,CAAC;AA2ED;;GAEG;AACH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAUjB;;GAEG;AACH,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB;;GAEG;AACH,OAAO,EACL,kBAAkB,GAGnB,MAAM,WAAW,CAAC;AAKnB;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAK5C;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAgB/D;;GAEG;AACH,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAUxB;;GAEG;AACH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAmBhE;;GAEG;AACH,OAAO,EACL,KAAK,EACL,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,sBAAsB,GACvB,MAAM,UAAU,CAAC;AASlB;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD;;GAEG;AACH,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EAKd,aAAa,EACb,WAAW,GACZ,MAAM,aAAa,CAAC;AAcrB;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD;;GAEG;AACH,OAAO,EAEL,yBAAyB,EACzB,oBAAoB,GAMrB,MAAM,gBAAgB,CAAC"}
|
package/dist/ports/logger.d.ts
CHANGED
|
@@ -1,22 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported structured logger levels.
|
|
3
|
+
*/
|
|
1
4
|
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
5
|
+
/**
|
|
6
|
+
* App-facing structured logger port.
|
|
7
|
+
*
|
|
8
|
+
* Application code logs through this interface so production can use Pino,
|
|
9
|
+
* Datadog, or another adapter while tests can use no-op or memory loggers.
|
|
10
|
+
*/
|
|
2
11
|
export interface LoggerPort {
|
|
12
|
+
/**
|
|
13
|
+
* Log very detailed diagnostic information.
|
|
14
|
+
*/
|
|
3
15
|
trace(message: string, meta?: Record<string, unknown>): void;
|
|
16
|
+
/**
|
|
17
|
+
* Log debug-level diagnostic information.
|
|
18
|
+
*/
|
|
4
19
|
debug(message: string, meta?: Record<string, unknown>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Log normal application progress.
|
|
22
|
+
*/
|
|
5
23
|
info(message: string, meta?: Record<string, unknown>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log recoverable problems or unusual conditions.
|
|
26
|
+
*/
|
|
6
27
|
warn(message: string, meta?: Record<string, unknown>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log failed operations.
|
|
30
|
+
*/
|
|
7
31
|
error(message: string, meta?: Record<string, unknown>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Log unrecoverable failures.
|
|
34
|
+
*/
|
|
8
35
|
fatal(message: string, meta?: Record<string, unknown>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Return a logger with additional structured bindings.
|
|
38
|
+
*/
|
|
9
39
|
child(bindings: Record<string, unknown>): LoggerPort;
|
|
10
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Captured entry from `createMemoryLogger(...)`.
|
|
43
|
+
*/
|
|
11
44
|
export interface MemoryLogEntry {
|
|
12
45
|
level: LogLevel;
|
|
13
46
|
message: string;
|
|
14
47
|
meta?: Record<string, unknown>;
|
|
15
48
|
bindings: Record<string, unknown>;
|
|
16
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* In-memory logger port used by tests and local assertions.
|
|
52
|
+
*/
|
|
17
53
|
export interface MemoryLoggerPort extends LoggerPort {
|
|
54
|
+
/**
|
|
55
|
+
* Captured log entries in call order.
|
|
56
|
+
*/
|
|
18
57
|
entries: MemoryLogEntry[];
|
|
19
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a logger that discards every log call.
|
|
61
|
+
*
|
|
62
|
+
* Use this in tests where logging is irrelevant.
|
|
63
|
+
*
|
|
64
|
+
* @returns A logger port whose methods are no-ops.
|
|
65
|
+
*/
|
|
20
66
|
export declare function createNoopLogger(): LoggerPort;
|
|
67
|
+
/**
|
|
68
|
+
* Create a logger that captures entries in memory.
|
|
69
|
+
*
|
|
70
|
+
* Child loggers inherit existing bindings and append new bindings to each
|
|
71
|
+
* captured entry.
|
|
72
|
+
*
|
|
73
|
+
* @param bindings - Structured bindings attached to every captured entry.
|
|
74
|
+
* @param entries - Optional shared entry array.
|
|
75
|
+
* @returns A logger port with an inspectable `entries` array.
|
|
76
|
+
*/
|
|
21
77
|
export declare function createMemoryLogger(bindings?: Record<string, unknown>, entries?: MemoryLogEntry[]): MemoryLoggerPort;
|
|
22
78
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/ports/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/E,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM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* Create a logger that discards every log call.
|
|
3
|
+
*
|
|
4
|
+
* Use this in tests where logging is irrelevant.
|
|
5
|
+
*
|
|
6
|
+
* @returns A logger port whose methods are no-ops.
|
|
7
|
+
*/
|
|
1
8
|
export function createNoopLogger() {
|
|
2
9
|
const logger = {
|
|
3
10
|
trace: () => { },
|
|
@@ -10,6 +17,16 @@ export function createNoopLogger() {
|
|
|
10
17
|
};
|
|
11
18
|
return logger;
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a logger that captures entries in memory.
|
|
22
|
+
*
|
|
23
|
+
* Child loggers inherit existing bindings and append new bindings to each
|
|
24
|
+
* captured entry.
|
|
25
|
+
*
|
|
26
|
+
* @param bindings - Structured bindings attached to every captured entry.
|
|
27
|
+
* @param entries - Optional shared entry array.
|
|
28
|
+
* @returns A logger port with an inspectable `entries` array.
|
|
29
|
+
*/
|
|
13
30
|
export function createMemoryLogger(bindings = {}, entries = []) {
|
|
14
31
|
const capturedBindings = { ...bindings };
|
|
15
32
|
const record = (level, message, meta) => {
|
package/dist/ports/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/ports/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/ports/logger.ts"],"names":[],"mappings":"AA8DA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAe;QACzB,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM;KACpB,CAAC;IAEF,OAAO,MAA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EAAE,OAAO,CAAC;KACzE,CAAC;AACJ,CAAC"}
|
package/dist/ports/policy.d.ts
CHANGED
|
@@ -1,53 +1,185 @@
|
|
|
1
1
|
type MaybePromise<T> = T | Promise<T>;
|
|
2
|
+
/**
|
|
3
|
+
* A policy decision that allows the requested ability.
|
|
4
|
+
*/
|
|
2
5
|
export type GateAllowedDecision = {
|
|
3
6
|
allowed: true;
|
|
4
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* A policy decision that denies the requested ability.
|
|
10
|
+
*
|
|
11
|
+
* Use `reason`, `code`, and `details` to preserve structured denial context for
|
|
12
|
+
* errors, audit logs, and tests.
|
|
13
|
+
*/
|
|
5
14
|
export type GateDeniedDecision = {
|
|
6
15
|
allowed: false;
|
|
7
16
|
reason?: string;
|
|
8
17
|
code?: string;
|
|
9
18
|
details?: unknown;
|
|
10
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Normalized authorization decision returned by gate inspection.
|
|
22
|
+
*/
|
|
11
23
|
export type GateDecision = GateAllowedDecision | GateDeniedDecision;
|
|
24
|
+
/**
|
|
25
|
+
* Value a policy resolver may return.
|
|
26
|
+
*
|
|
27
|
+
* Returning `true`/`false` is convenient for simple policies. Return
|
|
28
|
+
* `allow()`/`deny(...)` when the caller needs a denial reason, code, or
|
|
29
|
+
* structured details.
|
|
30
|
+
*/
|
|
12
31
|
export type GatePolicyResult = boolean | GateDecision;
|
|
32
|
+
/**
|
|
33
|
+
* Function that decides whether a context can perform an ability.
|
|
34
|
+
*
|
|
35
|
+
* The first argument is always the application context. Policies that operate
|
|
36
|
+
* on a record receive that record as their second argument.
|
|
37
|
+
*/
|
|
13
38
|
export type PolicyResolver = (...args: never[]) => MaybePromise<GatePolicyResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Typed collection of ability resolvers created by `definePolicy(...)`.
|
|
41
|
+
*/
|
|
14
42
|
export type PolicyDefinition<TPolicies extends Record<string, PolicyResolver> = Record<string, PolicyResolver>> = {
|
|
15
43
|
policies: TPolicies;
|
|
16
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Infer the application context type from a policy resolver.
|
|
47
|
+
*/
|
|
17
48
|
export type PolicyContext<TResolver> = TResolver extends (ctx: infer Ctx, ...args: never[]) => MaybePromise<GatePolicyResult> ? Ctx : never;
|
|
49
|
+
/**
|
|
50
|
+
* Infer whether an ability needs a subject argument.
|
|
51
|
+
*/
|
|
18
52
|
export type PolicySubjectArgs<TResolver> = TResolver extends (...args: infer TArgs) => MaybePromise<GatePolicyResult> ? TArgs extends [unknown, infer Subject] ? [subject: Subject] : [] : [];
|
|
19
53
|
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer U) => void ? U : never;
|
|
54
|
+
/**
|
|
55
|
+
* Merge the ability maps from multiple policy definitions.
|
|
56
|
+
*/
|
|
20
57
|
export type PolicyMapFromDefinitions<TPolicies extends readonly PolicyDefinition[]> = UnionToIntersection<TPolicies[number] extends PolicyDefinition<infer TPolicyMap> ? TPolicyMap : never>;
|
|
58
|
+
/**
|
|
59
|
+
* Infer the application context type shared by a list of policy definitions.
|
|
60
|
+
*/
|
|
21
61
|
export type PolicyContextFromDefinitions<TPolicies extends readonly PolicyDefinition[]> = PolicyContext<PolicyMapFromDefinitions<TPolicies>[keyof PolicyMapFromDefinitions<TPolicies>]>;
|
|
62
|
+
/**
|
|
63
|
+
* Gate bound to a specific application context.
|
|
64
|
+
*
|
|
65
|
+
* Apps commonly attach this to request context as `ctx.gate` so use cases can
|
|
66
|
+
* call `ctx.gate.authorize("posts.update", post)` without passing `ctx` back
|
|
67
|
+
* into every authorization call.
|
|
68
|
+
*/
|
|
22
69
|
export type BoundGate<TPolicies extends readonly PolicyDefinition[]> = {
|
|
70
|
+
/**
|
|
71
|
+
* Return only whether the ability is allowed.
|
|
72
|
+
*/
|
|
23
73
|
can<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Return the full allow/deny decision without throwing.
|
|
76
|
+
*/
|
|
24
77
|
inspect<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<GateDecision>;
|
|
78
|
+
/**
|
|
79
|
+
* Return an allowed decision or throw for denied abilities.
|
|
80
|
+
*/
|
|
25
81
|
authorize<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<GateAllowedDecision>;
|
|
26
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* App-facing authorization gate.
|
|
85
|
+
*
|
|
86
|
+
* The gate evaluates app-owned policies. It is not an authentication provider:
|
|
87
|
+
* authenticate at the HTTP boundary first, then pass the resulting actor/user
|
|
88
|
+
* data into policy context.
|
|
89
|
+
*/
|
|
27
90
|
export type GatePort<TContext, TPolicies extends readonly PolicyDefinition[] = readonly PolicyDefinition[]> = {
|
|
91
|
+
/**
|
|
92
|
+
* Bind this gate to a context, usually during `createContext`.
|
|
93
|
+
*/
|
|
28
94
|
bind(ctx: TContext): BoundGate<TPolicies>;
|
|
95
|
+
/**
|
|
96
|
+
* Return only whether the ability is allowed for a context.
|
|
97
|
+
*/
|
|
29
98
|
can<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ctx: TContext, ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Return the full allow/deny decision for a context without throwing.
|
|
101
|
+
*/
|
|
30
102
|
inspect<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ctx: TContext, ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<GateDecision>;
|
|
103
|
+
/**
|
|
104
|
+
* Return an allowed decision or throw for denied abilities.
|
|
105
|
+
*/
|
|
31
106
|
authorize<TAbility extends keyof PolicyMapFromDefinitions<TPolicies> & string>(ctx: TContext, ability: TAbility, ...subject: PolicySubjectArgs<PolicyMapFromDefinitions<TPolicies>[TAbility]>): Promise<GateAllowedDecision>;
|
|
32
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Hook used to convert a denied decision into an application-specific error.
|
|
110
|
+
*/
|
|
33
111
|
export type GateDenyHandler<TContext> = (decision: GateDeniedDecision, params: {
|
|
34
112
|
ctx: TContext;
|
|
35
113
|
ability: string;
|
|
36
114
|
subject?: unknown;
|
|
37
115
|
}) => MaybePromise<Error | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* Options for `createGate(...)`.
|
|
118
|
+
*/
|
|
38
119
|
export type CreateGateOptions<TContext, TPolicies extends readonly PolicyDefinition[]> = {
|
|
120
|
+
/**
|
|
121
|
+
* Policy definitions to register.
|
|
122
|
+
*/
|
|
39
123
|
policies: TPolicies;
|
|
124
|
+
/**
|
|
125
|
+
* Optional mapper for denied authorization decisions.
|
|
126
|
+
*/
|
|
40
127
|
onDeny?: GateDenyHandler<TContext>;
|
|
41
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Default error thrown by `authorize(...)` when a policy denies access.
|
|
131
|
+
*/
|
|
42
132
|
export declare class GateAuthorizationError extends Error {
|
|
43
133
|
readonly code: string;
|
|
44
134
|
readonly status = 403;
|
|
45
135
|
readonly details?: unknown;
|
|
46
136
|
constructor(decision?: GateDeniedDecision);
|
|
47
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Create an explicit allow decision.
|
|
140
|
+
*
|
|
141
|
+
* @returns A normalized gate decision with `allowed: true`.
|
|
142
|
+
*/
|
|
48
143
|
export declare function allow(): GateAllowedDecision;
|
|
144
|
+
/**
|
|
145
|
+
* Create an explicit deny decision.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* return deny("Only owners can edit this post");
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @param reasonOrDecision - Optional reason string or structured denial data.
|
|
153
|
+
* @returns A normalized gate decision with `allowed: false`.
|
|
154
|
+
*/
|
|
49
155
|
export declare function deny(reasonOrDecision?: string | Omit<GateDeniedDecision, "allowed">): GateDeniedDecision;
|
|
156
|
+
/**
|
|
157
|
+
* Define a typed group of authorization policies.
|
|
158
|
+
*
|
|
159
|
+
* Keep policy definitions near the feature that owns the business rule. The
|
|
160
|
+
* returned definition is registered with `createGate(...)`.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* export const postPolicy = definePolicy({
|
|
165
|
+
* "posts.update": (ctx, post: Post) => post.authorId === ctx.actor.id,
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @param policies - Ability resolver map keyed by stable ability names.
|
|
170
|
+
* @returns A typed policy definition for registration with `createGate(...)`.
|
|
171
|
+
*/
|
|
50
172
|
export declare function definePolicy<const TPolicies extends Record<string, PolicyResolver>>(policies: TPolicies): PolicyDefinition<TPolicies>;
|
|
173
|
+
/**
|
|
174
|
+
* Create an authorization gate from app-owned policy definitions.
|
|
175
|
+
*
|
|
176
|
+
* Register the gate as a port, then bind it to the request/background context:
|
|
177
|
+
* `gate: ports.gate.bind(context)`. Use cases can then call
|
|
178
|
+
* `ctx.gate.authorize(...)` for business authorization.
|
|
179
|
+
*
|
|
180
|
+
* @param options - Policy definitions and optional denial mapper.
|
|
181
|
+
* @returns A gate port that can evaluate registered abilities.
|
|
182
|
+
*/
|
|
51
183
|
export declare function createGate<TContext, const TPolicies extends readonly PolicyDefinition[]>(options: CreateGateOptions<TContext, TPolicies>): GatePort<TContext, TPolicies>;
|
|
52
184
|
export {};
|
|
53
185
|
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/ports/policy.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/ports/policy.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,YAAY,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,IAAI,EAAE,KAAK,EAAE,KACb,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,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;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAClB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,GAC9D,kBAAkB,CASpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACtD,QAAQ,EAAE,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAElD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EACR,KAAK,CAAC,SAAS,SAAS,SAAS,gBAAgB,EAAE,EAEnD,OAAO,EAAE,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,GAC9C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAgE/B"}
|
package/dist/ports/policy.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default error thrown by `authorize(...)` when a policy denies access.
|
|
3
|
+
*/
|
|
1
4
|
export class GateAuthorizationError extends Error {
|
|
2
5
|
code;
|
|
3
6
|
status = 403;
|
|
@@ -9,9 +12,25 @@ export class GateAuthorizationError extends Error {
|
|
|
9
12
|
this.details = decision.details;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Create an explicit allow decision.
|
|
17
|
+
*
|
|
18
|
+
* @returns A normalized gate decision with `allowed: true`.
|
|
19
|
+
*/
|
|
12
20
|
export function allow() {
|
|
13
21
|
return { allowed: true };
|
|
14
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Create an explicit deny decision.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* return deny("Only owners can edit this post");
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param reasonOrDecision - Optional reason string or structured denial data.
|
|
32
|
+
* @returns A normalized gate decision with `allowed: false`.
|
|
33
|
+
*/
|
|
15
34
|
export function deny(reasonOrDecision) {
|
|
16
35
|
if (typeof reasonOrDecision === "string") {
|
|
17
36
|
return { allowed: false, reason: reasonOrDecision };
|
|
@@ -21,9 +40,35 @@ export function deny(reasonOrDecision) {
|
|
|
21
40
|
...reasonOrDecision,
|
|
22
41
|
};
|
|
23
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Define a typed group of authorization policies.
|
|
45
|
+
*
|
|
46
|
+
* Keep policy definitions near the feature that owns the business rule. The
|
|
47
|
+
* returned definition is registered with `createGate(...)`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* export const postPolicy = definePolicy({
|
|
52
|
+
* "posts.update": (ctx, post: Post) => post.authorId === ctx.actor.id,
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param policies - Ability resolver map keyed by stable ability names.
|
|
57
|
+
* @returns A typed policy definition for registration with `createGate(...)`.
|
|
58
|
+
*/
|
|
24
59
|
export function definePolicy(policies) {
|
|
25
60
|
return { policies };
|
|
26
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Create an authorization gate from app-owned policy definitions.
|
|
64
|
+
*
|
|
65
|
+
* Register the gate as a port, then bind it to the request/background context:
|
|
66
|
+
* `gate: ports.gate.bind(context)`. Use cases can then call
|
|
67
|
+
* `ctx.gate.authorize(...)` for business authorization.
|
|
68
|
+
*
|
|
69
|
+
* @param options - Policy definitions and optional denial mapper.
|
|
70
|
+
* @returns A gate port that can evaluate registered abilities.
|
|
71
|
+
*/
|
|
27
72
|
export function createGate(options) {
|
|
28
73
|
const registry = new Map();
|
|
29
74
|
for (const definition of options.policies) {
|
package/dist/ports/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/ports/policy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../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