@classytic/payroll 1.0.2 → 2.0.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.

Potentially problematic release.


This version of @classytic/payroll might be problematic. Click here for more details.

Files changed (68) hide show
  1. package/README.md +168 -489
  2. package/dist/core/index.d.ts +480 -0
  3. package/dist/core/index.js +971 -0
  4. package/dist/core/index.js.map +1 -0
  5. package/dist/index-CTjHlCzz.d.ts +721 -0
  6. package/dist/index.d.ts +967 -0
  7. package/dist/index.js +4352 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/payroll.d.ts +233 -0
  10. package/dist/payroll.js +2103 -0
  11. package/dist/payroll.js.map +1 -0
  12. package/dist/plugin-D9mOr3_d.d.ts +333 -0
  13. package/dist/schemas/index.d.ts +2869 -0
  14. package/dist/schemas/index.js +440 -0
  15. package/dist/schemas/index.js.map +1 -0
  16. package/dist/services/index.d.ts +3 -0
  17. package/dist/services/index.js +1696 -0
  18. package/dist/services/index.js.map +1 -0
  19. package/dist/types-BSYyX2KJ.d.ts +671 -0
  20. package/dist/utils/index.d.ts +873 -0
  21. package/dist/utils/index.js +1046 -0
  22. package/dist/utils/index.js.map +1 -0
  23. package/package.json +54 -37
  24. package/dist/types/config.d.ts +0 -162
  25. package/dist/types/core/compensation.manager.d.ts +0 -54
  26. package/dist/types/core/employment.manager.d.ts +0 -49
  27. package/dist/types/core/payroll.manager.d.ts +0 -60
  28. package/dist/types/enums.d.ts +0 -117
  29. package/dist/types/factories/compensation.factory.d.ts +0 -196
  30. package/dist/types/factories/employee.factory.d.ts +0 -149
  31. package/dist/types/factories/payroll.factory.d.ts +0 -319
  32. package/dist/types/hrm.orchestrator.d.ts +0 -47
  33. package/dist/types/index.d.ts +0 -20
  34. package/dist/types/init.d.ts +0 -30
  35. package/dist/types/models/payroll-record.model.d.ts +0 -3
  36. package/dist/types/plugins/employee.plugin.d.ts +0 -2
  37. package/dist/types/schemas/employment.schema.d.ts +0 -959
  38. package/dist/types/services/compensation.service.d.ts +0 -94
  39. package/dist/types/services/employee.service.d.ts +0 -28
  40. package/dist/types/services/payroll.service.d.ts +0 -30
  41. package/dist/types/utils/calculation.utils.d.ts +0 -26
  42. package/dist/types/utils/date.utils.d.ts +0 -35
  43. package/dist/types/utils/logger.d.ts +0 -12
  44. package/dist/types/utils/query-builders.d.ts +0 -83
  45. package/dist/types/utils/validation.utils.d.ts +0 -33
  46. package/payroll.d.ts +0 -241
  47. package/src/config.js +0 -177
  48. package/src/core/compensation.manager.js +0 -242
  49. package/src/core/employment.manager.js +0 -224
  50. package/src/core/payroll.manager.js +0 -499
  51. package/src/enums.js +0 -141
  52. package/src/factories/compensation.factory.js +0 -198
  53. package/src/factories/employee.factory.js +0 -173
  54. package/src/factories/payroll.factory.js +0 -413
  55. package/src/hrm.orchestrator.js +0 -139
  56. package/src/index.js +0 -172
  57. package/src/init.js +0 -62
  58. package/src/models/payroll-record.model.js +0 -126
  59. package/src/plugins/employee.plugin.js +0 -164
  60. package/src/schemas/employment.schema.js +0 -126
  61. package/src/services/compensation.service.js +0 -231
  62. package/src/services/employee.service.js +0 -162
  63. package/src/services/payroll.service.js +0 -213
  64. package/src/utils/calculation.utils.js +0 -91
  65. package/src/utils/date.utils.js +0 -120
  66. package/src/utils/logger.js +0 -36
  67. package/src/utils/query-builders.js +0 -185
  68. package/src/utils/validation.utils.js +0 -122
