@mj-biz-apps/orders-entities 0.0.1 → 5.2.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.
Files changed (115) hide show
  1. package/LICENSE +183 -0
  2. package/README.md +50 -2
  3. package/dist/CustomerPaymentMethodEntity.d.ts +4 -0
  4. package/dist/CustomerPaymentMethodEntity.d.ts.map +1 -0
  5. package/dist/CustomerPaymentMethodEntity.js +26 -0
  6. package/dist/CustomerPaymentMethodEntity.js.map +1 -0
  7. package/dist/InitialPaymentIntentCompanion.d.ts +29 -0
  8. package/dist/InitialPaymentIntentCompanion.d.ts.map +1 -0
  9. package/dist/InitialPaymentIntentCompanion.js +40 -0
  10. package/dist/InitialPaymentIntentCompanion.js.map +1 -0
  11. package/dist/OrderHeaderEntity.d.ts +224 -0
  12. package/dist/OrderHeaderEntity.d.ts.map +1 -0
  13. package/dist/OrderHeaderEntity.js +509 -0
  14. package/dist/OrderHeaderEntity.js.map +1 -0
  15. package/dist/OrderLineEntity.d.ts +25 -0
  16. package/dist/OrderLineEntity.d.ts.map +1 -0
  17. package/dist/OrderLineEntity.js +54 -0
  18. package/dist/OrderLineEntity.js.map +1 -0
  19. package/dist/OrderLineExtensionCompanion.d.ts +54 -0
  20. package/dist/OrderLineExtensionCompanion.d.ts.map +1 -0
  21. package/dist/OrderLineExtensionCompanion.js +167 -0
  22. package/dist/OrderLineExtensionCompanion.js.map +1 -0
  23. package/dist/OrderStatusBehavior.d.ts +86 -0
  24. package/dist/OrderStatusBehavior.d.ts.map +1 -0
  25. package/dist/OrderStatusBehavior.js +160 -0
  26. package/dist/OrderStatusBehavior.js.map +1 -0
  27. package/dist/PartyAffiliationBehavior.d.ts +20 -0
  28. package/dist/PartyAffiliationBehavior.d.ts.map +1 -0
  29. package/dist/PartyAffiliationBehavior.js +52 -0
  30. package/dist/PartyAffiliationBehavior.js.map +1 -0
  31. package/dist/PaymentHeaderEntity.d.ts +18 -0
  32. package/dist/PaymentHeaderEntity.d.ts.map +1 -0
  33. package/dist/PaymentHeaderEntity.js +80 -0
  34. package/dist/PaymentHeaderEntity.js.map +1 -0
  35. package/dist/PricingDriverResolver.d.ts +70 -0
  36. package/dist/PricingDriverResolver.d.ts.map +1 -0
  37. package/dist/PricingDriverResolver.js +145 -0
  38. package/dist/PricingDriverResolver.js.map +1 -0
  39. package/dist/PromotionCodesCompanion.d.ts +77 -0
  40. package/dist/PromotionCodesCompanion.d.ts.map +1 -0
  41. package/dist/PromotionCodesCompanion.js +111 -0
  42. package/dist/PromotionCodesCompanion.js.map +1 -0
  43. package/dist/booked-money.d.ts +27 -0
  44. package/dist/booked-money.d.ts.map +1 -0
  45. package/dist/booked-money.js +67 -0
  46. package/dist/booked-money.js.map +1 -0
  47. package/dist/configuration-types.d.ts +157 -0
  48. package/dist/configuration-types.d.ts.map +1 -0
  49. package/dist/configuration-types.js +10 -0
  50. package/dist/configuration-types.js.map +1 -0
  51. package/dist/date-cell.d.ts +109 -0
  52. package/dist/date-cell.d.ts.map +1 -0
  53. package/dist/date-cell.js +131 -0
  54. package/dist/date-cell.js.map +1 -0
  55. package/dist/generated/entity_subclasses.d.ts +12055 -0
  56. package/dist/generated/entity_subclasses.d.ts.map +1 -0
  57. package/dist/generated/entity_subclasses.js +17800 -0
  58. package/dist/generated/entity_subclasses.js.map +1 -0
  59. package/dist/generated/remote_operations.d.ts +2365 -0
  60. package/dist/generated/remote_operations.d.ts.map +1 -0
  61. package/dist/generated/remote_operations.js +768 -0
  62. package/dist/generated/remote_operations.js.map +1 -0
  63. package/dist/index.d.ts +102 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +103 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/line-quantity.d.ts +6 -0
  68. package/dist/line-quantity.d.ts.map +1 -0
  69. package/dist/line-quantity.js +11 -0
  70. package/dist/line-quantity.js.map +1 -0
  71. package/dist/overdue.d.ts +77 -0
  72. package/dist/overdue.d.ts.map +1 -0
  73. package/dist/overdue.js +90 -0
  74. package/dist/overdue.js.map +1 -0
  75. package/dist/pricing/ChargeBehavior.d.ts +64 -0
  76. package/dist/pricing/ChargeBehavior.d.ts.map +1 -0
  77. package/dist/pricing/ChargeBehavior.js +124 -0
  78. package/dist/pricing/ChargeBehavior.js.map +1 -0
  79. package/dist/pricing/ChargeEngine.d.ts +54 -0
  80. package/dist/pricing/ChargeEngine.d.ts.map +1 -0
  81. package/dist/pricing/ChargeEngine.js +154 -0
  82. package/dist/pricing/ChargeEngine.js.map +1 -0
  83. package/dist/pricing/OrderPricingService.d.ts +244 -0
  84. package/dist/pricing/OrderPricingService.d.ts.map +1 -0
  85. package/dist/pricing/OrderPricingService.js +516 -0
  86. package/dist/pricing/OrderPricingService.js.map +1 -0
  87. package/dist/pricing/OrdersEngine.d.ts +100 -0
  88. package/dist/pricing/OrdersEngine.d.ts.map +1 -0
  89. package/dist/pricing/OrdersEngine.js +156 -0
  90. package/dist/pricing/OrdersEngine.js.map +1 -0
  91. package/dist/pricing/PriceResolver.d.ts +127 -0
  92. package/dist/pricing/PriceResolver.d.ts.map +1 -0
  93. package/dist/pricing/PriceResolver.js +345 -0
  94. package/dist/pricing/PriceResolver.js.map +1 -0
  95. package/dist/pricing/PricingBehavior.d.ts +161 -0
  96. package/dist/pricing/PricingBehavior.d.ts.map +1 -0
  97. package/dist/pricing/PricingBehavior.js +351 -0
  98. package/dist/pricing/PricingBehavior.js.map +1 -0
  99. package/dist/pricing/PromotionBehavior.d.ts +73 -0
  100. package/dist/pricing/PromotionBehavior.d.ts.map +1 -0
  101. package/dist/pricing/PromotionBehavior.js +166 -0
  102. package/dist/pricing/PromotionBehavior.js.map +1 -0
  103. package/dist/pricing/PromotionEngine.d.ts +131 -0
  104. package/dist/pricing/PromotionEngine.d.ts.map +1 -0
  105. package/dist/pricing/PromotionEngine.js +505 -0
  106. package/dist/pricing/PromotionEngine.js.map +1 -0
  107. package/dist/pricing/TaxResolver.d.ts +162 -0
  108. package/dist/pricing/TaxResolver.d.ts.map +1 -0
  109. package/dist/pricing/TaxResolver.js +361 -0
  110. package/dist/pricing/TaxResolver.js.map +1 -0
  111. package/dist/save-populated-fields.d.ts +17 -0
  112. package/dist/save-populated-fields.d.ts.map +1 -0
  113. package/dist/save-populated-fields.js +25 -0
  114. package/dist/save-populated-fields.js.map +1 -0
  115. package/package.json +34 -5
