@classytic/payroll 2.7.5 → 2.8.0

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.
@@ -0,0 +1,321 @@
1
+ import { E as EmployeeDocument, P as PayrollRecordDocument, A as AnyDocument, L as LeaveRequestDocument, T as TaxWithholdingDocument, H as HRMConfig, S as SingleTenantConfig, a as Logger } from '../types-bZdAJueH.js';
2
+ export { b as AttendanceInput, C as CompensationChangedEventPayload, D as DEFAULT_WORK_SCHEDULE, c as EmployeeHiredEventPayload, d as EmployeeRehiredEventPayload, e as EmployeeTerminatedEventPayload, f as EventBus, M as MilestoneAchievedEventPayload, N as NotificationPluginOptions, g as PayrollCompletedEventPayload, h as PayrollEventHandler, i as PayrollEventMap, j as PayrollEventType, k as PayrollExportedEventPayload, l as PayrollPluginDefinition, m as PayrollProcessingOptions, n as PluginContext, o as PluginHooks, p as PluginLogger, q as PluginManager, r as ProrationResult, s as SalaryFailedEventPayload, t as SalaryProcessedEventPayload, u as SalaryUpdatedEventPayload, W as WebhookConfig, v as WebhookDelivery, w as WebhookManager, x as WorkSchedule, y as WorkingDaysResult, z as calculateProration, B as countWorkingDays, F as createEventBus, G as createNotificationPlugin, I as definePlugin, J as getEventBus, K as getPayPeriod, O as loggingPlugin, Q as metricsPlugin, R as notificationPlugin, U as onEmployeeHired, V as onMilestoneAchieved, X as onPayrollCompleted, Y as onSalaryProcessed, Z as resetEventBus } from '../types-bZdAJueH.js';
3
+ export { E as EMPLOYEE_TIMELINE_CONFIG, a as EmployeeStatusMachine, b as EmployeeStatusState, I as IdempotencyManager, c as IdempotentResult, L as LEAVE_REQUEST_TIMELINE_CONFIG, d as LeaveRequestStatusMachine, e as LeaveRequestStatusState, P as PAYROLL_EVENTS, f as PAYROLL_RECORD_TIMELINE_CONFIG, g as PayrollStatusMachine, h as PayrollStatusState, i as PayrollTimelineEvent, S as StateMachine, j as StateMachineConfig, k as StateTransition, T as TaxStatusMachine, l as TaxStatusState, m as TransitionResult, n as buildRequestContext, o as buildTimelineMetadata, p as createStateMachine, q as generatePayrollIdempotencyKey, r as multiTenantPlugin } from '../payroll-states-DBt0XVm-.js';
4
+ import { Model, ClientSession } from 'mongoose';
5
+ export { c as calculateAttendanceDeduction, g as calculateSalaryBreakdown } from '../attendance.calculator-BZcv2iii.js';
6
+ import '@classytic/mongokit';
7
+
8
+ /**
9
+ * @classytic/payroll - Result Type
10
+ *
11
+ * Rust-inspired Result type for type-safe error handling
12
+ * No more try/catch everywhere - explicit error handling
13
+ */
14
+ /** Success result */
15
+ interface Ok<T> {
16
+ readonly ok: true;
17
+ readonly value: T;
18
+ }
19
+ /** Error result */
20
+ interface Err<E> {
21
+ readonly ok: false;
22
+ readonly error: E;
23
+ }
24
+ /**
25
+ * Create a success result
26
+ */
27
+ declare function ok<T>(value: T): Ok<T>;
28
+ /**
29
+ * Create an error result
30
+ */
31
+ declare function err<E>(error: E): Err<E>;
32
+ /**
33
+ * Check if result is success
34
+ */
35
+ declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
36
+ /**
37
+ * Check if result is error
38
+ */
39
+ declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
40
+ /**
41
+ * Unwrap result value or throw error
42
+ */
43
+ declare function unwrap<T, E>(result: Result<T, E>): T;
44
+ /**
45
+ * Unwrap result value or return default
46
+ */
47
+ declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
48
+ /**
49
+ * Unwrap result value or compute default
50
+ */
51
+ declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
52
+ /**
53
+ * Map success value
54
+ */
55
+ declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
56
+ /**
57
+ * Map error value
58
+ */
59
+ declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
60
+ /**
61
+ * FlatMap (chain) success value
62
+ */
63
+ declare function flatMap<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
64
+ /**
65
+ * Try/catch wrapper for async functions
66
+ */
67
+ declare function tryCatch<T, E = Error>(fn: () => Promise<T>, errorTransform?: (error: unknown) => E): Promise<Result<T, E>>;
68
+ /**
69
+ * Try/catch wrapper for sync functions
70
+ */
71
+ declare function tryCatchSync<T, E = Error>(fn: () => T, errorTransform?: (error: unknown) => E): Result<T, E>;
72
+ /**
73
+ * Combine multiple results into one
74
+ */
75
+ declare function all<T, E>(results: Result<T, E>[]): Result<T[], E>;
76
+ /**
77
+ * Pattern match on result
78
+ */
79
+ declare function match<T, E, R>(result: Result<T, E>, handlers: {
80
+ ok: (value: T) => R;
81
+ err: (error: E) => R;
82
+ }): R;
83
+ /**
84
+ * Convert Promise<Result> to Result<Promise>
85
+ */
86
+ declare function fromPromise<T, E = Error>(promise: Promise<T>, errorTransform?: (error: unknown) => E): Promise<Result<T, E>>;
87
+ /**
88
+ * Create Result from nullable value
89
+ */
90
+ declare function fromNullable<T, E>(value: T | null | undefined, error: E): Result<T, E>;
91
+ declare class ResultClass<T, E = Error> {
92
+ private readonly result;
93
+ private constructor();
94
+ static ok<T>(value: T): ResultClass<T, never>;
95
+ static err<E>(error: E): ResultClass<never, E>;
96
+ static fromAsync<T, E = Error>(fn: () => Promise<T>, errorTransform?: (error: unknown) => E): Promise<ResultClass<T, E>>;
97
+ isOk(): boolean;
98
+ isErr(): boolean;
99
+ unwrap(): T;
100
+ unwrapOr(defaultValue: T): T;
101
+ map<U>(fn: (value: T) => U): ResultClass<U, E>;
102
+ mapErr<F>(fn: (error: E) => F): ResultClass<T, F>;
103
+ flatMap<U>(fn: (value: T) => Result<U, E>): ResultClass<U, E>;
104
+ match<R>(handlers: {
105
+ ok: (value: T) => R;
106
+ err: (error: E) => R;
107
+ }): R;
108
+ toResult(): Result<T, E>;
109
+ }
110
+ /** Result type - either success or error */
111
+ type Result<T, E = Error> = Ok<T> | Err<E>;
112
+ declare const Result: {
113
+ ok: typeof ok;
114
+ err: typeof err;
115
+ isOk: typeof isOk;
116
+ isErr: typeof isErr;
117
+ unwrap: typeof unwrap;
118
+ unwrapOr: typeof unwrapOr;
119
+ unwrapOrElse: typeof unwrapOrElse;
120
+ map: typeof map;
121
+ mapErr: typeof mapErr;
122
+ flatMap: typeof flatMap;
123
+ tryCatch: typeof tryCatch;
124
+ tryCatchSync: typeof tryCatchSync;
125
+ all: typeof all;
126
+ match: typeof match;
127
+ fromPromise: typeof fromPromise;
128
+ fromNullable: typeof fromNullable;
129
+ };
130
+
131
+ /**
132
+ * @classytic/payroll - Dependency Container
133
+ *
134
+ * Per-instance dependency injection container for service management.
135
+ * Enables clean dependency injection and testing without global state.
136
+ *
137
+ * IMPORTANT: This container is instance-based (not a singleton) to support:
138
+ * - Serverless/Lambda environments
139
+ * - Multi-app runtimes
140
+ * - Parallel testing
141
+ * - Multiple Payroll instances in the same process
142
+ */
143
+
144
+ /**
145
+ * Strongly-typed models container
146
+ * Uses specific document types instead of Model<any> for better DX
147
+ */
148
+ interface ModelsContainer<TEmployee extends EmployeeDocument = EmployeeDocument, TPayrollRecord extends PayrollRecordDocument = PayrollRecordDocument, TTransaction extends AnyDocument = AnyDocument, TAttendance extends AnyDocument = AnyDocument, TLeaveRequest extends LeaveRequestDocument = LeaveRequestDocument, TTaxWithholding extends TaxWithholdingDocument = TaxWithholdingDocument> {
149
+ EmployeeModel: Model<TEmployee>;
150
+ PayrollRecordModel: Model<TPayrollRecord>;
151
+ TransactionModel: Model<TTransaction>;
152
+ AttendanceModel?: Model<TAttendance> | null;
153
+ LeaveRequestModel?: Model<TLeaveRequest> | null;
154
+ TaxWithholdingModel?: Model<TTaxWithholding> | null;
155
+ }
156
+ /**
157
+ * Container configuration with generic model types
158
+ */
159
+ interface ContainerConfig<TEmployee extends EmployeeDocument = EmployeeDocument, TPayrollRecord extends PayrollRecordDocument = PayrollRecordDocument, TTransaction extends AnyDocument = AnyDocument, TAttendance extends AnyDocument = AnyDocument, TLeaveRequest extends LeaveRequestDocument = LeaveRequestDocument, TTaxWithholding extends TaxWithholdingDocument = TaxWithholdingDocument> {
160
+ models: ModelsContainer<TEmployee, TPayrollRecord, TTransaction, TAttendance, TLeaveRequest, TTaxWithholding>;
161
+ config?: Partial<HRMConfig>;
162
+ singleTenant?: SingleTenantConfig | null;
163
+ logger?: Logger;
164
+ }
165
+ /**
166
+ * Per-instance DI Container for Payroll
167
+ *
168
+ * Each Payroll instance creates its own Container, avoiding global state issues
169
+ * in serverless and multi-app environments.
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Each Payroll instance has its own container
174
+ * const payroll1 = createPayrollInstance()
175
+ * .withModels({ EmployeeModel, PayrollRecordModel, TransactionModel })
176
+ * .build();
177
+ *
178
+ * const payroll2 = createPayrollInstance()
179
+ * .withModels({ OtherEmployeeModel, OtherPayrollModel, OtherTransactionModel })
180
+ * .build();
181
+ *
182
+ * // They don't share state - perfect for multi-tenant or testing
183
+ * ```
184
+ */
185
+ declare class Container<TEmployee extends EmployeeDocument = EmployeeDocument, TPayrollRecord extends PayrollRecordDocument = PayrollRecordDocument, TTransaction extends AnyDocument = AnyDocument, TAttendance extends AnyDocument = AnyDocument, TLeaveRequest extends LeaveRequestDocument = LeaveRequestDocument, TTaxWithholding extends TaxWithholdingDocument = TaxWithholdingDocument> {
186
+ private _models;
187
+ private _config;
188
+ private _singleTenant;
189
+ private _logger;
190
+ private _initialized;
191
+ constructor();
192
+ /**
193
+ * Initialize container with configuration
194
+ */
195
+ initialize(config: ContainerConfig<TEmployee, TPayrollRecord, TTransaction, TAttendance, TLeaveRequest, TTaxWithholding>): void;
196
+ /**
197
+ * Check if container is initialized
198
+ */
199
+ isInitialized(): boolean;
200
+ /**
201
+ * Reset container (useful for testing)
202
+ */
203
+ reset(): void;
204
+ /**
205
+ * Ensure container is initialized
206
+ */
207
+ private ensureInitialized;
208
+ /**
209
+ * Get models container (strongly typed)
210
+ */
211
+ getModels(): ModelsContainer<TEmployee, TPayrollRecord, TTransaction, TAttendance, TLeaveRequest, TTaxWithholding>;
212
+ /**
213
+ * Get Employee model (strongly typed)
214
+ */
215
+ getEmployeeModel(): Model<TEmployee>;
216
+ /**
217
+ * Get PayrollRecord model (strongly typed)
218
+ */
219
+ getPayrollRecordModel(): Model<TPayrollRecord>;
220
+ /**
221
+ * Get Transaction model (strongly typed)
222
+ */
223
+ getTransactionModel(): Model<TTransaction>;
224
+ /**
225
+ * Get Attendance model (optional, strongly typed)
226
+ */
227
+ getAttendanceModel(): Model<TAttendance> | null;
228
+ /**
229
+ * Get LeaveRequest model (optional, strongly typed)
230
+ */
231
+ getLeaveRequestModel(): Model<TLeaveRequest> | null;
232
+ /**
233
+ * Get TaxWithholding model (optional, strongly typed)
234
+ */
235
+ getTaxWithholdingModel(): Model<TTaxWithholding> | null;
236
+ /**
237
+ * Get configuration
238
+ */
239
+ getConfig(): HRMConfig;
240
+ /**
241
+ * Get specific config section
242
+ */
243
+ getConfigSection<K extends keyof HRMConfig>(section: K): HRMConfig[K];
244
+ /**
245
+ * Check if single-tenant mode
246
+ */
247
+ isSingleTenant(): boolean;
248
+ /**
249
+ * Get single-tenant config
250
+ */
251
+ getSingleTenantConfig(): SingleTenantConfig | null;
252
+ /**
253
+ * Get organization ID (for single-tenant mode)
254
+ */
255
+ getOrganizationId(): string | null;
256
+ /**
257
+ * Get logger
258
+ */
259
+ getLogger(): Logger;
260
+ /**
261
+ * Set logger
262
+ */
263
+ setLogger(logger: Logger): void;
264
+ /**
265
+ * Has attendance integration
266
+ */
267
+ hasAttendanceIntegration(): boolean;
268
+ /**
269
+ * Create operation context with defaults
270
+ *
271
+ * In single-tenant mode with autoInject enabled (default), automatically
272
+ * injects the configured organizationId into the context.
273
+ *
274
+ * @throws Error if autoInject is enabled but no organizationId is configured
275
+ */
276
+ createOperationContext(overrides?: Partial<{
277
+ userId: string;
278
+ userName: string;
279
+ userRole: string;
280
+ organizationId: string;
281
+ session: ClientSession;
282
+ }>): {
283
+ userId?: string;
284
+ userName?: string;
285
+ userRole?: string;
286
+ organizationId?: string;
287
+ session?: ClientSession;
288
+ };
289
+ }
290
+ /**
291
+ * @deprecated Use createPayrollInstance() instead.
292
+ * Get or create the default container instance.
293
+ */
294
+ declare function getContainer(): Container;
295
+ /**
296
+ * @deprecated Use createPayrollInstance() instead.
297
+ * Initialize the default container.
298
+ */
299
+ declare function initializeContainer(config: ContainerConfig): void;
300
+ /**
301
+ * @deprecated Use container.isInitialized() instead.
302
+ * Check if the default container is initialized.
303
+ */
304
+ declare function isContainerInitialized(): boolean;
305
+ /**
306
+ * @deprecated Use container.getModels() instead.
307
+ * Get models from the default container.
308
+ */
309
+ declare function getModels(): ModelsContainer;
310
+ /**
311
+ * @deprecated Use container.getConfig() instead.
312
+ * Get config from the default container.
313
+ */
314
+ declare function getConfig(): HRMConfig;
315
+ /**
316
+ * @deprecated Use container.isSingleTenant() instead.
317
+ * Check if single-tenant mode.
318
+ */
319
+ declare function isSingleTenant(): boolean;
320
+
321
+ export { Container, type ContainerConfig, type Err, type ModelsContainer, type Ok, Result, ResultClass, all, err, flatMap, fromNullable, fromPromise, getConfig, getContainer, getModels, initializeContainer, isContainerInitialized, isErr, isOk, isSingleTenant, map, mapErr, match, ok, tryCatch, tryCatchSync, unwrap, unwrapOr, unwrapOrElse };