@mj-biz-apps/orders-core-entities-server 5.48.0 → 5.49.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/dist/ChangeSubscriptionProductOperation.d.ts +45 -0
- package/dist/ChangeSubscriptionProductOperation.d.ts.map +1 -0
- package/dist/ChangeSubscriptionProductOperation.js +198 -0
- package/dist/ChangeSubscriptionProductOperation.js.map +1 -0
- package/dist/ContractIncrease.d.ts +60 -0
- package/dist/ContractIncrease.d.ts.map +1 -0
- package/dist/ContractIncrease.js +108 -0
- package/dist/ContractIncrease.js.map +1 -0
- package/dist/GetRenewalWorklistOperation.d.ts +52 -0
- package/dist/GetRenewalWorklistOperation.d.ts.map +1 -0
- package/dist/GetRenewalWorklistOperation.js +361 -0
- package/dist/GetRenewalWorklistOperation.js.map +1 -0
- package/dist/OrderEntityServer.d.ts +14 -0
- package/dist/OrderEntityServer.d.ts.map +1 -1
- package/dist/OrderEntityServer.js +57 -0
- package/dist/OrderEntityServer.js.map +1 -1
- package/dist/RenewalPassMode.d.ts +40 -0
- package/dist/RenewalPassMode.d.ts.map +1 -0
- package/dist/RenewalPassMode.js +63 -0
- package/dist/RenewalPassMode.js.map +1 -0
- package/dist/RenewalPricing.d.ts +209 -0
- package/dist/RenewalPricing.d.ts.map +1 -0
- package/dist/RenewalPricing.js +396 -0
- package/dist/RenewalPricing.js.map +1 -0
- package/dist/SetRenewalSettingsOperation.d.ts +34 -0
- package/dist/SetRenewalSettingsOperation.d.ts.map +1 -0
- package/dist/SetRenewalSettingsOperation.js +135 -0
- package/dist/SetRenewalSettingsOperation.js.map +1 -0
- package/dist/SpawnRenewalsOperation.d.ts +83 -105
- package/dist/SpawnRenewalsOperation.d.ts.map +1 -1
- package/dist/SpawnRenewalsOperation.js +352 -467
- package/dist/SpawnRenewalsOperation.js.map +1 -1
- package/dist/SubscriptionEntityServer.d.ts +10 -2
- package/dist/SubscriptionEntityServer.d.ts.map +1 -1
- package/dist/SubscriptionEntityServer.js +16 -1
- package/dist/SubscriptionEntityServer.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview How the scheduled renewal pass is set up on this host: live, preview, or off.
|
|
3
|
+
*
|
|
4
|
+
* The Renewals page calls a subscription "due for renewal" when its term end is inside the lead
|
|
5
|
+
* window and auto-renew is on. Whether anything then happens depends on the scheduled job
|
|
6
|
+
* (`metadata/scheduled-jobs/.orders-renewal-scheduled-jobs.json`): it ships Disabled, and when
|
|
7
|
+
* enabled its `Preview` parameter ships `true`, so it reports what it would renew and places
|
|
8
|
+
* nothing until a person switches it live. A page that said "renews on the next pass" on such a
|
|
9
|
+
* host would be promising an order nobody will place. So the worklist reads the job and reports
|
|
10
|
+
* its mode, and the page says so.
|
|
11
|
+
*
|
|
12
|
+
* The job and its Preview parameter are found by the fixed IDs the metadata assigns them, which
|
|
13
|
+
* is what a re-push preserves. A host without the job row reads as Off; a read that fails reads
|
|
14
|
+
* as Unknown and is never fatal.
|
|
15
|
+
*
|
|
16
|
+
* CONNECTS TO:
|
|
17
|
+
* CALLERS: ./GetRenewalWorklistOperation.ts
|
|
18
|
+
* READS: MJ: Scheduled Jobs (Status, Configuration, NextRunAt)
|
|
19
|
+
*/
|
|
20
|
+
import { type IMetadataProvider, type UserInfo } from '@memberjunction/core';
|
|
21
|
+
/** `metadata/scheduled-jobs/.orders-renewal-scheduled-jobs.json`: "Orders — Spawn Renewals (daily)". */
|
|
22
|
+
export declare const RENEWAL_JOB_ID = "4E7A21B5-3C60-4F18-9D42-0A15C7E9B210";
|
|
23
|
+
/** `metadata/actions`: the Spawn Renewals action's `Preview` parameter. */
|
|
24
|
+
export declare const RENEWAL_PREVIEW_PARAM_ID = "4E7A21B5-3C60-4F18-9D42-0A15C7E9B203";
|
|
25
|
+
export type RenewalPassMode = 'Live' | 'Preview' | 'Off' | 'Unknown';
|
|
26
|
+
export interface RenewalPass {
|
|
27
|
+
Mode: RenewalPassMode;
|
|
28
|
+
NextRunAt: string | null;
|
|
29
|
+
}
|
|
30
|
+
interface JobRow {
|
|
31
|
+
Status: string | null;
|
|
32
|
+
Configuration: string | null;
|
|
33
|
+
NextRunAt: Date | string | null;
|
|
34
|
+
}
|
|
35
|
+
/** The mode a job row means. Null row: no job on this host, so nothing renews on its own. */
|
|
36
|
+
export declare function ReadPassMode(job: Pick<JobRow, 'Status' | 'Configuration'> | null): RenewalPassMode;
|
|
37
|
+
/** Read the job and say what it will do. Never throws: a page that cannot learn the mode still lists the renewals. */
|
|
38
|
+
export declare function LoadRenewalPass(provider: IMetadataProvider, user: UserInfo): Promise<RenewalPass>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=RenewalPassMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenewalPassMode.d.ts","sourceRoot":"","sources":["../src/RenewalPassMode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAqB,KAAK,iBAAiB,EAAyB,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEvH,wGAAwG;AACxG,eAAO,MAAM,cAAc,yCAAyC,CAAC;AACrE,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAE/E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,MAAM;IACZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,eAAe,CAAC,GAAG,IAAI,GAAG,eAAe,CAgBlG;AAED,sHAAsH;AACtH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAgBvG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview How the scheduled renewal pass is set up on this host: live, preview, or off.
|
|
3
|
+
*
|
|
4
|
+
* The Renewals page calls a subscription "due for renewal" when its term end is inside the lead
|
|
5
|
+
* window and auto-renew is on. Whether anything then happens depends on the scheduled job
|
|
6
|
+
* (`metadata/scheduled-jobs/.orders-renewal-scheduled-jobs.json`): it ships Disabled, and when
|
|
7
|
+
* enabled its `Preview` parameter ships `true`, so it reports what it would renew and places
|
|
8
|
+
* nothing until a person switches it live. A page that said "renews on the next pass" on such a
|
|
9
|
+
* host would be promising an order nobody will place. So the worklist reads the job and reports
|
|
10
|
+
* its mode, and the page says so.
|
|
11
|
+
*
|
|
12
|
+
* The job and its Preview parameter are found by the fixed IDs the metadata assigns them, which
|
|
13
|
+
* is what a re-push preserves. A host without the job row reads as Off; a read that fails reads
|
|
14
|
+
* as Unknown and is never fatal.
|
|
15
|
+
*
|
|
16
|
+
* CONNECTS TO:
|
|
17
|
+
* CALLERS: ./GetRenewalWorklistOperation.ts
|
|
18
|
+
* READS: MJ: Scheduled Jobs (Status, Configuration, NextRunAt)
|
|
19
|
+
*/
|
|
20
|
+
import { LogError, RunView } from '@memberjunction/core';
|
|
21
|
+
/** `metadata/scheduled-jobs/.orders-renewal-scheduled-jobs.json`: "Orders — Spawn Renewals (daily)". */
|
|
22
|
+
export const RENEWAL_JOB_ID = '4E7A21B5-3C60-4F18-9D42-0A15C7E9B210';
|
|
23
|
+
/** `metadata/actions`: the Spawn Renewals action's `Preview` parameter. */
|
|
24
|
+
export const RENEWAL_PREVIEW_PARAM_ID = '4E7A21B5-3C60-4F18-9D42-0A15C7E9B203';
|
|
25
|
+
/** The mode a job row means. Null row: no job on this host, so nothing renews on its own. */
|
|
26
|
+
export function ReadPassMode(job) {
|
|
27
|
+
if (!job)
|
|
28
|
+
return 'Off';
|
|
29
|
+
if (String(job.Status ?? '').trim().toLowerCase() !== 'active')
|
|
30
|
+
return 'Off';
|
|
31
|
+
let params = [];
|
|
32
|
+
if (job.Configuration) {
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(job.Configuration);
|
|
35
|
+
params = Array.isArray(parsed?.Params) ? parsed.Params : [];
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return 'Unknown';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const preview = params.find((p) => String(p.ActionParamID ?? '').toLowerCase() === RENEWAL_PREVIEW_PARAM_ID.toLowerCase());
|
|
42
|
+
// The action reads a blank as "not given", and the operation then places for real.
|
|
43
|
+
const value = String(preview?.Value ?? '').trim().toLowerCase();
|
|
44
|
+
return ['true', '1', 'yes', 'y'].includes(value) ? 'Preview' : 'Live';
|
|
45
|
+
}
|
|
46
|
+
/** Read the job and say what it will do. Never throws: a page that cannot learn the mode still lists the renewals. */
|
|
47
|
+
export async function LoadRenewalPass(provider, user) {
|
|
48
|
+
try {
|
|
49
|
+
const rv = new RunView(provider);
|
|
50
|
+
const result = await rv.RunView({ EntityName: 'MJ: Scheduled Jobs', ExtraFilter: `ID='${RENEWAL_JOB_ID}'`, Fields: ['Status', 'Configuration', 'NextRunAt'], ResultType: 'simple' }, user);
|
|
51
|
+
if (!result.Success)
|
|
52
|
+
throw new Error(result.ErrorMessage || 'the scheduled job could not be read');
|
|
53
|
+
const job = result.Results[0] ?? null;
|
|
54
|
+
const mode = ReadPassMode(job);
|
|
55
|
+
const next = job?.NextRunAt;
|
|
56
|
+
return { Mode: mode, NextRunAt: next == null ? null : next instanceof Date ? next.toISOString() : String(next) };
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
LogError(`RenewalPassMode: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
|
+
return { Mode: 'Unknown', NextRunAt: null };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=RenewalPassMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenewalPassMode.js","sourceRoot":"","sources":["../src/RenewalPassMode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAgE,MAAM,sBAAsB,CAAC;AAEvH,wGAAwG;AACxG,MAAM,CAAC,MAAM,cAAc,GAAG,sCAAsC,CAAC;AACrE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,wBAAwB,GAAG,sCAAsC,CAAC;AAe/E,6FAA6F;AAC7F,MAAM,UAAU,YAAY,CAAC,GAAoD;IAC7E,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7E,IAAI,MAAM,GAAuD,EAAE,CAAC;IACpE,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACpB,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAoE,CAAC;YAChH,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,C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AC,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IACrH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,QAAQ,CAAC,oBAAoB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAChD,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a subscription renews at, and onto what — shared by the renewal pass and the Renewals page.
|
|
3
|
+
*
|
|
4
|
+
* `Orders.SpawnRenewals` used to carry this code privately. The Renewals page needs the same answer
|
|
5
|
+
* for a subscription the pass is not yet due to place — "what will this renew at, and why?" — so a
|
|
6
|
+
* person can check the figure months ahead rather than the morning the order books. Moving the
|
|
7
|
+
* pricing here is what lets both read one rule; a second implementation in a worklist operation
|
|
8
|
+
* would be the one that drifted, and the drift would show up as a renewal priced differently from
|
|
9
|
+
* its preview.
|
|
10
|
+
*
|
|
11
|
+
* The rule itself is `PriceRenewal` in orders-entities (golive #304): the prior term's undiscounted
|
|
12
|
+
* price, or a successor's list price, plus the annual increase when the new term crosses an
|
|
13
|
+
* anniversary. This module gathers that rule's inputs: the line that bought the expiring term, the
|
|
14
|
+
* successor chain, the increase ladder (subscription → product → category → company), the list
|
|
15
|
+
* prices the rule needs, and the term the renewal would buy. The increase ladder, the successor
|
|
16
|
+
* chain and the type rules are cached per instance, because a worklist prices hundreds of rows and
|
|
17
|
+
* most of them share a product.
|
|
18
|
+
*
|
|
19
|
+
* NOTHING HERE WRITES. A pricer is read-only by construction, so a preview, a worklist and the live
|
|
20
|
+
* pass all run the same code and only the pass goes on to place an order.
|
|
21
|
+
*
|
|
22
|
+
* @module @mj-biz-apps/orders-core-entities-server
|
|
23
|
+
*/
|
|
24
|
+
import { type IMetadataProvider, type UserInfo } from '@memberjunction/core';
|
|
25
|
+
import { type RenewalPrice } from '@mj-biz-apps/orders-entities';
|
|
26
|
+
/**
|
|
27
|
+
* A subscription and the term that is expiring: everything the pricer and the pass read about it.
|
|
28
|
+
* Dates are `YYYY-MM-DD` (or whatever the driver hands back for a `date` column; read through
|
|
29
|
+
* `new Date(...)` only in UTC day arithmetic).
|
|
30
|
+
*/
|
|
31
|
+
export interface RenewalSubjectRow {
|
|
32
|
+
SubscriptionID: string;
|
|
33
|
+
SubscriptionNumber: string;
|
|
34
|
+
SubscriptionStatus: string;
|
|
35
|
+
SubscriptionTypeID: string;
|
|
36
|
+
CompanyID: string;
|
|
37
|
+
ProductID: string;
|
|
38
|
+
HolderOrganizationID: string | null;
|
|
39
|
+
BeneficiaryPersonID: string | null;
|
|
40
|
+
SubscriptionRenewalLeadDays: number | null;
|
|
41
|
+
TypeRenewalLeadDays: number | null;
|
|
42
|
+
TermID: string;
|
|
43
|
+
TermNumber: number;
|
|
44
|
+
TermStartDate: string;
|
|
45
|
+
TermEndDate: string;
|
|
46
|
+
/** Seats the expiring term covers (`SubscriptionTerm.Quantity`) — what the renewal buys again. */
|
|
47
|
+
TermQuantity: number;
|
|
48
|
+
OrderLineID: string;
|
|
49
|
+
SubscriptionStartDate: string;
|
|
50
|
+
SubscriptionIncreasePercent: number | null;
|
|
51
|
+
CarryDiscountOnRenewal: boolean;
|
|
52
|
+
/** The renewal card (#289). When set, the renewal is charged on its term start and is due that day. */
|
|
53
|
+
DefaultCustomerPaymentMethodID: string | null;
|
|
54
|
+
/** `Subscription.AutoRenew`: the customer's standing consent to recurring billing. */
|
|
55
|
+
AutoRenew: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** The line that bought the expiring term, as the pricer reads it. */
|
|
58
|
+
export interface RenewalSourceLineRow {
|
|
59
|
+
ID: string;
|
|
60
|
+
OrderHeaderID: string;
|
|
61
|
+
ProductID: string;
|
|
62
|
+
Quantity: number;
|
|
63
|
+
UnitPrice: number;
|
|
64
|
+
DiscountPct: number | null;
|
|
65
|
+
PriceOverridden: boolean;
|
|
66
|
+
ProductPriceID: string | null;
|
|
67
|
+
/** The coverage the line bought, start of its first term to end of its last (golive #338). */
|
|
68
|
+
ServicePeriodStart: string | null;
|
|
69
|
+
ServicePeriodEnd: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** A product on the subscription's successor chain, the subscription's own product first. */
|
|
72
|
+
export interface ChainProductRow {
|
|
73
|
+
ID: string;
|
|
74
|
+
Name: string;
|
|
75
|
+
Status: string;
|
|
76
|
+
ProductCategoryID: string;
|
|
77
|
+
RenewalIncreasePercent: number | null;
|
|
78
|
+
SuccessorProductID: string | null;
|
|
79
|
+
/** The product's subscription type, else its product type's default; null when it sells no subscription. */
|
|
80
|
+
SubscriptionTypeID: string | null;
|
|
81
|
+
ProductTypeID: string | null;
|
|
82
|
+
}
|
|
83
|
+
/** A promotion code recorded on the line that bought the expiring term. */
|
|
84
|
+
export interface RecordedCodeRow {
|
|
85
|
+
PromotionCodeID: string;
|
|
86
|
+
Code: string;
|
|
87
|
+
AppliesToRenewals: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** What the pricer decided: the product, quantity and price the renewal line is written with. */
|
|
90
|
+
export interface PricedRenewal {
|
|
91
|
+
ProductID: string;
|
|
92
|
+
ProductName: string;
|
|
93
|
+
MovesToSuccessor: boolean;
|
|
94
|
+
Quantity: number;
|
|
95
|
+
Price: RenewalPrice;
|
|
96
|
+
/** The months the prior line's price covered, when it bought several terms and was cut to one (golive #338). */
|
|
97
|
+
PriorLineMonths: number | null;
|
|
98
|
+
/** The renewal term, as the confirm will decide it; null when it cannot be decided ahead of the confirm. */
|
|
99
|
+
Term: {
|
|
100
|
+
Start: string;
|
|
101
|
+
End: string;
|
|
102
|
+
} | null;
|
|
103
|
+
/** The codes the renewal presents (see `RenewalPromotions.ts`), with their PromotionCode IDs. */
|
|
104
|
+
PromotionCodes: RecordedCodeRow[];
|
|
105
|
+
}
|
|
106
|
+
export interface RenewalPriceOptions {
|
|
107
|
+
/**
|
|
108
|
+
* The source line, when the caller has already read it (a worklist reads them all in one query).
|
|
109
|
+
* `null` says it was looked for and is gone; absent says the pricer should read it.
|
|
110
|
+
*/
|
|
111
|
+
SourceLine?: RenewalSourceLineRow | null;
|
|
112
|
+
/** Read the promotion codes recorded on the source line. Defaults to true; a worklist projection skips them. */
|
|
113
|
+
IncludePromotions?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Why a successor chain cannot be renewed onto, or null when it can (#869).
|
|
117
|
+
*
|
|
118
|
+
* A successor that resolves no subscription type would book the renewal as a plain line with no
|
|
119
|
+
* term, and every later pass would then skip the subscription as already renewed. So the candidate
|
|
120
|
+
* is skipped with this reason instead. The subscription's own product (the first entry) is not
|
|
121
|
+
* checked: it already holds the subscription.
|
|
122
|
+
*/
|
|
123
|
+
export declare function NonSubscriptionSuccessorRefusal(chain: ReadonlyArray<Pick<ChainProductRow, 'Name' | 'SubscriptionTypeID'>>): string | null;
|
|
124
|
+
/** The day after a `YYYY-MM-DD` (or date-like) value, as a UTC-midnight `Date`: where the renewal term starts. */
|
|
125
|
+
export declare function DayAfter(date: string | Date): Date;
|
|
126
|
+
/** Lead days in force for a subject: its own, else its type's, else 0. */
|
|
127
|
+
export declare function EffectiveLeadDays(subject: Pick<RenewalSubjectRow, 'SubscriptionRenewalLeadDays' | 'TypeRenewalLeadDays'>): number;
|
|
128
|
+
/** Column list the pricer needs from an order line; shared so a bulk reader returns the same shape. */
|
|
129
|
+
export declare const RENEWAL_SOURCE_LINE_FIELDS: readonly ["ID", "OrderHeaderID", "ProductID", "Quantity", "UnitPrice", "DiscountPct", "PriceOverridden", "ProductPriceID", "ServicePeriodStart", "ServicePeriodEnd"];
|
|
130
|
+
/**
|
|
131
|
+
* Prices renewals for one provider and user, caching what rows share.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const pricer = new RenewalPricer(provider, user);
|
|
136
|
+
* const priced = await pricer.Price(subject); // throws with a reason a person can act on
|
|
137
|
+
* priced.Price.UnitPrice; priced.Term?.Start;
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare class RenewalPricer {
|
|
141
|
+
private readonly provider;
|
|
142
|
+
private readonly user;
|
|
143
|
+
private readonly chains;
|
|
144
|
+
private readonly categoryIncreases;
|
|
145
|
+
private readonly companyIncreases;
|
|
146
|
+
constructor(provider: IMetadataProvider, user: UserInfo);
|
|
147
|
+
/**
|
|
148
|
+
* What the renewal line is written with: product, quantity and price (golive #304).
|
|
149
|
+
*
|
|
150
|
+
* Read-only, so a preview and a worklist run it too. Throws with a reason a person can act on
|
|
151
|
+
* when the renewal cannot be priced; the caller reports that reason on the row.
|
|
152
|
+
*/
|
|
153
|
+
Price(due: RenewalSubjectRow, options?: RenewalPriceOptions): Promise<PricedRenewal>;
|
|
154
|
+
/** The line that bought the expiring term, or null when it is gone. */
|
|
155
|
+
LoadSourceLine(orderLineID: string): Promise<RenewalSourceLineRow | null>;
|
|
156
|
+
/**
|
|
157
|
+
* Several source lines in one read, keyed by lower-cased ID. A worklist prices hundreds of rows;
|
|
158
|
+
* one query per row would be the N+1 the architecture doc warns about.
|
|
159
|
+
*/
|
|
160
|
+
LoadSourceLines(orderLineIDs: ReadonlyArray<string>): Promise<Map<string, RenewalSourceLineRow>>;
|
|
161
|
+
/**
|
|
162
|
+
* The term the renewal buys, decided the way the confirm decides it: the renewal product's
|
|
163
|
+
* subscription type and behaviour, continuing the subscription from the day after its latest term.
|
|
164
|
+
* Null when that cannot be decided here (no type, an unregistered driver, a rejection); the
|
|
165
|
+
* confirm then reports the reason itself.
|
|
166
|
+
*/
|
|
167
|
+
RenewalTerm(due: RenewalSubjectRow, product: ChainProductRow): {
|
|
168
|
+
Start: string;
|
|
169
|
+
End: string;
|
|
170
|
+
} | null;
|
|
171
|
+
/**
|
|
172
|
+
* The months the source line's price covers when that line bought earlier terms too, or null
|
|
173
|
+
* (golive #338). Read from the line's service period, which the confirm sets to the whole coverage.
|
|
174
|
+
*/
|
|
175
|
+
private priorLineMonths;
|
|
176
|
+
/**
|
|
177
|
+
* The term length of the subscription's own type: the length the confirm split the source line
|
|
178
|
+
* by. Throws when the type cannot be read, since renewing at the whole line's price would bill
|
|
179
|
+
* the customer for every term the line already paid for.
|
|
180
|
+
*/
|
|
181
|
+
private termMonthsOf;
|
|
182
|
+
/** A subscription type's rules from the engine cache, or null when the type is not there. */
|
|
183
|
+
private rulesFor;
|
|
184
|
+
/**
|
|
185
|
+
* The codes the renewal presents: those recorded on the line that bought the expiring term whose
|
|
186
|
+
* promotion carries into renewals (#289). A promotion's adjustment rows always name a line; an
|
|
187
|
+
* order-level promotion writes one per line, so the source line's own rows are complete.
|
|
188
|
+
*/
|
|
189
|
+
private loadRenewalPromotionCodes;
|
|
190
|
+
/**
|
|
191
|
+
* The subscription's product followed along `SuccessorProductID` while the next product is
|
|
192
|
+
* Active: a successor that is still a draft, or already retired, is not one to renew onto.
|
|
193
|
+
* The subscription's own product comes first; the last entry is what the renewal is placed on.
|
|
194
|
+
* Cached per product for the life of the pricer.
|
|
195
|
+
*/
|
|
196
|
+
private loadSuccessorChain;
|
|
197
|
+
private readSuccessorChain;
|
|
198
|
+
/** `RenewalIncreasePercent` of a category and each ancestor, the category itself first. Cached. */
|
|
199
|
+
private loadCategoryIncreases;
|
|
200
|
+
/** The selling company's `OrderCompanyPolicy.RenewalIncreasePercent`; null when it has no policy row. Cached. */
|
|
201
|
+
private loadCompanyIncrease;
|
|
202
|
+
/**
|
|
203
|
+
* What the pricing engine charges for `line`'s product, for the customer on `line`'s order. As of
|
|
204
|
+
* that order's date, or as of `asOf` when given. Null when no rule prices the product.
|
|
205
|
+
*/
|
|
206
|
+
private listPrice;
|
|
207
|
+
private sql;
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=RenewalPricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenewalPricing.d.ts","sourceRoot":"","sources":["../src/RenewalPricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAqB,KAAK,iBAAiB,EAAyB,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvH,OAAO,EAWH,KAAK,YAAY,EACpB,MAAM,8BAA8B,CAAC;AActC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,kGAAkG;IAClG,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,sBAAsB,EAAE,OAAO,CAAC;IAChC,uGAAuG;IACvG,8BAA8B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,sFAAsF;IACtF,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,sEAAsE;AACtE,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,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