Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import type { CadenceOwner } from '@alga-psa/types';
|
|
|
|
import {
|
|
resolveBillingCycleAlignmentForCompatibility,
|
|
type BillingCycleAlignment,
|
|
} from './billingCycleAlignmentCompatibility';
|
|
import { resolveCadenceOwner } from './recurringTiming';
|
|
|
|
export type RecurringBillingTiming = 'arrears' | 'advance';
|
|
|
|
export const DEFAULT_RECURRING_AUTHORING_CADENCE_OWNER: CadenceOwner = 'client';
|
|
export const DEFAULT_RECURRING_AUTHORING_BILLING_TIMING: RecurringBillingTiming = 'arrears';
|
|
|
|
type ResolveRecurringAuthoringPolicyInput = {
|
|
cadenceOwner?: CadenceOwner | null;
|
|
fallbackCadenceOwner?: CadenceOwner | null;
|
|
defaultCadenceOwner?: CadenceOwner | null;
|
|
billingTiming?: RecurringBillingTiming | null;
|
|
fallbackBillingTiming?: RecurringBillingTiming | null;
|
|
enableProration?: boolean | null;
|
|
billingCycleAlignment?: BillingCycleAlignment | null;
|
|
fallbackBillingCycleAlignment?: BillingCycleAlignment | null;
|
|
};
|
|
|
|
export type RecurringAuthoringPolicy = {
|
|
cadenceOwner: CadenceOwner;
|
|
billingTiming: RecurringBillingTiming;
|
|
enableProration: boolean;
|
|
billingCycleAlignment: BillingCycleAlignment;
|
|
};
|
|
|
|
// Authoring defaults stay explicit here so wizard, inline edit, preset, repository,
|
|
// and API write paths can share one recurrence policy instead of inventing per-path fallbacks.
|
|
export function resolveRecurringAuthoringPolicy(
|
|
input: ResolveRecurringAuthoringPolicyInput,
|
|
): RecurringAuthoringPolicy {
|
|
const enableProration = Boolean(input.enableProration ?? false);
|
|
const resolvedCadenceOwner =
|
|
input.cadenceOwner
|
|
?? input.fallbackCadenceOwner
|
|
?? input.defaultCadenceOwner;
|
|
|
|
if (!resolvedCadenceOwner) {
|
|
throw new Error(
|
|
'Recurring authoring requires an explicit cadence owner or a stored cadence owner to reuse.',
|
|
);
|
|
}
|
|
|
|
return {
|
|
cadenceOwner: resolveCadenceOwner(resolvedCadenceOwner),
|
|
billingTiming:
|
|
input.billingTiming
|
|
?? input.fallbackBillingTiming
|
|
?? DEFAULT_RECURRING_AUTHORING_BILLING_TIMING,
|
|
enableProration,
|
|
billingCycleAlignment: resolveBillingCycleAlignmentForCompatibility({
|
|
billingCycleAlignment: input.billingCycleAlignment,
|
|
enableProration,
|
|
fallbackAlignment: input.fallbackBillingCycleAlignment,
|
|
}),
|
|
};
|
|
}
|