@@ -0,0 +1,480 @@
1
+ export { C as CompensationChangedEventPayload, k as EmployeeHiredEventPayload, m as EmployeeRehiredEventPayload, l as EmployeeTerminatedEventPayload, E as EventBus, M as MilestoneAchievedEventPayload, N as NotificationPluginOptions, q as PayrollCompletedEventPayload, j as PayrollEventHandler, a as PayrollEventMap, i as PayrollEventType, s as PayrollExportedEventPayload, P as PayrollPluginDefinition, d as PluginContext, z as PluginHooks, y as PluginLogger, b as PluginManager, p as SalaryFailedEventPayload, n as SalaryProcessedEventPayload, S as SalaryUpdatedEventPayload, c as createEventBus, x as createNotificationPlugin, t as definePlugin, g as getEventBus, u as loggingPlugin, v as metricsPlugin, w as notificationPlugin, o as onEmployeeHired, h as onMilestoneAchieved, f as onPayrollCompleted, e as onSalaryProcessed, r as resetEventBus } from '../plugin-D9mOr3_d.js';
2
+ import { Model, ClientSession } from 'mongoose';
3
+ import { n as HRMConfig, S as SingleTenantConfig, o as Logger } from '../types-BSYyX2KJ.js';
4
+
5
+ /**
6
+ * @classytic/payroll - Result Type
7
+ *
8
+ * Rust-inspired Result type for type-safe error handling
9
+ * No more try/catch everywhere - explicit error handling
10
+ */
11
+ /** Success result */
12
+ interface Ok<T> {
13
+ readonly ok: true;
14
+ readonly value: T;
15
+ }
16
+ /** Error result */
17
+ interface Err<E> {
18
+ readonly ok: false;
19
+ readonly error: E;
20
+ }
21
+ /**
22
+ * Create a success result
23
+ */
24
+ declare function ok<T>(value: T): Ok<T>;
25
+ /**
26
+ * Create an error result
27
+ */
28
+ declare function err<E>(error: E): Err<E>;
29
+ /**
30
+ * Check if result is success
31
+ */
32
+ declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
33
+ /**
34
+ * Check if result is error
35
+ */
36
+ declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
37
+ /**
38
+ * Unwrap result value or throw error
39
+ */
40
+ declare function unwrap<T, E>(result: Result<T, E>): T;
41
+ /**
42
+ * Unwrap result value or return default
43
+ */
44
+ declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
45
+ /**
46
+ * Unwrap result value or compute default
47
+ */
48
+ declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
49
+ /**
50
+ * Map success value
51
+ */
52
+ declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
53
+ /**
54
+ * Map error value
55
+ */
56
+ declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
57
+ /**
58
+ * FlatMap (chain) success value
59
+ */
60
+ declare function flatMap<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
61
+ /**
62
+ * Try/catch wrapper for async functions
63
+ */
64
+ declare function tryCatch<T, E = Error>(fn: () => Promise<T>, errorTransform?: (error: unknown) => E): Promise<Result<T, E>>;
65
+ /**
66
+ * Try/catch wrapper for sync functions
67
+ */
68
+ declare function tryCatchSync<T, E = Error>(fn: () => T, errorTransform?: (error: unknown) => E): Result<T, E>;
69
+ /**
70
+ * Combine multiple results into one
71
+ */
72
+ declare function all<T, E>(results: Result<T, E>[]): Result<T[], E>;
73
+ /**
74
+ * Pattern match on result
75
+ */
76
+ declare function match<T, E, R>(result: Result<T, E>, handlers: {
77
+ ok: (value: T) => R;
78
+ err: (error: E) => R;
79
+ }): R;
80
+ /**
81
+ * Convert Promise<Result> to Result<Promise>
82
+ */
83
+ declare function fromPromise<T, E = Error>(promise: Promise<T>, errorTransform?: (error: unknown) => E): Promise<Result<T, E>>;
84
+ /**
85
+ * Create Result from nullable value
86
+ */
87
+ declare function fromNullable<T, E>(value: T | null | undefined, error: E): Result<T, E>;
88
+ declare class ResultClass<T, E = Error> {
89
+ private readonly result;
90
+ private constructor();
91
+ static ok<T>(value: T): ResultClass<T, never>;
92
+ static err<E>(error: E): ResultClass<never, E>;
93
+ static fromAsync<T, E = Error>(fn: () => Promise<T>, errorTransform?: (error: unknown) => E): Promise<ResultClass<T, E>>;
94
+ isOk(): boolean;
95
+ isErr(): boolean;
96
+ unwrap(): T;
97
+ unwrapOr(defaultValue: T): T;
98
+ map<U>(fn: (value: T) => U): ResultClass<U, E>;
99
+ mapErr<F>(fn: (error: E) => F): ResultClass<T, F>;
100
+ flatMap<U>(fn: (value: T) => Result<U, E>): ResultClass<U, E>;
101
+ match<R>(handlers: {
102
+ ok: (value: T) => R;
103
+ err: (error: E) => R;
104
+ }): R;
105
+ toResult(): Result<T, E>;
106
+ }
107
+ /** Result type - either success or error */
108
+ type Result<T, E = Error> = Ok<T> | Err<E>;
109
+ declare const Result: {
110
+ ok: typeof ok;
111
+ err: typeof err;
112
+ isOk: typeof isOk;
113
+ isErr: typeof isErr;
114
+ unwrap: typeof unwrap;
115
+ unwrapOr: typeof unwrapOr;
116
+ unwrapOrElse: typeof unwrapOrElse;
117
+ map: typeof map;
118
+ mapErr: typeof mapErr;
119
+ flatMap: typeof flatMap;
120
+ tryCatch: typeof tryCatch;
121
+ tryCatchSync: typeof tryCatchSync;
122
+ all: typeof all;
123
+ match: typeof match;
124
+ fromPromise: typeof fromPromise;
125
+ fromNullable: typeof fromNullable;
126
+ };
127
+
128
+ /**
129
+ * @classytic/payroll - Dependency Container
130
+ *
131
+ * Simple dependency injection container for service management
132
+ * Enables clean dependency injection and testing
133
+ */
134
+
135
+ interface ModelsContainer {
136
+ EmployeeModel: Model<any>;
137
+ PayrollRecordModel: Model<any>;
138
+ TransactionModel: Model<any>;
139
+ AttendanceModel?: Model<any> | null;
140
+ }
141
+ interface ContainerConfig {
142
+ models: ModelsContainer;
143
+ config?: Partial<HRMConfig>;
144
+ singleTenant?: SingleTenantConfig | null;
145
+ logger?: Logger;
146
+ }
147
+ declare class Container {
148
+ private static instance;
149
+ private _models;
150
+ private _config;
151
+ private _singleTenant;
152
+ private _logger;
153
+ private _initialized;
154
+ private constructor();
155
+ /**
156
+ * Get singleton instance
157
+ */
158
+ static getInstance(): Container;
159
+ /**
160
+ * Reset instance (for testing)
161
+ */
162
+ static resetInstance(): void;
163
+ /**
164
+ * Initialize container with configuration
165
+ */
166
+ initialize(config: ContainerConfig): void;
167
+ /**
168
+ * Check if container is initialized
169
+ */
170
+ isInitialized(): boolean;
171
+ /**
172
+ * Ensure container is initialized
173
+ */
174
+ private ensureInitialized;
175
+ /**
176
+ * Get models container
177
+ */
178
+ getModels(): ModelsContainer;
179
+ /**
180
+ * Get Employee model
181
+ */
182
+ getEmployeeModel(): Model<any>;
183
+ /**
184
+ * Get PayrollRecord model
185
+ */
186
+ getPayrollRecordModel(): Model<any>;
187
+ /**
188
+ * Get Transaction model
189
+ */
190
+ getTransactionModel(): Model<any>;
191
+ /**
192
+ * Get Attendance model (optional)
193
+ */
194
+ getAttendanceModel(): Model<any> | null;
195
+ /**
196
+ * Get configuration
197
+ */
198
+ getConfig(): HRMConfig;
199
+ /**
200
+ * Get specific config section
201
+ */
202
+ getConfigSection<K extends keyof HRMConfig>(section: K): HRMConfig[K];
203
+ /**
204
+ * Check if single-tenant mode
205
+ */
206
+ isSingleTenant(): boolean;
207
+ /**
208
+ * Get single-tenant config
209
+ */
210
+ getSingleTenantConfig(): SingleTenantConfig | null;
211
+ /**
212
+ * Get organization ID (for single-tenant mode)
213
+ */
214
+ getOrganizationId(): string | null;
215
+ /**
216
+ * Get logger
217
+ */
218
+ getLogger(): Logger;
219
+ /**
220
+ * Set logger
221
+ */
222
+ setLogger(logger: Logger): void;
223
+ /**
224
+ * Has attendance integration
225
+ */
226
+ hasAttendanceIntegration(): boolean;
227
+ /**
228
+ * Create operation context with defaults
229
+ */
230
+ createOperationContext(overrides?: Partial<{
231
+ userId: string;
232
+ userName: string;
233
+ userRole: string;
234
+ organizationId: string;
235
+ session: ClientSession;
236
+ }>): {
237
+ userId?: string;
238
+ userName?: string;
239
+ userRole?: string;
240
+ organizationId?: string;
241
+ session?: ClientSession;
242
+ };
243
+ }
244
+ /**
245
+ * Get container instance
246
+ */
247
+ declare function getContainer(): Container;
248
+ /**
249
+ * Initialize container
250
+ */
251
+ declare function initializeContainer(config: ContainerConfig): void;
252
+ /**
253
+ * Check if container is initialized
254
+ */
255
+ declare function isContainerInitialized(): boolean;
256
+ /**
257
+ * Get models from container
258
+ */
259
+ declare function getModels(): ModelsContainer;
260
+ /**
261
+ * Get config from container
262
+ */
263
+ declare function getConfig(): HRMConfig;
264
+ /**
265
+ * Check if single-tenant mode
266
+ */
267
+ declare function isSingleTenant(): boolean;
268
+
269
+ /**
270
+ * @classytic/payroll - Configuration & Calculation Utilities
271
+ *
272
+ * DESIGN PRINCIPLES:
273
+ * 1. Accept data, don't manage it
274
+ * 2. Pure functions - easy to test, no side effects
275
+ * 3. Smart defaults that work out of the box
276
+ * 4. Override at operation time when needed
277
+ *
278
+ * The payroll package CALCULATES, it doesn't STORE calendars/holidays.
279
+ * Your app manages that data and passes it when needed.
280
+ */
281
+ /** Work schedule configuration */
282
+ interface WorkSchedule {
283
+ /** Working days (0=Sun, 1=Mon, ..., 6=Sat). Default: Mon-Fri */
284
+ workDays: number[];
285
+ /** Hours per work day. Default: 8 */
286
+ hoursPerDay: number;
287
+ }
288
+ /** Options passed when processing payroll */
289
+ interface PayrollProcessingOptions {
290
+ /** Holidays in this period (from YOUR app's holiday model) */
291
+ holidays?: Date[];
292
+ /** Override work schedule for this operation */
293
+ workSchedule?: Partial<WorkSchedule>;
294
+ /** Skip tax calculation */
295
+ skipTax?: boolean;
296
+ /** Skip proration (pay full amount regardless of hire/termination date) */
297
+ skipProration?: boolean;
298
+ /** Skip attendance deduction */
299
+ skipAttendance?: boolean;
300
+ }
301
+ /** Working days calculation result */
302
+ interface WorkingDaysResult {
303
+ /** Total calendar days in period */
304
+ totalDays: number;
305
+ /** Working days (excluding weekends and holidays) */
306
+ workingDays: number;
307
+ /** Weekend days */
308
+ weekends: number;
309
+ /** Holiday count */
310
+ holidays: number;
311
+ }
312
+ /** Proration calculation result */
313
+ interface ProrationResult {
314
+ /** Proration ratio (0-1) */
315
+ ratio: number;
316
+ /** Reason for proration */
317
+ reason: 'full' | 'new_hire' | 'termination' | 'both';
318
+ /** Whether salary should be prorated */
319
+ isProrated: boolean;
320
+ }
321
+ /** Tax calculation result */
322
+ interface TaxResult {
323
+ /** Tax amount */
324
+ amount: number;
325
+ /** Effective tax rate */
326
+ effectiveRate: number;
327
+ }
328
+ /** Attendance data (from YOUR attendance system) */
329
+ interface AttendanceInput {
330
+ /** Expected work days in period */
331
+ expectedDays: number;
332
+ /** Actual days worked */
333
+ actualDays: number;
334
+ }
335
+ /** Complete salary calculation result */
336
+ interface SalaryCalculationResult {
337
+ /** Original base salary */
338
+ baseSalary: number;
339
+ /** Prorated base salary */
340
+ proratedBase: number;
341
+ /** Total allowances */
342
+ totalAllowances: number;
343
+ /** Total deductions (excluding tax) */
344
+ totalDeductions: number;
345
+ /** Attendance deduction */
346
+ attendanceDeduction: number;
347
+ /** Gross salary (prorated base + allowances) */
348
+ grossSalary: number;
349
+ /** Tax amount */
350
+ taxAmount: number;
351
+ /** Net salary (gross - all deductions - tax) */
352
+ netSalary: number;
353
+ /** Proration details */
354
+ proration: ProrationResult;
355
+ /** Working days details */
356
+ workingDays: WorkingDaysResult;
357
+ /** Itemized breakdown */
358
+ breakdown: {
359
+ allowances: Array<{
360
+ type: string;
361
+ amount: number;
362
+ taxable: boolean;
363
+ }>;
364
+ deductions: Array<{
365
+ type: string;
366
+ amount: number;
367
+ }>;
368
+ };
369
+ }
370
+ declare const COUNTRY_DEFAULTS: Record<string, {
371
+ currency: string;
372
+ workDays: number[];
373
+ taxBrackets: Array<{
374
+ min: number;
375
+ max: number;
376
+ rate: number;
377
+ }>;
378
+ }>;
379
+ declare const DEFAULT_WORK_SCHEDULE: WorkSchedule;
380
+ declare const DEFAULT_TAX_BRACKETS: {
381
+ min: number;
382
+ max: number;
383
+ rate: number;
384
+ }[];
385
+ /**
386
+ * Count working days in a date range
387
+ *
388
+ * @example
389
+ * const result = countWorkingDays(
390
+ * new Date('2024-03-01'),
391
+ * new Date('2024-03-31'),
392
+ * { workDays: [1,2,3,4,5], holidays: companyHolidays }
393
+ * );
394
+ */
395
+ declare function countWorkingDays(startDate: Date, endDate: Date, options?: {
396
+ workDays?: number[];
397
+ holidays?: Date[];
398
+ }): WorkingDaysResult;
399
+ /**
400
+ * Calculate proration ratio for partial months
401
+ *
402
+ * @example
403
+ * const proration = calculateProration(
404
+ * employee.hireDate,
405
+ * employee.terminationDate,
406
+ * periodStart,
407
+ * periodEnd
408
+ * );
409
+ */
410
+ declare function calculateProration(hireDate: Date, terminationDate: Date | null | undefined, periodStart: Date, periodEnd: Date): ProrationResult;
411
+ /**
412
+ * Calculate tax using brackets (annualized)
413
+ *
414
+ * @example
415
+ * const tax = calculateTax(monthlyIncome, 'USD');
416
+ */
417
+ declare function calculateTax(monthlyIncome: number, currency: string, customBrackets?: Array<{
418
+ min: number;
419
+ max: number;
420
+ rate: number;
421
+ }>): TaxResult;
422
+ /**
423
+ * Calculate attendance deduction
424
+ *
425
+ * @example
426
+ * const deduction = calculateAttendanceDeduction(22, 20, dailyRate);
427
+ */
428
+ declare function calculateAttendanceDeduction(expectedDays: number, actualDays: number, dailyRate: number, maxDeductionPercent?: number): number;
429
+ /**
430
+ * Calculate complete salary breakdown
431
+ *
432
+ * This is the main function for salary calculation.
433
+ * Pass all data from YOUR app, get back complete breakdown.
434
+ *
435
+ * @example
436
+ * const result = calculateSalaryBreakdown({
437
+ * baseSalary: 100000,
438
+ * currency: 'USD',
439
+ * hireDate: employee.hireDate,
440
+ * terminationDate: employee.terminationDate,
441
+ * periodStart: new Date('2024-03-01'),
442
+ * periodEnd: new Date('2024-03-31'),
443
+ * allowances: [{ type: 'housing', amount: 20000, taxable: true }],
444
+ * deductions: [{ type: 'provident_fund', amount: 5000 }],
445
+ * options: { holidays: companyHolidays },
446
+ * attendance: { expectedDays: 22, actualDays: 20 },
447
+ * });
448
+ */
449
+ declare function calculateSalaryBreakdown(params: {
450
+ baseSalary: number;
451
+ currency: string;
452
+ hireDate: Date;
453
+ terminationDate?: Date | null;
454
+ periodStart: Date;
455
+ periodEnd: Date;
456
+ allowances?: Array<{
457
+ type: string;
458
+ amount: number;
459
+ taxable?: boolean;
460
+ }>;
461
+ deductions?: Array<{
462
+ type: string;
463
+ amount: number;
464
+ }>;
465
+ options?: PayrollProcessingOptions;
466
+ attendance?: AttendanceInput;
467
+ }): SalaryCalculationResult;
468
+ /**
469
+ * Get pay period dates for a given month
470
+ *
471
+ * @example
472
+ * const period = getPayPeriod(3, 2024); // March 2024
473
+ */
474
+ declare function getPayPeriod(month: number, year: number, payDay?: number): {
475
+ startDate: Date;
476
+ endDate: Date;
477
+ payDate: Date;
478
+ };
479
+
480
+ export { type AttendanceInput, COUNTRY_DEFAULTS, Container, type ContainerConfig, DEFAULT_TAX_BRACKETS, DEFAULT_WORK_SCHEDULE, type Err, type ModelsContainer, type Ok, type PayrollProcessingOptions, type ProrationResult, Result, ResultClass, type SalaryCalculationResult, type TaxResult, type WorkSchedule, type WorkingDaysResult, all, calculateAttendanceDeduction, calculateProration, calculateSalaryBreakdown, calculateTax, countWorkingDays, err, flatMap, fromNullable, fromPromise, getConfig, getContainer, getModels, getPayPeriod, initializeContainer, isContainerInitialized, isErr, isOk, isSingleTenant, map, mapErr, match, ok, tryCatch, tryCatchSync, unwrap, unwrapOr, unwrapOrElse };