@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.
- package/README.md +333 -323
- package/dist/attendance.calculator-BZcv2iii.d.ts +336 -0
- package/dist/calculators/index.d.ts +3 -299
- package/dist/calculators/index.js +154 -19
- package/dist/calculators/index.js.map +1 -1
- package/dist/core/index.d.ts +321 -0
- package/dist/core/index.js +1962 -0
- package/dist/core/index.js.map +1 -0
- package/dist/{employee-identity-Cq2wo9-2.d.ts → error-helpers-Bm6lMny2.d.ts} +257 -7
- package/dist/{index-DjB72l6e.d.ts → index-BKLkuSAs.d.ts} +248 -132
- package/dist/index.d.ts +418 -658
- package/dist/index.js +1179 -373
- package/dist/index.js.map +1 -1
- package/dist/payroll-states-DBt0XVm-.d.ts +598 -0
- package/dist/{prorating.calculator-C7sdFiG2.d.ts → prorating.calculator-C33fWBQf.d.ts} +2 -2
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.js +95 -75
- package/dist/schemas/index.js.map +1 -1
- package/dist/{types-BVDjiVGS.d.ts → types-bZdAJueH.d.ts} +427 -12
- package/dist/utils/index.d.ts +17 -5
- package/dist/utils/index.js +185 -25
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -1
|
@@ -98,7 +98,8 @@ interface PayrollCompletedEventPayload {
|
|
|
98
98
|
}
|
|
99
99
|
interface PayrollExportedEventPayload {
|
|
100
100
|
organizationId: ObjectId;
|
|
101
|
-
|
|
101
|
+
exportId?: string;
|
|
102
|
+
dateRange?: {
|
|
102
103
|
start: Date;
|
|
103
104
|
end: Date;
|
|
104
105
|
};
|
|
@@ -233,6 +234,34 @@ declare class EventBus {
|
|
|
233
234
|
*/
|
|
234
235
|
eventNames(): PayrollEventType[];
|
|
235
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Get or create the default event bus
|
|
239
|
+
*/
|
|
240
|
+
declare function getEventBus(): EventBus;
|
|
241
|
+
/**
|
|
242
|
+
* Create a new event bus instance
|
|
243
|
+
*/
|
|
244
|
+
declare function createEventBus(): EventBus;
|
|
245
|
+
/**
|
|
246
|
+
* Reset the default event bus (for testing)
|
|
247
|
+
*/
|
|
248
|
+
declare function resetEventBus(): void;
|
|
249
|
+
/**
|
|
250
|
+
* Subscribe to employee hired events
|
|
251
|
+
*/
|
|
252
|
+
declare function onEmployeeHired(handler: PayrollEventHandler<'employee:hired'>): () => void;
|
|
253
|
+
/**
|
|
254
|
+
* Subscribe to salary processed events
|
|
255
|
+
*/
|
|
256
|
+
declare function onSalaryProcessed(handler: PayrollEventHandler<'salary:processed'>): () => void;
|
|
257
|
+
/**
|
|
258
|
+
* Subscribe to payroll completed events
|
|
259
|
+
*/
|
|
260
|
+
declare function onPayrollCompleted(handler: PayrollEventHandler<'payroll:completed'>): () => void;
|
|
261
|
+
/**
|
|
262
|
+
* Subscribe to milestone achieved events
|
|
263
|
+
*/
|
|
264
|
+
declare function onMilestoneAchieved(handler: PayrollEventHandler<'milestone:achieved'>): () => void;
|
|
236
265
|
|
|
237
266
|
/**
|
|
238
267
|
* Webhook System
|
|
@@ -247,6 +276,19 @@ interface WebhookConfig {
|
|
|
247
276
|
retries?: number;
|
|
248
277
|
timeout?: number;
|
|
249
278
|
}
|
|
279
|
+
interface WebhookManagerOptions {
|
|
280
|
+
/**
|
|
281
|
+
* Maximum number of delivery log entries to retain (default: 1000).
|
|
282
|
+
* Oldest entries are pruned when the limit is exceeded.
|
|
283
|
+
*/
|
|
284
|
+
maxLogSize?: number;
|
|
285
|
+
/**
|
|
286
|
+
* Whether to store full payloads in the delivery log (default: false).
|
|
287
|
+
* When false, only metadata (event, url, status, error, sentAt) is stored,
|
|
288
|
+
* preventing PII from accumulating in memory.
|
|
289
|
+
*/
|
|
290
|
+
storePayloads?: boolean;
|
|
291
|
+
}
|
|
250
292
|
interface WebhookDelivery {
|
|
251
293
|
id: string;
|
|
252
294
|
event: PayrollEventType;
|
|
@@ -264,6 +306,9 @@ interface WebhookDelivery {
|
|
|
264
306
|
declare class WebhookManager {
|
|
265
307
|
private webhooks;
|
|
266
308
|
private deliveryLog;
|
|
309
|
+
private readonly maxLogSize;
|
|
310
|
+
private readonly storePayloads;
|
|
311
|
+
constructor(options?: WebhookManagerOptions);
|
|
267
312
|
/**
|
|
268
313
|
* Register a webhook
|
|
269
314
|
*/
|
|
@@ -322,6 +367,11 @@ declare class WebhookManager {
|
|
|
322
367
|
* ```
|
|
323
368
|
*/
|
|
324
369
|
private generateSignature;
|
|
370
|
+
/**
|
|
371
|
+
* Prune delivery log to stay within maxLogSize.
|
|
372
|
+
* Removes oldest entries first.
|
|
373
|
+
*/
|
|
374
|
+
private pruneLog;
|
|
325
375
|
/**
|
|
326
376
|
* Sleep for ms
|
|
327
377
|
*/
|
|
@@ -376,6 +426,33 @@ interface PayrollProcessingOptions {
|
|
|
376
426
|
/** Skip attendance deduction */
|
|
377
427
|
skipAttendance?: boolean;
|
|
378
428
|
}
|
|
429
|
+
/** Working days calculation result */
|
|
430
|
+
interface WorkingDaysResult {
|
|
431
|
+
/** Total calendar days in period */
|
|
432
|
+
totalDays: number;
|
|
433
|
+
/** Working days (excluding weekends and holidays) */
|
|
434
|
+
workingDays: number;
|
|
435
|
+
/** Weekend days */
|
|
436
|
+
weekends: number;
|
|
437
|
+
/** Holiday count */
|
|
438
|
+
holidays: number;
|
|
439
|
+
}
|
|
440
|
+
/** Proration calculation result */
|
|
441
|
+
interface ProrationResult {
|
|
442
|
+
/** Proration ratio (0-1) */
|
|
443
|
+
ratio: number;
|
|
444
|
+
/**
|
|
445
|
+
* Reason for proration:
|
|
446
|
+
* - 'full': Employee worked the entire period (ratio = 1)
|
|
447
|
+
* - 'new_hire': Employee was hired during the period
|
|
448
|
+
* - 'termination': Employee was terminated during the period
|
|
449
|
+
* - 'both': Both hired and terminated within the period
|
|
450
|
+
* - 'not_active': Employee was not active at all during the period (ratio = 0)
|
|
451
|
+
*/
|
|
452
|
+
reason: 'full' | 'new_hire' | 'termination' | 'both' | 'not_active';
|
|
453
|
+
/** Whether salary should be prorated */
|
|
454
|
+
isProrated: boolean;
|
|
455
|
+
}
|
|
379
456
|
/** Attendance data (from YOUR attendance system) */
|
|
380
457
|
interface AttendanceInput {
|
|
381
458
|
/**
|
|
@@ -386,6 +463,44 @@ interface AttendanceInput {
|
|
|
386
463
|
/** Actual days worked */
|
|
387
464
|
actualDays: number;
|
|
388
465
|
}
|
|
466
|
+
declare const DEFAULT_WORK_SCHEDULE: WorkSchedule$1;
|
|
467
|
+
/**
|
|
468
|
+
* Count working days in a date range
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* const result = countWorkingDays(
|
|
472
|
+
* new Date('2024-03-01'),
|
|
473
|
+
* new Date('2024-03-31'),
|
|
474
|
+
* { workingDays: [1,2,3,4,5], holidays: companyHolidays }
|
|
475
|
+
* );
|
|
476
|
+
*/
|
|
477
|
+
declare function countWorkingDays(startDate: Date, endDate: Date, options?: {
|
|
478
|
+
workingDays?: number[];
|
|
479
|
+
holidays?: Date[];
|
|
480
|
+
}): WorkingDaysResult;
|
|
481
|
+
/**
|
|
482
|
+
* Calculate proration ratio for partial months
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const proration = calculateProration(
|
|
486
|
+
* employee.hireDate,
|
|
487
|
+
* employee.terminationDate,
|
|
488
|
+
* periodStart,
|
|
489
|
+
* periodEnd
|
|
490
|
+
* );
|
|
491
|
+
*/
|
|
492
|
+
declare function calculateProration(hireDate: Date, terminationDate: Date | null | undefined, periodStart: Date, periodEnd: Date): ProrationResult;
|
|
493
|
+
/**
|
|
494
|
+
* Get pay period dates for a given month
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* const period = getPayPeriod(3, 2024); // March 2024
|
|
498
|
+
*/
|
|
499
|
+
declare function getPayPeriod(month: number, year: number, payDay?: number): {
|
|
500
|
+
startDate: Date;
|
|
501
|
+
endDate: Date;
|
|
502
|
+
payDate: Date;
|
|
503
|
+
};
|
|
389
504
|
|
|
390
505
|
/**
|
|
391
506
|
* @classytic/payroll - Plugin System
|
|
@@ -435,6 +550,77 @@ interface PayrollPluginDefinition {
|
|
|
435
550
|
init?: (context: PluginContext) => void | Promise<void>;
|
|
436
551
|
destroy?: () => void | Promise<void>;
|
|
437
552
|
}
|
|
553
|
+
declare class PluginManager {
|
|
554
|
+
private context;
|
|
555
|
+
private plugins;
|
|
556
|
+
private hooks;
|
|
557
|
+
constructor(context: PluginContext);
|
|
558
|
+
/**
|
|
559
|
+
* Register a plugin
|
|
560
|
+
*/
|
|
561
|
+
register(plugin: PayrollPluginDefinition): Promise<void>;
|
|
562
|
+
/**
|
|
563
|
+
* Unregister a plugin
|
|
564
|
+
*/
|
|
565
|
+
unregister(name: string): Promise<void>;
|
|
566
|
+
/**
|
|
567
|
+
* Add a hook handler
|
|
568
|
+
*/
|
|
569
|
+
private addHook;
|
|
570
|
+
/**
|
|
571
|
+
* Execute hooks for a given event
|
|
572
|
+
*/
|
|
573
|
+
executeHooks<K extends keyof PluginHooks>(hookName: K, ...args: Parameters<NonNullable<PluginHooks[K]>>): Promise<void>;
|
|
574
|
+
/**
|
|
575
|
+
* Get registered plugin names
|
|
576
|
+
*/
|
|
577
|
+
getPluginNames(): string[];
|
|
578
|
+
/**
|
|
579
|
+
* Check if plugin is registered
|
|
580
|
+
*/
|
|
581
|
+
hasPlugin(name: string): boolean;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Define a plugin with type safety
|
|
585
|
+
*/
|
|
586
|
+
declare function definePlugin(definition: PayrollPluginDefinition): PayrollPluginDefinition;
|
|
587
|
+
/**
|
|
588
|
+
* Logging plugin - logs all payroll events
|
|
589
|
+
*/
|
|
590
|
+
declare const loggingPlugin: PayrollPluginDefinition;
|
|
591
|
+
/**
|
|
592
|
+
* Metrics plugin - collects payroll metrics
|
|
593
|
+
*/
|
|
594
|
+
declare const metricsPlugin: PayrollPluginDefinition;
|
|
595
|
+
/**
|
|
596
|
+
* Notification plugin - sends notifications for events
|
|
597
|
+
*/
|
|
598
|
+
interface NotificationPluginOptions {
|
|
599
|
+
onHired?: (employee: {
|
|
600
|
+
id: unknown;
|
|
601
|
+
name?: string;
|
|
602
|
+
}) => void | Promise<void>;
|
|
603
|
+
onTerminated?: (employee: {
|
|
604
|
+
id: unknown;
|
|
605
|
+
name?: string;
|
|
606
|
+
}) => void | Promise<void>;
|
|
607
|
+
onSalaryProcessed?: (details: {
|
|
608
|
+
employee: {
|
|
609
|
+
id: unknown;
|
|
610
|
+
name?: string;
|
|
611
|
+
};
|
|
612
|
+
amount: number;
|
|
613
|
+
}) => void | Promise<void>;
|
|
614
|
+
onMilestone?: (details: {
|
|
615
|
+
employee: {
|
|
616
|
+
id: unknown;
|
|
617
|
+
name?: string;
|
|
618
|
+
};
|
|
619
|
+
milestone: string;
|
|
620
|
+
}) => void | Promise<void>;
|
|
621
|
+
}
|
|
622
|
+
declare function createNotificationPlugin(options: NotificationPluginOptions): PayrollPluginDefinition;
|
|
623
|
+
declare const notificationPlugin: PayrollPluginDefinition;
|
|
438
624
|
|
|
439
625
|
/** Query filter type */
|
|
440
626
|
type FilterQuery<T> = {
|
|
@@ -549,7 +735,12 @@ interface ValidationConfig {
|
|
|
549
735
|
/** Fallback modes if primary lookup fails */
|
|
550
736
|
identityFallbacks: EmployeeIdentityMode[];
|
|
551
737
|
}
|
|
552
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Tax bracket definition.
|
|
740
|
+
*
|
|
741
|
+
* Tax brackets should be managed by your application and passed at calculation time.
|
|
742
|
+
* Use `effectiveFrom`/`effectiveTo` to version brackets when tax rates change.
|
|
743
|
+
*/
|
|
553
744
|
interface TaxBracket {
|
|
554
745
|
/** Minimum income for bracket */
|
|
555
746
|
min: number;
|
|
@@ -557,6 +748,128 @@ interface TaxBracket {
|
|
|
557
748
|
max: number;
|
|
558
749
|
/** Tax rate (0-1) */
|
|
559
750
|
rate: number;
|
|
751
|
+
/** Start date from which this bracket applies (inclusive) */
|
|
752
|
+
effectiveFrom?: Date;
|
|
753
|
+
/** End date until which this bracket applies (inclusive, null = still active) */
|
|
754
|
+
effectiveTo?: Date | null;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Pre-tax deduction input for tax calculation
|
|
758
|
+
*
|
|
759
|
+
* Deductions that reduce taxable income before tax brackets are applied.
|
|
760
|
+
* Common examples: pension, provident fund, 401k, health savings.
|
|
761
|
+
*/
|
|
762
|
+
interface PreTaxDeductionInput {
|
|
763
|
+
/** Deduction type identifier */
|
|
764
|
+
type: string;
|
|
765
|
+
/** Deduction amount */
|
|
766
|
+
amount: number;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Tax credit/rebate input
|
|
770
|
+
*
|
|
771
|
+
* Credits that reduce tax liability after tax calculation.
|
|
772
|
+
* Different from deductions which reduce taxable income.
|
|
773
|
+
*/
|
|
774
|
+
interface TaxCreditInput {
|
|
775
|
+
/** Credit type identifier (e.g., 'investment', 'charitable', 'education') */
|
|
776
|
+
type: string;
|
|
777
|
+
/** Credit amount */
|
|
778
|
+
amount: number;
|
|
779
|
+
/** Maximum as percentage of tax liability (0-1). If set, credit is capped. */
|
|
780
|
+
maxPercent?: number;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Enhanced tax calculation options
|
|
784
|
+
*
|
|
785
|
+
* Provides jurisdiction-aware tax calculation with support for:
|
|
786
|
+
* - Standard deduction / tax-free threshold
|
|
787
|
+
* - Demographic-based thresholds (senior, disabled, etc.)
|
|
788
|
+
* - Pre-tax deductions (pension, 401k)
|
|
789
|
+
* - Tax credits/rebates
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* const taxOptions: TaxCalculationOptions = {
|
|
794
|
+
* applyStandardDeduction: true,
|
|
795
|
+
* taxpayerCategory: 'senior',
|
|
796
|
+
* preTaxDeductions: [
|
|
797
|
+
* { type: 'provident_fund', amount: 5000 },
|
|
798
|
+
* { type: 'pension', amount: 3000 },
|
|
799
|
+
* ],
|
|
800
|
+
* taxCredits: [
|
|
801
|
+
* { type: 'investment', amount: 2000, maxPercent: 0.15 },
|
|
802
|
+
* ],
|
|
803
|
+
* };
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
interface TaxCalculationOptions {
|
|
807
|
+
/**
|
|
808
|
+
* Apply standard deduction from jurisdiction config
|
|
809
|
+
*
|
|
810
|
+
* When true, subtracts TaxConfiguration.standardDeduction from
|
|
811
|
+
* taxable income before applying tax brackets.
|
|
812
|
+
*
|
|
813
|
+
* @default false
|
|
814
|
+
*/
|
|
815
|
+
applyStandardDeduction?: boolean;
|
|
816
|
+
/**
|
|
817
|
+
* Taxpayer category for threshold lookup
|
|
818
|
+
*
|
|
819
|
+
* Used to look up the appropriate tax-free threshold from
|
|
820
|
+
* TaxConfiguration.thresholdsByCategory. If not found,
|
|
821
|
+
* falls back to standardDeduction.
|
|
822
|
+
*
|
|
823
|
+
* Common categories: 'standard', 'senior', 'disabled', 'veteran', 'female'
|
|
824
|
+
*
|
|
825
|
+
* @example 'senior' - for taxpayers 65+
|
|
826
|
+
*/
|
|
827
|
+
taxpayerCategory?: string;
|
|
828
|
+
/**
|
|
829
|
+
* Override thresholds by category
|
|
830
|
+
*
|
|
831
|
+
* Allows runtime override of jurisdiction thresholds.
|
|
832
|
+
* Useful for custom/organization-specific rules.
|
|
833
|
+
*
|
|
834
|
+
* @example { senior: 500000, disabled: 550000 }
|
|
835
|
+
*/
|
|
836
|
+
thresholdOverrides?: Record<string, number>;
|
|
837
|
+
/**
|
|
838
|
+
* Pre-tax deductions (reduce taxable income)
|
|
839
|
+
*
|
|
840
|
+
* These deductions are subtracted from gross income before
|
|
841
|
+
* tax brackets are applied. Common examples:
|
|
842
|
+
* - Pension/401k contributions
|
|
843
|
+
* - Health savings account (HSA)
|
|
844
|
+
* - Provident fund
|
|
845
|
+
*
|
|
846
|
+
* Note: Employee's compensation.deductions with reducesTaxableIncome=true
|
|
847
|
+
* are automatically included. Use this for additional one-time deductions.
|
|
848
|
+
*/
|
|
849
|
+
preTaxDeductions?: PreTaxDeductionInput[];
|
|
850
|
+
/**
|
|
851
|
+
* Tax credits/rebates (reduce tax liability)
|
|
852
|
+
*
|
|
853
|
+
* Applied after tax calculation. Different from deductions:
|
|
854
|
+
* - Deduction: reduces taxable income
|
|
855
|
+
* - Credit: reduces calculated tax amount
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* taxCredits: [
|
|
860
|
+
* { type: 'investment', amount: 15000, maxPercent: 0.15 }, // Max 15% of tax
|
|
861
|
+
* { type: 'charitable', amount: 5000 }, // Full credit
|
|
862
|
+
* ]
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
865
|
+
taxCredits?: TaxCreditInput[];
|
|
866
|
+
/**
|
|
867
|
+
* Standard deduction amount (annual)
|
|
868
|
+
*
|
|
869
|
+
* Direct override for standard deduction. Takes precedence over
|
|
870
|
+
* jurisdiction config when provided.
|
|
871
|
+
*/
|
|
872
|
+
standardDeductionOverride?: number;
|
|
560
873
|
}
|
|
561
874
|
/** Salary band range */
|
|
562
875
|
interface SalaryBandRange {
|
|
@@ -657,6 +970,25 @@ interface Deduction {
|
|
|
657
970
|
effectiveFrom?: Date;
|
|
658
971
|
effectiveTo?: Date | null;
|
|
659
972
|
description?: string;
|
|
973
|
+
/**
|
|
974
|
+
* Whether this deduction reduces taxable income (pre-tax deduction)
|
|
975
|
+
*
|
|
976
|
+
* When true, this deduction is subtracted from gross income before
|
|
977
|
+
* tax calculation. Common examples: pension contributions, 401k,
|
|
978
|
+
* provident fund, health savings account (HSA).
|
|
979
|
+
*
|
|
980
|
+
* @default false (post-tax deduction)
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* ```typescript
|
|
984
|
+
* // Provident fund contribution reduces taxable income
|
|
985
|
+
* { type: 'provident_fund', amount: 5000, reducesTaxableIncome: true }
|
|
986
|
+
*
|
|
987
|
+
* // Loan repayment does NOT reduce taxable income
|
|
988
|
+
* { type: 'loan', amount: 2000, reducesTaxableIncome: false }
|
|
989
|
+
* ```
|
|
990
|
+
*/
|
|
991
|
+
reducesTaxableIncome?: boolean;
|
|
660
992
|
}
|
|
661
993
|
/** Compensation structure */
|
|
662
994
|
interface Compensation {
|
|
@@ -816,6 +1148,11 @@ interface PayrollRecordDocument extends Document {
|
|
|
816
1148
|
* Default: 'regular'
|
|
817
1149
|
*/
|
|
818
1150
|
payrollRunType?: PayrollRunType;
|
|
1151
|
+
/**
|
|
1152
|
+
* Payment frequency at time of processing (v2.9.0+)
|
|
1153
|
+
* Stored for proper idempotency key reconstruction in void/reverse operations
|
|
1154
|
+
*/
|
|
1155
|
+
paymentFrequency?: PaymentFrequency;
|
|
819
1156
|
/**
|
|
820
1157
|
* Retroactive adjustment details (for back-pay or corrections)
|
|
821
1158
|
* Only populated when payrollRunType is 'retroactive'
|
|
@@ -859,6 +1196,14 @@ interface PayrollRecordDocument extends Document {
|
|
|
859
1196
|
* expireAt: undefined
|
|
860
1197
|
*/
|
|
861
1198
|
expireAt?: Date | null;
|
|
1199
|
+
addCorrection(previousAmount: number, newAmount: number, reason: string, correctedBy: ObjectId): void;
|
|
1200
|
+
markAsPaid(transactionId: ObjectId, paidAt?: Date): void;
|
|
1201
|
+
getBreakdownSummary(): {
|
|
1202
|
+
gross: number;
|
|
1203
|
+
net: number;
|
|
1204
|
+
tax: number;
|
|
1205
|
+
deductions: number;
|
|
1206
|
+
};
|
|
862
1207
|
save(options?: {
|
|
863
1208
|
session?: ClientSession;
|
|
864
1209
|
}): Promise<this>;
|
|
@@ -1194,7 +1539,7 @@ interface ProcessSalaryParams extends EmployeeOperationParams {
|
|
|
1194
1539
|
/**
|
|
1195
1540
|
* Idempotency key (Stripe-style)
|
|
1196
1541
|
* If provided, duplicate calls with same key return cached result
|
|
1197
|
-
* Auto-generated if not provided: `payroll:{orgId}:{empId}:{year}-{month}`
|
|
1542
|
+
* Auto-generated if not provided: `payroll:{orgId}:{empId}:{year}-{month}:{payrollRunType}`
|
|
1198
1543
|
*/
|
|
1199
1544
|
idempotencyKey?: string;
|
|
1200
1545
|
/**
|
|
@@ -1225,8 +1570,12 @@ interface BulkPayrollProgress {
|
|
|
1225
1570
|
}
|
|
1226
1571
|
/** Process bulk payroll parameters */
|
|
1227
1572
|
interface ProcessBulkPayrollParams {
|
|
1228
|
-
/**
|
|
1229
|
-
|
|
1573
|
+
/**
|
|
1574
|
+
* Organization ID (required in multi-tenant mode).
|
|
1575
|
+
* Can also be provided via context.organizationId as fallback.
|
|
1576
|
+
* In single-tenant mode with autoInject, this is optional.
|
|
1577
|
+
*/
|
|
1578
|
+
organizationId?: ObjectIdLike;
|
|
1230
1579
|
/** Month (1-12) */
|
|
1231
1580
|
month: number;
|
|
1232
1581
|
/** Year */
|
|
@@ -1285,6 +1634,19 @@ interface ProcessBulkPayrollParams {
|
|
|
1285
1634
|
* - undefined/auto: Automatically use streaming for >10k employees
|
|
1286
1635
|
*/
|
|
1287
1636
|
useStreaming?: boolean;
|
|
1637
|
+
/**
|
|
1638
|
+
* Maximum number of individual result entries to keep in successful/failed arrays.
|
|
1639
|
+
* When exceeded, new results are counted but not stored in the arrays.
|
|
1640
|
+
* Use `successCount`/`failCount` on the result for accurate totals regardless of this limit.
|
|
1641
|
+
*
|
|
1642
|
+
* - undefined/Infinity: Store all results (default, backward compatible)
|
|
1643
|
+
* - 0: Summary only - no individual results, just counts
|
|
1644
|
+
* - N: Store up to N results per array
|
|
1645
|
+
*
|
|
1646
|
+
* Recommended for streaming mode with large datasets to prevent OOM.
|
|
1647
|
+
* @default Infinity
|
|
1648
|
+
*/
|
|
1649
|
+
maxResultDetails?: number;
|
|
1288
1650
|
}
|
|
1289
1651
|
/** Payroll history parameters */
|
|
1290
1652
|
interface PayrollHistoryParams {
|
|
@@ -1316,7 +1678,14 @@ interface PayrollSummaryParams {
|
|
|
1316
1678
|
/** Year */
|
|
1317
1679
|
year?: number;
|
|
1318
1680
|
}
|
|
1319
|
-
/**
|
|
1681
|
+
/**
|
|
1682
|
+
* Export payroll parameters
|
|
1683
|
+
*
|
|
1684
|
+
* Used with the two-phase export flow (v2.8.0+):
|
|
1685
|
+
* - `prepareExport(params)` - Gets records without marking, returns exportId
|
|
1686
|
+
* - `confirmExport({ exportId })` - Marks records after downstream confirms
|
|
1687
|
+
* - `cancelExport({ exportId })` - Cancels if downstream fails
|
|
1688
|
+
*/
|
|
1320
1689
|
interface ExportPayrollParams {
|
|
1321
1690
|
/** Organization ID */
|
|
1322
1691
|
organizationId: ObjectIdLike;
|
|
@@ -1444,6 +1813,21 @@ interface BulkPayrollResult {
|
|
|
1444
1813
|
error: string;
|
|
1445
1814
|
}>;
|
|
1446
1815
|
total: number;
|
|
1816
|
+
/**
|
|
1817
|
+
* Accurate count of successful operations, regardless of maxResultDetails.
|
|
1818
|
+
* Always reflects the true number of successes even when `successful` array is capped.
|
|
1819
|
+
*/
|
|
1820
|
+
successCount: number;
|
|
1821
|
+
/**
|
|
1822
|
+
* Accurate count of failed operations, regardless of maxResultDetails.
|
|
1823
|
+
* Always reflects the true number of failures even when `failed` array is capped.
|
|
1824
|
+
*/
|
|
1825
|
+
failCount: number;
|
|
1826
|
+
/**
|
|
1827
|
+
* Running total of all successful payment amounts, regardless of maxResultDetails.
|
|
1828
|
+
* Always reflects the true sum even when `successful` array is capped.
|
|
1829
|
+
*/
|
|
1830
|
+
totalAmount: number;
|
|
1447
1831
|
}
|
|
1448
1832
|
/** Payroll summary result */
|
|
1449
1833
|
interface PayrollSummaryResult {
|
|
@@ -1508,7 +1892,40 @@ interface PayrollInstance<TEmployee extends EmployeeDocument = EmployeeDocument,
|
|
|
1508
1892
|
processBulkPayroll(params: ProcessBulkPayrollParams): Promise<BulkPayrollResult>;
|
|
1509
1893
|
payrollHistory(params: PayrollHistoryParams): Promise<TPayrollRecord[]>;
|
|
1510
1894
|
payrollSummary(params: PayrollSummaryParams): Promise<PayrollSummaryResult>;
|
|
1511
|
-
|
|
1895
|
+
/**
|
|
1896
|
+
* Prepare payroll data for export (Phase 1)
|
|
1897
|
+
*
|
|
1898
|
+
* Retrieves records but does NOT mark them as exported yet.
|
|
1899
|
+
* Returns an exportId that must be used to confirm or cancel.
|
|
1900
|
+
*/
|
|
1901
|
+
prepareExport(params: ExportPayrollParams): Promise<{
|
|
1902
|
+
records: TPayrollRecord[];
|
|
1903
|
+
exportId: string;
|
|
1904
|
+
total: number;
|
|
1905
|
+
}>;
|
|
1906
|
+
/**
|
|
1907
|
+
* Confirm export success (Phase 2a)
|
|
1908
|
+
*
|
|
1909
|
+
* Marks records as exported after downstream confirms receipt.
|
|
1910
|
+
*/
|
|
1911
|
+
confirmExport(params: {
|
|
1912
|
+
organizationId: ObjectIdLike;
|
|
1913
|
+
exportId: string;
|
|
1914
|
+
}): Promise<{
|
|
1915
|
+
confirmed: number;
|
|
1916
|
+
}>;
|
|
1917
|
+
/**
|
|
1918
|
+
* Cancel export (Phase 2b)
|
|
1919
|
+
*
|
|
1920
|
+
* Called when downstream fails. Records remain unmarked.
|
|
1921
|
+
*/
|
|
1922
|
+
cancelExport(params: {
|
|
1923
|
+
organizationId: ObjectIdLike;
|
|
1924
|
+
exportId: string;
|
|
1925
|
+
reason?: string;
|
|
1926
|
+
}): Promise<{
|
|
1927
|
+
cancelled: boolean;
|
|
1928
|
+
}>;
|
|
1512
1929
|
/**
|
|
1513
1930
|
* Void a payroll record (before payment)
|
|
1514
1931
|
*
|
|
@@ -1529,11 +1946,9 @@ interface PayrollInstance<TEmployee extends EmployeeDocument = EmployeeDocument,
|
|
|
1529
1946
|
* Only works for voided payrolls (not reversed)
|
|
1530
1947
|
*/
|
|
1531
1948
|
restorePayroll(params: RestorePayrollParams): Promise<RestorePayrollResult>;
|
|
1532
|
-
/** Extended properties from plugins */
|
|
1533
|
-
[key: string]: unknown;
|
|
1534
1949
|
}
|
|
1535
1950
|
/**
|
|
1536
|
-
* @deprecated Use `PayrollPluginDefinition` from `@classytic/payroll/core`.
|
|
1951
|
+
* @deprecated Use `PayrollPluginDefinition` from `@classytic/payroll` or `@classytic/payroll/core`.
|
|
1537
1952
|
* This legacy plugin shape is kept for compatibility with older code.
|
|
1538
1953
|
*/
|
|
1539
1954
|
interface PayrollPlugin {
|
|
@@ -1596,7 +2011,7 @@ interface Logger {
|
|
|
1596
2011
|
debug(message: string, meta?: Record<string, unknown>): void;
|
|
1597
2012
|
}
|
|
1598
2013
|
/** Error codes */
|
|
1599
|
-
type ErrorCode = 'PAYROLL_ERROR' | 'NOT_INITIALIZED' | 'EMPLOYEE_NOT_FOUND' | 'INVALID_EMPLOYEE' | 'DUPLICATE_PAYROLL' | 'VALIDATION_ERROR' | 'EMPLOYEE_TERMINATED' | 'ALREADY_PROCESSED' | 'NOT_ELIGIBLE' | 'SECURITY_ERROR';
|
|
2014
|
+
type ErrorCode = 'PAYROLL_ERROR' | 'NOT_INITIALIZED' | 'EMPLOYEE_NOT_FOUND' | 'INVALID_EMPLOYEE' | 'DUPLICATE_PAYROLL' | 'VOIDED_PAYROLL_REPROCESS' | 'VALIDATION_ERROR' | 'EMPLOYEE_TERMINATED' | 'ALREADY_PROCESSED' | 'NOT_ELIGIBLE' | 'SECURITY_ERROR' | 'EXPORT_NOT_FOUND' | 'EXPORT_ORG_MISMATCH';
|
|
1600
2015
|
/** HTTP error with status code */
|
|
1601
2016
|
interface HttpError extends Error {
|
|
1602
2017
|
code: ErrorCode;
|
|
@@ -1853,4 +2268,4 @@ interface MarkTaxPaidParams {
|
|
|
1853
2268
|
context?: OperationContext;
|
|
1854
2269
|
}
|
|
1855
2270
|
|
|
1856
|
-
export { type
|
|
2271
|
+
export { type TaxBracket as $, type AnyDocument as A, countWorkingDays as B, type CompensationChangedEventPayload as C, DEFAULT_WORK_SCHEDULE as D, type EmployeeDocument as E, createEventBus as F, createNotificationPlugin as G, type HRMConfig as H, definePlugin as I, getEventBus as J, getPayPeriod as K, type LeaveRequestDocument as L, type MilestoneAchievedEventPayload as M, type NotificationPluginOptions as N, loggingPlugin as O, type PayrollRecordDocument as P, metricsPlugin as Q, notificationPlugin as R, type SingleTenantConfig as S, type TaxWithholdingDocument as T, onEmployeeHired as U, onMilestoneAchieved as V, type WebhookConfig as W, onPayrollCompleted as X, onSalaryProcessed as Y, resetEventBus as Z, type Compensation as _, type Logger as a, type AllowanceType as a$, type TaxCalculationOptions as a0, type PayrollBreakdown as a1, type ObjectIdLike as a2, type ObjectId as a3, type TaxType as a4, type TaxStatus as a5, type LeaveRequestStatus as a6, type LeaveType as a7, type PayPeriodInfo as a8, type Allowance as a9, type AddDeductionParams as aA, type RemoveDeductionParams as aB, type UpdateBankDetailsParams as aC, type ProcessSalaryParams as aD, type ProcessSalaryResult as aE, type ProcessBulkPayrollParams as aF, type BulkPayrollResult as aG, type PayrollHistoryParams as aH, type PayrollSummaryParams as aI, type PayrollSummaryResult as aJ, type VoidPayrollParams as aK, type VoidPayrollResult as aL, type ReversePayrollParams as aM, type ReversePayrollResult as aN, type RestorePayrollParams as aO, type RestorePayrollResult as aP, type GetPendingTaxParams as aQ, type TaxSummaryParams as aR, type TaxSummaryResult as aS, type MarkTaxPaidParams as aT, type ExportPayrollParams as aU, type DeepPartial as aV, type OrgRole as aW, type WorkSchedule as aX, type PaymentFrequency as aY, type TerminationReason as aZ, type AccrueLeaveOptions as a_, type CompensationBreakdownResult as aa, type Deduction as ab, type TaxCalculationResult as ac, type EmployeeStatus as ad, type EmployeeValidationResult as ae, type BankDetails as af, type EmploymentType as ag, type Department as ah, type PayrollStatus as ai, type HttpError as aj, type ErrorCode as ak, type LeaveBalance as al, type WorkingDaysOptions as am, type LeaveSummaryResult as an, type LeaveInitConfig as ao, type OperationContext as ap, type PayrollInstance as aq, type PayrollInitConfig as ar, type HireEmployeeParams as as, type UpdateEmploymentParams as at, type TerminateEmployeeParams as au, type ReHireEmployeeParams as av, type EmployeeIdentityMode as aw, type UpdateSalaryParams as ax, type AddAllowanceParams as ay, type RemoveAllowanceParams as az, type AttendanceInput as b, type AnyModel as b0, type BulkPayrollProgress as b1, type DataRetentionConfig as b2, type DeductionType as b3, type EmployeeHiredEvent as b4, type EmployeeIdMode as b5, type EmployeeOperationParams as b6, type EmploymentConfig as b7, type EmploymentHistoryEntry as b8, type EventPayload as b9, type TaxCreditInput as bA, type TaxSummaryByType as bB, type UserReference as bC, type ValidationConfig as bD, type WithPayroll as bE, type EventPayloadBase as ba, type FilterQuery as bb, type GetEmployeeParams as bc, type HRMTransactionCategory as bd, type LeaveHistoryFilters as be, type Nullable as bf, type PaymentMethod as bg, type PayrollConfig as bh, type PayrollCorrection as bi, type PayrollEmployee as bj, type PayrollEvent as bk, type PayrollPeriod as bl, type PayrollPlugin as bm, type PayrollStats as bn, type PluginFunction as bo, type PluginType as bp, type PreTaxDeductionInput as bq, type QueryOptions as br, type RequestLeaveInput as bs, type ResetAnnualLeaveOptions as bt, type ReviewLeaveRequestInput as bu, type RoleMappingConfig as bv, type SalaryBand as bw, type SalaryBandRange as bx, type SalaryConfig as by, type SalaryProcessedEvent as bz, type EmployeeHiredEventPayload as c, type EmployeeRehiredEventPayload as d, type EmployeeTerminatedEventPayload as e, EventBus as f, type PayrollCompletedEventPayload as g, type PayrollEventHandler as h, type PayrollEventMap as i, type PayrollEventType as j, type PayrollExportedEventPayload as k, type PayrollPluginDefinition as l, type PayrollProcessingOptions as m, type PluginContext as n, type PluginHooks as o, type PluginLogger as p, PluginManager as q, type ProrationResult as r, type SalaryFailedEventPayload as s, type SalaryProcessedEventPayload as t, type SalaryUpdatedEventPayload as u, type WebhookDelivery as v, WebhookManager as w, type WorkSchedule$1 as x, type WorkingDaysResult as y, calculateProration as z };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { a as Logger, a8 as PayPeriodInfo, a9 as Allowance, _ as Compensation, aa as CompensationBreakdownResult, ab as Deduction, ac as TaxCalculationResult, ad as EmployeeStatus, ae as EmployeeValidationResult, af as BankDetails, ag as EmploymentType, a2 as ObjectIdLike, ah as Department, ai as PayrollStatus } from '../types-bZdAJueH.js';
|
|
2
|
+
export { b as applyProRating, c as calculateProRating } from '../prorating.calculator-C33fWBQf.js';
|
|
3
3
|
import { Types } from 'mongoose';
|
|
4
|
-
export { C as ContainerLike, D as DEFAULT_CARRY_OVER, a as DEFAULT_LEAVE_ALLOCATIONS, E as EmployeeIdMode,
|
|
4
|
+
export { C as ContainerLike, D as DEFAULT_CARRY_OVER, a as DEFAULT_LEAVE_ALLOCATIONS, b as DuplicateKeyErrorResult, E as EmployeeIdMode, c as EmployeeIdType, d as EmployeeQueryFilter, P as PayrollErrorResult, R as ResolveOrganizationIdParams, S as SecureEmployeeLookupOptions, T as TransactionErrorResult, e as accrueLeaveToBalance, f as calculateCarryOver, g as calculateLeaveDays, h as calculateUnpaidLeaveDeduction, i as detectEmployeeIdType, j as employeeExistsSecure, k as findEmployeeSecure, l as findEmployeesSecure, m as formatEmployeeId, n as formatUserError, o as getAvailableDays, p as getLeaveBalance, q as getLeaveBalances, r as getLeaveSummary, s as getUnpaidLeaveDays, t as handleDuplicateKeyError, u as handlePayrollError, v as handleTransactionError, w as hasLeaveBalance, x as initializeLeaveBalances, y as isObjectIdEmployeeId, z as isStringEmployeeId, _ as leaveUtils, A as normalizeEmployeeId, B as proRateAllocation, F as requireOrganizationId, G as resolveOrganizationId, H as tryResolveOrganizationId, I as validateOrganizationId } from '../error-helpers-Bm6lMny2.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @classytic/payroll - Logger
|
|
@@ -100,7 +100,18 @@ declare function startOfDay(date: Date): Date;
|
|
|
100
100
|
*/
|
|
101
101
|
declare function endOfDay(date: Date): Date;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Convert a date to a UTC-based date string for consistent comparison.
|
|
104
|
+
*
|
|
105
|
+
* Unlike `Date.toDateString()` which uses the local timezone, this produces
|
|
106
|
+
* a locale-independent string based on the date's year/month/day components.
|
|
107
|
+
* Use this for holiday set lookups to avoid timezone-dependent mismatches.
|
|
108
|
+
*/
|
|
109
|
+
declare function toUTCDateString(date: Date): string;
|
|
110
|
+
/**
|
|
111
|
+
* Calculate difference in days between two dates.
|
|
112
|
+
*
|
|
113
|
+
* Normalizes both dates to midnight before computing to avoid
|
|
114
|
+
* inconsistencies from time-of-day differences or DST transitions.
|
|
104
115
|
*/
|
|
105
116
|
declare function diffInDays(start: Date, end: Date): number;
|
|
106
117
|
/**
|
|
@@ -130,7 +141,7 @@ declare function getDayOfWeek(date: Date): number;
|
|
|
130
141
|
*/
|
|
131
142
|
declare function getDayName(date: Date): string;
|
|
132
143
|
/**
|
|
133
|
-
* Get pay period for a given month and year
|
|
144
|
+
* Get pay period for a given month and year (monthly periods)
|
|
134
145
|
*/
|
|
135
146
|
declare function getPayPeriod(month: number, year: number): PayPeriodInfo;
|
|
136
147
|
/**
|
|
@@ -226,6 +237,7 @@ declare function getMonthName(month: number): string;
|
|
|
226
237
|
*/
|
|
227
238
|
declare function getShortMonthName(month: number): string;
|
|
228
239
|
declare const _default$3: {
|
|
240
|
+
toUTCDateString: typeof toUTCDateString;
|
|
229
241
|
addDays: typeof addDays;
|
|
230
242
|
addMonths: typeof addMonths;
|
|
231
243
|
addYears: typeof addYears;
|