package/LICENSE ADDED
@@ -0,0 +1,183 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB plc.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Blue Cypress, Inc.
11
+
12
+ Licensed Work: MemberJunction.
13
+ The Licensed Work is (c) 2023-2026 Blue Cypress, Inc.
14
+
15
+ Additional Use Grant: Subject to the terms of this License, Licensor grants
16
+ you the following additional rights to make Production
17
+ Use of the Licensed Work.
18
+
19
+ 1. Internal Use
20
+
21
+ You may make production use of the Licensed Work for
22
+ your own internal business or organizational operations.
23
+
24
+ 2. Nonprofit Use
25
+
26
+ If you are a Nonprofit, you may make production use of
27
+ the Licensed Work for the operations and activities of
28
+ your Organizational Family.
29
+
30
+ 3. MemberJunction Certified Program Use
31
+
32
+ If you are authorized by Licensor under the
33
+ MemberJunction Certified Program to provide professional
34
+ services using the Licensed Work, you may make
35
+ production use of the Licensed Work in providing such
36
+ professional services to a client, provided that:
37
+
38
+ (a) the Licensed Work is deployed in, and the applicable
39
+ production use occurs within, an environment owned,
40
+ leased, licensed, subscribed to, or otherwise controlled
41
+ by that client; and
42
+
43
+ (b) the production use is for that client's own internal
44
+ business or organizational operations or is otherwise
45
+ independently permitted to that client under this
46
+ Additional Use Grant.
47
+
48
+ 4. Definitions Applicable to the Additional Use Grant
49
+
50
+ "Affiliate" means, with respect to a specified Person,
51
+ any other Person that directly or indirectly Controls,
52
+ is Controlled by, or is under common Control with such
53
+ specified Person.
54
+
55
+ "Control" (including the terms "Controls," "Controlled
56
+ by," and "under common Control with") means the direct
57
+ or indirect possession of the power to direct or cause
58
+ the direction of the management and policies of a
59
+ Person, whether through ownership of voting interests,
60
+ by contract, or otherwise.
61
+
62
+ "Organizational Family" means, with respect to a Person,
63
+ (a) such Person and its Affiliates, and (b) any
64
+ nonprofit organization, governmental entity, chapter,
65
+ division, local affiliate, regional affiliate, state
66
+ affiliate, national affiliate, or other entity that is
67
+ formally affiliated with such Person through governing
68
+ documents, a charter, bylaws, a membership agreement, or
69
+ another written organizational instrument, and is
70
+ recognized under such documents as part of the same
71
+ organizational structure.
72
+
73
+ "Nonprofit" means a Person recognized by the Internal
74
+ Revenue Service as exempt from federal income taxation
75
+ under Section 501(c)(3), 501(c)(4), 501(c)(5), or
76
+ 501(c)(6) of the Internal Revenue Code, or a foreign
77
+ organization recognized under substantially equivalent
78
+ laws.
79
+
80
+ A Person claiming eligibility as a Nonprofit shall, upon
81
+ Licensor's reasonable request, provide documentation
82
+ reasonably sufficient to demonstrate that it qualifies
83
+ as a Nonprofit. If such Person materially misrepresents,
84
+ or is unable to demonstrate, its qualification as a
85
+ Nonprofit, the rights granted to such Person under
86
+ Section 2 of this Additional Use Grant shall terminate.
87
+
88
+ "MemberJunction Certified Program" means Licensor's
89
+ then-current program for certifying and authorizing a
90
+ Person to provide professional services using the
91
+ Licensed Work.
92
+
93
+ "Person" means any individual, corporation, limited
94
+ liability company, partnership, association, nonprofit
95
+ organization, governmental entity, or other legal or
96
+ organizational entity.
97
+
98
+ Change Date: Four (4) years from the date the Licensed Work is first
99
+ made available.
100
+
101
+ Change License: MIT License.
102
+
103
+ For information about alternative licensing arrangements for the Licensed
104
+ Work, please contact Blue Cypress, Inc.
105
+
106
+ -----------------------------------------------------------------------------
107
+
108
+ Terms
109
+
110
+ The Licensor hereby grants you the right to copy, modify, create derivative
111
+ works, redistribute, and make non-production use of the Licensed Work. The
112
+ Licensor may make an Additional Use Grant, above, permitting limited
113
+ production use.
114
+
115
+ Effective on the Change Date, or the fourth anniversary of the first publicly
116
+ available distribution of a specific version of the Licensed Work under this
117
+ License, whichever comes first, the Licensor hereby grants you rights under
118
+ the terms of the Change License, and the rights granted in the paragraph
119
+ above terminate.
120
+
121
+ If your use of the Licensed Work does not comply with the requirements
122
+ currently in effect as described in this License, you must purchase a
123
+ commercial license from the Licensor, its affiliated entities, or authorized
124
+ resellers, or you must refrain from using the Licensed Work.
125
+
126
+ All copies of the original and modified Licensed Work, and derivative works
127
+ of the Licensed Work, are subject to this License. This License applies
128
+ separately for each version of the Licensed Work and the Change Date may vary
129
+ for each version of the Licensed Work released by Licensor.
130
+
131
+ You must conspicuously display this License on each original or modified copy
132
+ of the Licensed Work. If you receive the Licensed Work in original or
133
+ modified form from a third party, the terms and conditions set forth in this
134
+ License apply to your use of that work.
135
+
136
+ Any use of the Licensed Work in violation of this License will automatically
137
+ terminate your rights under this License for the current and all other
138
+ versions of the Licensed Work.
139
+
140
+ This License does not grant you any right in any trademark or logo of
141
+ Licensor or its affiliates (provided that you may use a trademark or logo of
142
+ Licensor as expressly required by this License).
143
+
144
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
145
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
146
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
147
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
148
+ TITLE.
149
+
150
+ MariaDB hereby grants you permission to use this License's text to license
151
+ your works, and to refer to it using the trademark "Business Source License",
152
+ as long as you comply with the Covenants of Licensor below.
153
+
154
+ -----------------------------------------------------------------------------
155
+
156
+ Covenants of Licensor
157
+
158
+ In consideration of the right to use this License's text and the "Business
159
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
160
+ other recipients of the licensed work to be provided by Licensor:
161
+
162
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
163
+ or a license that is compatible with GPL Version 2.0 or a later version,
164
+ where "compatible" means that software provided under the Change License
165
+ can be included in a program with software provided under GPL Version 2.0
166
+ or a later version. Licensor may specify additional Change Licenses without
167
+ limitation.
168
+
169
+ 2. To either: (a) specify an additional grant of rights to use that does not
170
+ impose any additional restriction on the right granted in this License, as
171
+ the Additional Use Grant; or (b) insert the text "None".
172
+
173
+ 3. To specify a Change Date.
174
+
175
+ 4. Not to modify this License in any other way.
176
+
177
+ -----------------------------------------------------------------------------
178
+
179
+ Notice
180
+
181
+ The Business Source License (this document, or the "License") is not an Open
182
+ Source license. However, the Licensed Work will eventually be made available
183
+ under an Open Source License, as stated in this License.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # @mj-biz-apps/orders-entities
1
+ # `@mj-biz-apps/orders-entities`
2
2
 
3
- Placeholder release. See https://github.com/MemberJunction/bizapps-orders
3
+ **Generated entity subclasses and Zod schemas for every table in `__mj_BizAppsOrders`.** Browser-safe:
4
+ depends on `@memberjunction/core` and `zod`, nothing server-side.
5
+
6
+ ## Do not edit anything in `src/generated/`
7
+
8
+ CodeGen rewrites it wholesale from the database. Edits are lost at the next run, silently, and
9
+ usually at the worst moment.
10
+
11
+ To change what appears here, change the **schema**:
12
+
13
+ ```bash
14
+ # 1. edit the baseline migration (pre-1.0 practice: edit in place, never fix-up migrations)
15
+ # 2. rebuild from zero and regenerate
16
+ scripts/rebuild-db.sh # trims the generated half, applies hand-authored DDL only
17
+ npm run mj:codegen # regenerates everything, since the DB is now bare
18
+ scripts/append-codegen.sh # puts the generated SQL back below the banner
19
+ npm run mj -- sync push --dir metadata
20
+ ```
21
+
22
+ That cycle is self-consistent by construction: the rebuild deliberately drops the generated half
23
+ first, because otherwise it produces a database whose metadata is already current and CodeGen emits
24
+ only a delta.
25
+
26
+ ## What CodeGen gives you, and what it does not
27
+
28
+ **Does:** a typed class per entity, a Zod schema per entity, string-union types derived from CHECK
29
+ constraints (`OrderType`, `Status`, `PricingModel`…), and field descriptions lifted from the
30
+ migration's `MS_Description` extended properties.
31
+
32
+ That last one is why the migration is so heavily commented — those comments become the developer
33
+ documentation and the AI-facing metadata. A column added without an extended property arrives here
34
+ undocumented.
35
+
36
+ **Does not:** business rules. Every invariant lives in
37
+ `@mj-biz-apps/orders-core-entities-server`, whose subclasses override `Save()` and are resolved by
38
+ `ClassFactory` at runtime. Instantiating an entity from this package on the client gets you the
39
+ shape; the rules run on the server.
40
+
41
+ ## Two things that will bite
42
+
43
+ **Union types come from CHECK constraints.** Widening a CHECK widens the type — a breaking change to
44
+ consumers even though no TypeScript was touched. Narrowing one is worse: existing rows become
45
+ unrepresentable.
46
+
47
+ **A repeated column name inside a CHECK can break generation.** CodeGen derives validation method
48
+ names from the constraint expression, and repeating a column produced a call to
49
+ `ValidatePromotionOrReasonRequiredReasonRequiredReasonRequired` against a method defined as
50
+ `ValidatePromotionOrReasonRequired` — a build break in generated code. Name the column once
51
+ (`ISNULL(col, '')` rather than `col IS NOT NULL AND col <> ''`). Reported upstream.
@@ -0,0 +1,4 @@
1
+ import { mjBizAppsOrdersCustomerPaymentMethodEntity } from './generated/entity_subclasses.js';
2
+ export declare class CustomerPaymentMethodEntity extends mjBizAppsOrdersCustomerPaymentMethodEntity {
3
+ }
4
+ //# sourceMappingURL=CustomerPaymentMethodEntity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomerPaymentMethodEntity.d.ts","sourceRoot":"","sources":["../src/CustomerPaymentMethodEntity.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,0CAA0C,EAE7C,MAAM,+BAA+B,CAAC;AAKvC,qBACa,2BAA4B,SAAQ,0CAA0C;CAAG"}
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * Shared (client + server) subclass for Customer Payment Methods.
9
+ *
10
+ * Declares the required `PaymentDetailID` embed here — the wallet is a thin host
11
+ * and the instrument snapshot lives on Payment Details (D38/D39). CodeGen will
12
+ * emit the same members onto the generated class once `EntityField.EmbeddedRecord`
13
+ * is set on a database that has that MJ column; remove this declaration then.
14
+ */
15
+ import { BaseEntity } from '@memberjunction/core';
16
+ import { RegisterClass } from '@memberjunction/global';
17
+ import { mjBizAppsOrdersCustomerPaymentMethodEntity, } from './generated/entity_subclasses.js';
18
+ const ENTITY = 'MJ_BizApps_Orders: Customer Payment Methods';
19
+ const DETAIL_ENTITY = 'MJ_BizApps_Orders: Payment Details';
20
+ let CustomerPaymentMethodEntity = class CustomerPaymentMethodEntity extends mjBizAppsOrdersCustomerPaymentMethodEntity {
21
+ };
22
+ CustomerPaymentMethodEntity = __decorate([
23
+ RegisterClass(BaseEntity, ENTITY)
24
+ ], CustomerPaymentMethodEntity);
25
+ export { CustomerPaymentMethodEntity };
26
+ //# sourceMappingURL=CustomerPaymentMethodEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomerPaymentMethodEntity.js","sourceRoot":"","sources":["../src/CustomerPaymentMethodEntity.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACH,0CAA0C,GAE7C,MAAM,+BAA+B,CAAC;AAEvC,MAAM,MAAM,GAAG,6CAA6C,CAAC;AAC7D,MAAM,aAAa,GAAG,oCAAoC,CAAC;AAGpD,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,0CAA0C;CAAG,CAAA;AAAjF,2BAA2B;IADvC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC;GACrB,2BAA2B,CAAsD"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The check / wire / transfer number typed at order entry.
3
+ *
4
+ * There is no `InitialPaymentReference` column — the number lives on `PaymentDetail.ReferenceNumber`
5
+ * once confirm creates that row. Until then the browser holds a string that has to reach the
6
+ * server, which is what a companion is for (same reason as promotion codes).
7
+ *
8
+ * Leaving it as page state is how Fast Entry confirmed a Check with "abc" on screen and the
9
+ * server refused: `createInitialPayment` only looks at `InitialPaymentDetailID`, and nothing had
10
+ * created that row.
11
+ */
12
+ import { EntityCompanion, type EntityCompanionDeserializeMode } from '@memberjunction/core';
13
+ export type InitialPaymentIntentWire = {
14
+ Reference: string;
15
+ };
16
+ export declare class InitialPaymentIntentCompanion extends EntityCompanion<InitialPaymentIntentWire> {
17
+ readonly Name = "InitialPaymentIntent";
18
+ private reference;
19
+ get Reference(): string | null;
20
+ set Reference(value: string | null);
21
+ Serialize(): Promise<InitialPaymentIntentWire | null>;
22
+ Deserialize(data: InitialPaymentIntentWire, _mode: EntityCompanionDeserializeMode): Promise<void>;
23
+ /**
24
+ * Dirty when a reference is present so a confirm whose only extra fact is the check
25
+ * number still ships the companion. A clean companion would drop it on Save().
26
+ */
27
+ get Dirty(): boolean;
28
+ }
29
+ //# sourceMappingURL=InitialPaymentIntentCompanion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InitialPaymentIntentCompanion.d.ts","sourceRoot":"","sources":["../src/InitialPaymentIntentCompanion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,eAAe,EAAE,KAAK,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAE5F,MAAM,MAAM,wBAAwB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,qBAAa,6BAA8B,SAAQ,eAAe,CAAC,wBAAwB,CAAC;IACxF,SAAgB,IAAI,0BAA0B;IAE9C,OAAO,CAAC,SAAS,CAAuB;IAExC,IAAW,SAAS,IAAI,MAAM,GAAG,IAAI,CAEpC;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAGxC;IAEY,SAAS,IAAI,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC;IAIrD,WAAW,CACpB,IAAI,EAAE,wBAAwB,EAC9B,KAAK,EAAE,8BAA8B,GACtC,OAAO,CAAC,IAAI,CAAC;IAIhB;;;OAGG;IACH,IAAoB,KAAK,IAAI,OAAO,CAEnC;CACJ"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The check / wire / transfer number typed at order entry.
3
+ *
4
+ * There is no `InitialPaymentReference` column — the number lives on `PaymentDetail.ReferenceNumber`
5
+ * once confirm creates that row. Until then the browser holds a string that has to reach the
6
+ * server, which is what a companion is for (same reason as promotion codes).
7
+ *
8
+ * Leaving it as page state is how Fast Entry confirmed a Check with "abc" on screen and the
9
+ * server refused: `createInitialPayment` only looks at `InitialPaymentDetailID`, and nothing had
10
+ * created that row.
11
+ */
12
+ import { EntityCompanion } from '@memberjunction/core';
13
+ export class InitialPaymentIntentCompanion extends EntityCompanion {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.Name = 'InitialPaymentIntent';
17
+ this.reference = null;
18
+ }
19
+ get Reference() {
20
+ return this.reference;
21
+ }
22
+ set Reference(value) {
23
+ const trimmed = (value ?? '').trim();
24
+ this.reference = trimmed.length ? trimmed : null;
25
+ }
26
+ async Serialize() {
27
+ return this.reference ? { Reference: this.reference } : null;
28
+ }
29
+ async Deserialize(data, _mode) {
30
+ this.Reference = data?.Reference ?? null;
31
+ }
32
+ /**
33
+ * Dirty when a reference is present so a confirm whose only extra fact is the check
34
+ * number still ships the companion. A clean companion would drop it on Save().
35
+ */
36
+ get Dirty() {
37
+ return this.reference != null;
38
+ }
39
+ }
40
+ //# sourceMappingURL=InitialPaymentIntentCompanion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InitialPaymentIntentCompanion.js","sourceRoot":"","sources":["../src/InitialPaymentIntentCompanion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,eAAe,EAAuC,MAAM,sBAAsB,CAAC;AAI5F,MAAM,OAAO,6BAA8B,SAAQ,eAAyC;IAA5F;;QACoB,SAAI,GAAG,sBAAsB,CAAC;QAEtC,cAAS,GAAkB,IAAI,CAAC;IA6B5C,CAAC;IA3BG,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAW,SAAS,CAAC,KAAoB;QACrC,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,SAAS;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,WAAW,CACpB,IAA8B,EAC9B,KAAqC;QAErC,IAAI,CAAC,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,IAAoB,KAAK;QACrB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC;IAClC,CAAC;CACJ"}
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @fileoverview `OrderHeaderEntity` — the order rules that hold on BOTH tiers.
3
+ *
4
+ * WHY THIS LAYER EXISTS
5
+ *
6
+ * Every order rule used to live in `OrderEntityServer`, in a server-only package. That meant the
7
+ * browser could compose an order that the server would refuse, and only find out after a round
8
+ * trip — and it meant a rule enforced "in the order screen" was enforced nowhere at all the moment
9
+ * anything else saved an order. This codebase has found that shape three times.
10
+ *
11
+ * So the rules split by what they NEED, not by where they were written:
12
+ *
13
+ * · Here — anything decidable from the record and its lines alone. No database, no engine, no
14
+ * provider. Runs in the browser before a round trip and again on the server, because the server
15
+ * subclass extends this one and `super.Validate()` still fires.
16
+ * · `OrderEntityServer` — anything that must read or write the database: pricing, promotions,
17
+ * charges and tax, journal entries, subscriptions, sequence numbers.
18
+ *
19
+ * `ClassFactory` priority auto-increments by load order, so the server subclass — registered later
20
+ * because it is loaded later — wins server-side with no configuration, while the browser resolves
21
+ * to this one and keeps the `Lines` collection the generated class declares.
22
+ *
23
+ * WHAT THIS DELIBERATELY DOES NOT DO
24
+ *
25
+ * It does not override `Save()`. A shared class that persisted would have to work on a provider
26
+ * that cannot open a transaction, which is exactly the split that made composite saves server-only
27
+ * before MJ 6.1. Persistence stays with the server subclass; the browser ships the whole graph in
28
+ * one `MJ.SaveEntityGraph` call and the server runs the same executor.
29
+ *
30
+ * @module @mj-biz-apps/orders-entities
31
+ */
32
+ import { ValidationResult, type FieldValueCollection } from '@memberjunction/core';
33
+ import { mjBizAppsOrdersOrderHeaderEntity } from './generated/entity_subclasses.js';
34
+ import { type TransitionVerdict } from './OrderStatusBehavior.js';
35
+ import { PromotionCodesCompanion } from './PromotionCodesCompanion.js';
36
+ import { InitialPaymentIntentCompanion } from './InitialPaymentIntentCompanion.js';
37
+ /** The order editor's sections, in the order the screen shows them. */
38
+ export type OrderEditorSection = 'header' | 'parties' | 'lines' | 'charges' | 'payment';
39
+ export declare class OrderHeaderEntity extends mjBizAppsOrdersOrderHeaderEntity {
40
+ /**
41
+ * Promotion codes the customer presented, riding with the order across the wire.
42
+ *
43
+ * Registered HERE rather than on the server subclass so a browser has it: the whole point is
44
+ * that a code typed on screen reaches the engine. See `PromotionCodesCompanion` for why this is
45
+ * a companion and not a related-record collection — in short, a code has no child row, and only
46
+ * the engine can turn one into an `OrderAdjustment`.
47
+ */
48
+ readonly PromotionCodes: PromotionCodesCompanion;
49
+ /**
50
+ * Check / wire / transfer number typed at entry. Not a column — it rides as a companion
51
+ * and `OrderEntityServer.createInitialPayment` turns it into a `PaymentDetail`.
52
+ */
53
+ readonly InitialPaymentIntent: InitialPaymentIntentCompanion;
54
+ ClearInitialPaymentDetail(): void;
55
+ ClearBillToAddress(): void;
56
+ ClearShipToAddress(): void;
57
+ get InitialPaymentReference(): string | null;
58
+ set InitialPaymentReference(value: string | null);
59
+ private isInitialPaymentDetailEmpty;
60
+ /**
61
+ * True while THIS save is the booking save, and it stays true across `ConfirmedAt` being set.
62
+ *
63
+ * `willBookOnThisSave()` answers "would a save starting now book?", which is the right question
64
+ * everywhere except inside the booking save itself. The server subclass stamps `ConfirmedAt`
65
+ * before it calls `super.Save()`, and `ConfirmedAt` is exactly what makes `willBookOnThisSave()`
66
+ * return false — so validation running inside that `super.Save()` was asking a question whose
67
+ * answer had already been flipped by its own caller, three lines earlier. Every rule gated on it
68
+ * was therefore skipped on the one save it existed to guard.
69
+ *
70
+ * That is why a confirm with zero lines (ORD-000030) and a confirm with no payer (ORD-000028,
71
+ * which posted Dr A/R 99 / Cr Sales 99) both went through. Two separate defects had to coincide
72
+ * — this one and a skipped `ValidateAsync` — and fixing either alone changes nothing, which is
73
+ * why the block looked correct for as long as it did.
74
+ *
75
+ * `protected` because the server subclass sets it around its booking walk.
76
+ */
77
+ protected bookingInFlight: boolean;
78
+ /** True when this save is the first transition into a booked status (plan D8). */
79
+ protected willBookOnThisSave(): boolean;
80
+ /**
81
+ * Whether the status change on this save is a legal move.
82
+ *
83
+ * The PERSISTED status is the `from`: `OldValue` is what is on disk, so re-saving an unchanged
84
+ * row is a no-op transition and a genuine move is measured against what was really there rather
85
+ * than against whatever this object was last set to.
86
+ *
87
+ * `CK_OrderHeader_Status` enforces the legal SET of statuses and nothing enforced the legal
88
+ * MOVES, which is how `Voided → Confirmed` used to save: a voided order came back to life
89
+ * keeping the journal entries its reversal had already unwound.
90
+ */
91
+ /**
92
+ * The lifecycle verdict on this save's status change, with no side effects.
93
+ *
94
+ * Separate from `Validate()` because the server subclass has to ask this question EARLY —
95
+ * before it prices lines, mints an order number or posts anything — while the rest of
96
+ * `Validate()` cannot be asked that early: it includes the generated NOT NULL field checks, and
97
+ * `OrderNumber`, `Company` and each line's `UnitPrice` are all populated by the save itself.
98
+ * Running the whole of `Validate()` up front therefore fails on fields the save was about to
99
+ * fill in.
100
+ */
101
+ protected statusTransitionVerdict(): TransitionVerdict;
102
+ /** The refusal message for an illegal move, shared by `Validate()` and the server's early gate. */
103
+ protected statusTransitionRefusal(verdict: TransitionVerdict): string;
104
+ /**
105
+ * Rules decidable without touching the database.
106
+ *
107
+ * `super.Validate()` fans out to every declared related-record collection, so each line's own
108
+ * `Validate()` runs here too and its failures arrive attributed by position (`Lines[3].Quantity`).
109
+ * That replaces a hand-written loop that only existed on the server.
110
+ */
111
+ NewRecord(newValues?: FieldValueCollection): boolean;
112
+ Validate(): ValidationResult;
113
+ /**
114
+ * `super.Validate()` includes generated NOT NULL checks for fields this save
115
+ * is about to fill in (`OrderNumber`, each new line's `UnitPrice` / `CompanyID`
116
+ * / `LineNumber`). Fast Entry and the editor gate confirm on `Validate()`, so
117
+ * those checks disabled the button on every complete unsaved order.
118
+ *
119
+ * Same reason `OrderEntityServer.Save()` refuses to run the full `Validate()`
120
+ * before it mints the number. After the first save the values exist, so an
121
+ * empty one is a real error and is kept.
122
+ */
123
+ private dropSavePopulatedFieldErrors;
124
+ /** Whether this order is booked to the ledger right now. */
125
+ get IsBookedOrder(): boolean;
126
+ /**
127
+ * True when money composition is frozen: the order was already booked
128
+ * *before* this save. The booking save itself (Draft/Quoted → Confirmed)
129
+ * must still write the figures it just computed. A brand-new unsaved row
130
+ * is never locked, including back-office create-as-Confirmed.
131
+ */
132
+ get MoneyLocked(): boolean;
133
+ /**
134
+ * Refuse adds / removes / reprices / tender restatements after booking.
135
+ * The booking save itself still has to write the figures it just computed.
136
+ */
137
+ private refuseBookedMoneyEdits;
138
+ /**
139
+ * Which editing SECTION each validation failure belongs to.
140
+ *
141
+ * The order editor shows errors against the section that owns the field — an unreachable payer
142
+ * lights up "parties", a bad quantity lights up "lines" — so the user is stopped at the field
143
+ * they can fix rather than at a rejection after the fact.
144
+ *
145
+ * This lives on the shared subclass because it is metadata-only: it reads the `Source` a
146
+ * `ValidationErrorInfo` already carries and maps it to a section. No database, no provider, so
147
+ * the browser gets it for free and the server does not need it at all.
148
+ *
149
+ * It replaces `OrderDraft.SectionsWithErrors`, which computed the same thing from a parallel
150
+ * model of the order that had to be kept in step with the entity by hand.
151
+ */
152
+ static SectionForField(source: string | null | undefined): OrderEditorSection;
153
+ /**
154
+ * The sections currently holding at least one error, for the editor's section chrome.
155
+ *
156
+ * Runs the real `Validate()` — the same rules the server enforces — so a section cannot light up
157
+ * for a reason the save would not also refuse, and cannot stay quiet for one it would.
158
+ */
159
+ SectionsWithErrors(): OrderEditorSection[];
160
+ /**
161
+ * Save, or throw with the reason the engine gave.
162
+ *
163
+ * WHY THIS IS ON THE ENTITY. It was a method on an Angular service, which
164
+ * `docs/ui-architecture.md` names as the wrong place: "if a method on it loads, saves, validates
165
+ * or maps entity data, it is in the wrong place." The reason it existed at all is the boolean
166
+ * return — `Save()` answers true/false and leaves the reason on `LatestResult`, so every caller
167
+ * wrote the same three lines to turn that into something a person could read. Writing them once
168
+ * is right; writing them in a service is not.
169
+ *
170
+ * A non-Angular host gets this too, which is the test the guidelines actually apply.
171
+ *
172
+ * @throws The engine's own message — never a generic one. "Order ORD-000123 cannot be confirmed
173
+ * without a customer" is actionable; "the order could not be saved" is not.
174
+ */
175
+ SaveOrThrow(): Promise<void>;
176
+ /**
177
+ * Whether the Confirm verb should be offered, and why not if it shouldn't.
178
+ *
179
+ * Status-only half is {@link CanOfferConfirm}. This adds the two facts the
180
+ * screen already knows: a payer, and at least one line. The UI stays dumb —
181
+ * it asks this, then calls {@link Confirm}.
182
+ */
183
+ ConfirmEligibility(): TransitionVerdict;
184
+ /** True when {@link Confirm} is a legal next move from what is on this object. */
185
+ get CanConfirm(): boolean;
186
+ /**
187
+ * Confirm — the irreversible step.
188
+ *
189
+ * Setting the status and saving IS the confirm: the server subclass sees the transition into a
190
+ * booked state and books — journal entries, subscriptions, entitlements, the initial payment —
191
+ * in one transaction, or refuses with a reason and writes nothing.
192
+ *
193
+ * There is no dry run in front of it. Every rule is enforced by the engine itself, and a browser
194
+ * has already run the tier-independent ones through `Validate()`, so the user is told about a
195
+ * missing payer without a round trip.
196
+ */
197
+ Confirm(): Promise<void>;
198
+ /**
199
+ * Load this order and its lines together — the state an editor needs.
200
+ *
201
+ * Two calls and no mapping layer: the object bound to the screen is the object that will be
202
+ * saved. `Lines` is `Load: 'explicit'`, so it has to be asked for; asking here means no caller
203
+ * can forget and then wonder why an order with lines renders as empty.
204
+ *
205
+ * @returns False when the order does not exist, leaving this entity unloaded.
206
+ */
207
+ LoadWithLines(orderHeaderID: string): Promise<boolean>;
208
+ /**
209
+ * Person-level party defaults after a bill-to / ship-to person is set.
210
+ *
211
+ * 1. Copy person bill-to ↔ ship-to when the other side's person is null.
212
+ * 2. For each side that has a person and no org, stamp the longest-lasting
213
+ * active Employee relationship's organization.
214
+ *
215
+ * Does not overwrite an org the user already chose. Skips booked/voided orders.
216
+ */
217
+ ApplyPersonPartyDefaults(changed?: 'BillTo' | 'ShipTo' | 'Both'): Promise<void>;
218
+ /**
219
+ * Stamp BillToOrganizationID or ShipToOrganizationID from the person's longest
220
+ * active Employee relationship when that side's org is still empty.
221
+ */
222
+ AutoPopulateEmployerOrganization(partyRole?: 'ShipTo' | 'BillTo', personID?: string | null): Promise<string | null>;
223
+ }
224
+ //# sourceMappingURL=OrderHeaderEntity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OrderHeaderEntity.d.ts","sourceRoot":"","sources":["../src/OrderHeaderEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAwE,gBAAgB,EAAW,KAAK,oBAAoB,EAAyB,MAAM,sBAAsB,CAAC;AAGzL,OAAO,EAAE,gCAAgC,EAAsC,MAAM,+BAA+B,CAAC;AACrH,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAQhF,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAKxF,qBACa,iBAAkB,SAAQ,gCAAgC;IACnE;;;;;;;OAOG;IACH,SAAgB,cAAc,0BAA6D;IAE3F;;;OAGG;IACH,SAAgB,oBAAoB,gCAAmE;IAEhG,yBAAyB,IAAI,IAAI;IAKjC,kBAAkB,IAAI,IAAI;IAI1B,kBAAkB,IAAI,IAAI;IAIjC,IAAW,uBAAuB,IAAI,MAAM,GAAG,IAAI,CAMlD;IAED,IAAW,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAmBtD;IAED,OAAO,CAAC,2BAA2B;IAanC;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,eAAe,UAAS;IAElC,kFAAkF;IAClF,SAAS,CAAC,kBAAkB,IAAI,OAAO;IAOvC;;;;;;;;;;OAUG;IACH;;;;;;;;;OASG;IACH,SAAS,CAAC,uBAAuB,IAAI,iBAAiB;IAKtD,mGAAmG;IACnG,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM;IAIrE;;;;;;OAMG;IACa,SAAS,CAAC,SAAS,CAAC,EAAE,oBAAoB,GAAG,OAAO;IAapD,QAAQ,IAAI,gBAAgB;IAiF5C;;;;;;;;;OASG;IACH,OAAO,CAAC,4BAA4B;IAcpC,4DAA4D;IAC5D,IAAW,aAAa,IAAI,OAAO,CAElC;IAED;;;;;OAKG;IACH,IAAW,WAAW,IAAI,OAAO,CAIhC;IAED;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA6C9B;;;;;;;;;;;;;OAaG;WACW,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,kBAAkB;IAuBpF;;;;;OAKG;IACI,kBAAkB,IAAI,kBAAkB,EAAE;IAUjD;;;;;;;;;;;;;;OAcG;IACU,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAMzC;;;;;;OAMG;IACI,kBAAkB,IAAI,iBAAiB;IAe9C,kFAAkF;IAClF,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;;;;;;;;OAUG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrC;;;;;;;;OAQG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOnE;;;;;;;;OAQG;IACU,wBAAwB,CAAC,OAAO,GAAE,QAAQ,GAAG,QAAQ,GAAG,MAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBpG;;;OAGG;IACU,gCAAgC,CACzC,SAAS,GAAE,QAAQ,GAAG,QAAmB,EACzC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAqB5B"}