@mj-biz-apps/orders-server 0.0.1 → 5.1.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/LICENSE +183 -0
- package/README.md +40 -2
- package/dist/PaymentWebhookExtension.d.ts +17 -0
- package/dist/PaymentWebhookExtension.d.ts.map +1 -0
- package/dist/PaymentWebhookExtension.js +151 -0
- package/dist/PaymentWebhookExtension.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -0
- package/dist/custom/generate-invoice.action.d.ts +59 -0
- package/dist/custom/generate-invoice.action.d.ts.map +1 -0
- package/dist/custom/generate-invoice.action.js +208 -0
- package/dist/custom/generate-invoice.action.js.map +1 -0
- package/dist/custom/open-payment-intent.action.d.ts +39 -0
- package/dist/custom/open-payment-intent.action.d.ts.map +1 -0
- package/dist/custom/open-payment-intent.action.js +169 -0
- package/dist/custom/open-payment-intent.action.js.map +1 -0
- package/dist/custom/send-document.action.d.ts +78 -0
- package/dist/custom/send-document.action.d.ts.map +1 -0
- package/dist/custom/send-document.action.js +277 -0
- package/dist/custom/send-document.action.js.map +1 -0
- package/dist/generated/class-registrations-manifest.d.ts +7 -0
- package/dist/generated/class-registrations-manifest.d.ts.map +1 -0
- package/dist/generated/class-registrations-manifest.js +7 -0
- package/dist/generated/class-registrations-manifest.js.map +1 -0
- package/dist/generated/generated.d.ts +3520 -0
- package/dist/generated/generated.d.ts.map +1 -0
- package/dist/generated/generated.js +19166 -0
- package/dist/generated/generated.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/services/invoice-renderer.d.ts +80 -0
- package/dist/services/invoice-renderer.d.ts.map +1 -0
- package/dist/services/invoice-renderer.js +103 -0
- package/dist/services/invoice-renderer.js.map +1 -0
- package/package.json +48 -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,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@mj-biz-apps/orders-server`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**The bootstrap.** Its job is to make sure every `@RegisterClass` decorator in this app has actually
|
|
4
|
+
fired before a request is served.
|
|
5
|
+
|
|
6
|
+
## Why it exists
|
|
7
|
+
|
|
8
|
+
MJ resolves entity subclasses and remotable operations through `ClassFactory` at runtime. A
|
|
9
|
+
decorator only registers when its module is **loaded**, and a bundler will happily tree-shake a
|
|
10
|
+
module nothing imports by name. The failure mode is quiet and expensive: `Metadata.GetEntityObject`
|
|
11
|
+
returns the *base* entity, `Save()` writes the row without running a single business rule, and the
|
|
12
|
+
order books with no journal entry.
|
|
13
|
+
|
|
14
|
+
So this package imports the `Load*` anchors explicitly:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
LoadOrderEntityServer();
|
|
18
|
+
LoadRefundPaymentOperation(); // 'Orders.RefundPayment' (D17)
|
|
19
|
+
LoadApplyAccountCreditOperation(); // 'Orders.ApplyAccountCredit' (D68)
|
|
20
|
+
LoadPreviewPriceOperation(); // 'Orders.PreviewPrice' (D69)
|
|
21
|
+
LoadDefaultPriceResolver(); // the resolver the walk falls back to
|
|
22
|
+
LoadPromotionEngine(); // the promotion qualifier seam (D70)
|
|
23
|
+
LoadTaxResolver(); // the address → jurisdiction seam (D73)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Each anchor is an empty exported function. Its only purpose is to be a name a bundler cannot prove
|
|
27
|
+
is unused.
|
|
28
|
+
|
|
29
|
+
**Adding a registered class? Add its anchor here.** Nothing will fail loudly if you forget — the base
|
|
30
|
+
class will be used instead, and the first symptom is a financial one.
|
|
31
|
+
|
|
32
|
+
## Also here
|
|
33
|
+
|
|
34
|
+
- `config.ts` — server configuration
|
|
35
|
+
- `src/generated/` — CodeGen's GraphQL resolvers. Do not edit; see the Entities package README.
|
|
36
|
+
|
|
37
|
+
## Verifying registration
|
|
38
|
+
|
|
39
|
+
The integration suite is the real check: it resolves entities through the same `ClassFactory` a
|
|
40
|
+
request does, so a missing anchor shows up as a rule not running. If a check fails in a way that
|
|
41
|
+
looks like "the guard didn't fire", suspect a missing anchor before suspecting the guard.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import { BaseServerExtension, type ExtensionHealthResult, type ExtensionInitResult, type ServerExtensionConfig } from '@memberjunction/server-extensions-core';
|
|
3
|
+
export declare class PaymentWebhookExtension extends BaseServerExtension {
|
|
4
|
+
Initialize(app: Application, config: ServerExtensionConfig): Promise<ExtensionInitResult>;
|
|
5
|
+
Shutdown(): Promise<void>;
|
|
6
|
+
HealthCheck(): Promise<ExtensionHealthResult>;
|
|
7
|
+
/**
|
|
8
|
+
* The user the webhook's writes are attributed to.
|
|
9
|
+
*
|
|
10
|
+
* Returns undefined rather than throwing, so the caller decides the status code. Looked up fresh
|
|
11
|
+
* each time: the metadata provider may not have been ready when this extension initialised.
|
|
12
|
+
*/
|
|
13
|
+
private resolveSystemUser;
|
|
14
|
+
}
|
|
15
|
+
/** Tree-shaking anchor — call from the server bootstrap so @RegisterClass is retained. */
|
|
16
|
+
export declare function LoadPaymentWebhookExtension(): void;
|
|
17
|
+
//# sourceMappingURL=PaymentWebhookExtension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentWebhookExtension.d.ts","sourceRoot":"","sources":["../src/PaymentWebhookExtension.ts"],"names":[],"mappings":"AA4CA,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAC;AAI9D,OAAO,EACH,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC7B,MAAM,wCAAwC,CAAC;AAMhD,qBACa,uBAAwB,SAAQ,mBAAmB;IAC/C,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA6CzF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,WAAW,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAgB1D;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CAS5B;AAmBD,0FAA0F;AAC1F,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}
|
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
* The route that lets a gateway tell us money moved — finally mounted.
|
|
9
|
+
*
|
|
10
|
+
* `MountPaymentWebhook` has existed since the payment drivers landed and was called by nobody. That was
|
|
11
|
+
* survivable while every provider settled synchronously: a card capture books at the moment it is
|
|
12
|
+
* asked, so the webhook only ever confirmed something already recorded, and its absence cost a little
|
|
13
|
+
* reconciliation detail. It stops being survivable the instant a bank debit is configured. A debit is
|
|
14
|
+
* captured BY the webhook — there is no other moment at which the money is known to have arrived — so
|
|
15
|
+
* without this route every ACH payment sits `Pending` for ever and no cash is ever booked.
|
|
16
|
+
*
|
|
17
|
+
* WHY AN EXTENSION AND NOT A CHANGE TO MJ. MJServer loads `serverExtensions[]` from `mj.config.cjs`
|
|
18
|
+
* BEFORE it installs the auth middleware, which is precisely the window an unauthenticated webhook
|
|
19
|
+
* needs. So the route can be mounted from this repo, in this app's own config, with no upstream change
|
|
20
|
+
* — and an operator can turn it off by flipping `Enabled` rather than by redeploying.
|
|
21
|
+
*
|
|
22
|
+
* ═══ TWO THINGS THE MOUNT MUST GET RIGHT, both of them silent when wrong ═══
|
|
23
|
+
*
|
|
24
|
+
* BEFORE AUTH. Stripe presents no bearer token; the signature IS the credential. Behind the auth
|
|
25
|
+
* middleware every delivery would be rejected with a 401 that Stripe retries and eventually gives up
|
|
26
|
+
* on, and the only symptom is payments that never capture.
|
|
27
|
+
*
|
|
28
|
+
* RAW BODY, ON THIS PATH ONLY. The signature covers the exact bytes sent. Any JSON round-trip — key
|
|
29
|
+
* reordering, whitespace, unicode normalisation — changes them, so a `express.json()` upstream turns
|
|
30
|
+
* every legitimate webhook into a signature failure. `express.raw()` is scoped to this route so it
|
|
31
|
+
* cannot affect anything else the app serves.
|
|
32
|
+
*
|
|
33
|
+
* THE PROVIDER ID IS IN THE PATH, and one endpoint per configured provider is deliberate. It is what
|
|
34
|
+
* tells the handler WHICH secret to verify against before it has read a byte of the payload — a single
|
|
35
|
+
* shared endpoint would have to parse untrusted JSON to work out whose signature to check, which is
|
|
36
|
+
* the one thing `HandlePaymentWebhook` is ordered to avoid.
|
|
37
|
+
*
|
|
38
|
+
* THE SYSTEM USER, AND WHY IT IS RESOLVED PER REQUEST. There is no human behind a webhook, so the
|
|
39
|
+
* writes are attributed to MJ's system user — the same one MJ's own unauthenticated eSignature webhook
|
|
40
|
+
* uses, via the same `UserCache`, rather than a bespoke email setting this app would then have to keep
|
|
41
|
+
* correct. It is looked up on each delivery rather than cached at startup because the extension
|
|
42
|
+
* initialises before the data provider is necessarily ready, and a user captured too early would be
|
|
43
|
+
* absent for the lifetime of the process.
|
|
44
|
+
*
|
|
45
|
+
* CONNECTS TO:
|
|
46
|
+
* HANDLER: @mj-biz-apps/orders-core-entities-server → PaymentWebhookHandler
|
|
47
|
+
* CONFIG: mj.config.cjs → serverExtensions[]
|
|
48
|
+
* DOC: plans/archive/bizapps-orders-master.md D19
|
|
49
|
+
*/
|
|
50
|
+
import BodyParser from 'body-parser';
|
|
51
|
+
import { LogError, LogStatus, Metadata } from '@memberjunction/core';
|
|
52
|
+
import { UserCache } from '@memberjunction/generic-database-provider';
|
|
53
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
54
|
+
import { BaseServerExtension, } from '@memberjunction/server-extensions-core';
|
|
55
|
+
import { MountPaymentWebhook } from '@mj-biz-apps/orders-core-entities-server';
|
|
56
|
+
/** Stripe's largest documented event payload is well under this; the cap keeps the door narrow. */
|
|
57
|
+
const MAX_BODY = '1mb';
|
|
58
|
+
let PaymentWebhookExtension = class PaymentWebhookExtension extends BaseServerExtension {
|
|
59
|
+
async Initialize(app, config) {
|
|
60
|
+
const route = `${config.RootPath.replace(/\/+$/, '')}/:providerId`;
|
|
61
|
+
app.post(route,
|
|
62
|
+
// RAW, and scoped to this path. See the header — a JSON parser anywhere upstream of this
|
|
63
|
+
// invalidates every signature.
|
|
64
|
+
BodyParser.raw({ type: 'application/json', limit: MAX_BODY }), async (req, res) => {
|
|
65
|
+
const user = this.resolveSystemUser();
|
|
66
|
+
if (!user) {
|
|
67
|
+
// 500, NOT 400. The gateway did nothing wrong and the event is real — this is our
|
|
68
|
+
// configuration being incomplete, and a 4xx would tell Stripe to stop retrying a
|
|
69
|
+
// notification we very much want back once someone fixes it.
|
|
70
|
+
LogError('A payment webhook arrived but MJ\'s system user could not be resolved, so it ' +
|
|
71
|
+
'cannot be recorded. The user cache is not populated — this is a startup ' +
|
|
72
|
+
'problem, not a problem with the delivery.');
|
|
73
|
+
res.status(500).json({ received: false });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const handler = MountPaymentWebhook(() => ({ provider: Metadata.Provider, user }));
|
|
77
|
+
await handler({
|
|
78
|
+
body: req.body,
|
|
79
|
+
headers: flattenHeaders(req.headers),
|
|
80
|
+
// Only the one parameter the handler reads, narrowed to a string here rather
|
|
81
|
+
// than passed through as Express's `string | string[]` dictionary.
|
|
82
|
+
params: { providerId: String(req.params?.providerId ?? '') },
|
|
83
|
+
}, res);
|
|
84
|
+
});
|
|
85
|
+
LogStatus(`[Orders] Payment webhook route registered at POST ${route}`);
|
|
86
|
+
return {
|
|
87
|
+
Success: true,
|
|
88
|
+
Message: 'Orders payment webhook mounted (unauthenticated, raw body, signature-verified).',
|
|
89
|
+
RegisteredRoutes: [`POST ${route}`],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async Shutdown() {
|
|
93
|
+
// Nothing held open — the route owns no connections, timers or sockets.
|
|
94
|
+
}
|
|
95
|
+
async HealthCheck() {
|
|
96
|
+
// Healthy means "this route can do its job", which is exactly "the system user resolves".
|
|
97
|
+
// Reporting healthy without checking would hide the one misconfiguration that silently drops
|
|
98
|
+
// real payment notifications.
|
|
99
|
+
const user = this.resolveSystemUser();
|
|
100
|
+
return user
|
|
101
|
+
? { Healthy: true, Name: 'OrdersPaymentWebhook' }
|
|
102
|
+
: {
|
|
103
|
+
Healthy: false,
|
|
104
|
+
Name: 'OrdersPaymentWebhook',
|
|
105
|
+
Details: {
|
|
106
|
+
Reason: 'MJ\'s system user does not resolve, so every webhook delivery will be refused.',
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The user the webhook's writes are attributed to.
|
|
112
|
+
*
|
|
113
|
+
* Returns undefined rather than throwing, so the caller decides the status code. Looked up fresh
|
|
114
|
+
* each time: the metadata provider may not have been ready when this extension initialised.
|
|
115
|
+
*/
|
|
116
|
+
resolveSystemUser() {
|
|
117
|
+
try {
|
|
118
|
+
return UserCache.Instance.GetSystemUser() ?? undefined;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// The cache is not populated yet. Undefined rather than a throw, so the caller can answer
|
|
122
|
+
// 500 and the gateway retries once startup has finished.
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
PaymentWebhookExtension = __decorate([
|
|
128
|
+
RegisterClass(BaseServerExtension, 'OrdersPaymentWebhook')
|
|
129
|
+
], PaymentWebhookExtension);
|
|
130
|
+
export { PaymentWebhookExtension };
|
|
131
|
+
/**
|
|
132
|
+
* Express types a header value as `string | string[]` because a header CAN legitimately repeat.
|
|
133
|
+
*
|
|
134
|
+
* The handler wants a flat map, and the flattening matters for exactly one header: `stripe-signature`.
|
|
135
|
+
* Joining a repeated value with a comma would be right by luck — Stripe's own scheme is already
|
|
136
|
+
* comma-separated (`t=…,v1=…,v1=…`) so a proxy that split it across two headers rejoins correctly —
|
|
137
|
+
* whereas taking the first would silently drop half a signature during a secret rotation and fail
|
|
138
|
+
* verification for events that are perfectly valid.
|
|
139
|
+
*/
|
|
140
|
+
function flattenHeaders(headers) {
|
|
141
|
+
const flat = {};
|
|
142
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
143
|
+
flat[key] = Array.isArray(value) ? value.join(',') : value;
|
|
144
|
+
}
|
|
145
|
+
return flat;
|
|
146
|
+
}
|
|
147
|
+
/** Tree-shaking anchor — call from the server bootstrap so @RegisterClass is retained. */
|
|
148
|
+
export function LoadPaymentWebhookExtension() {
|
|
149
|
+
// intentionally empty
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=PaymentWebhookExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentWebhookExtension.js","sourceRoot":"","sources":["../src/PaymentWebhookExtension.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC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ED;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,OAA2B;IAC/C,MAAM,IAAI,GAAuC,EAAE,CAAC;IACpD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,2BAA2B;IACvC,sBAAsB;AAC1B,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc,SAAS,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `Orders: Generate Invoice` — hand it any order, get back the document you send the
|
|
3
|
+
* customer.
|
|
4
|
+
*
|
|
5
|
+
* WHY AN ACTION AND NOT A REMOTE OPERATION. The other order verbs — confirm, capture, fulfil — are
|
|
6
|
+
* operations because they are the API a browser calls to change something. This one changes
|
|
7
|
+
* nothing, and its callers are different in kind: a workflow that emails a bill on confirmation, an
|
|
8
|
+
* agent asked to "send Contoso their invoice", a scheduled job producing a month's PDFs, a person
|
|
9
|
+
* clicking Print. Actions are the surface all four already speak, and they are discoverable in
|
|
10
|
+
* metadata rather than only from code.
|
|
11
|
+
*
|
|
12
|
+
* WHAT IT COMPOSES. This class does no arithmetic, no formatting and no markup. It resolves inputs,
|
|
13
|
+
* calls the reader, the display layer and the template engine in that order, and hands back what
|
|
14
|
+
* they produced:
|
|
15
|
+
*
|
|
16
|
+
* `InvoiceBuilder` → the document, per selling company, derived from the order
|
|
17
|
+
* `InvoiceDisplay` → the strings, so the template can print without computing
|
|
18
|
+
* MJ Templates → the HTML, editable in the database with no deploy
|
|
19
|
+
*
|
|
20
|
+
* IT RETURNS THE DATA ALONGSIDE THE HTML. A caller that wants a PDF renders the HTML; a caller
|
|
21
|
+
* doing a reconciliation check wants the numbers, and making it scrape them back out of markup
|
|
22
|
+
* would be a guarantee that the check and the document eventually disagree.
|
|
23
|
+
*
|
|
24
|
+
* IT NEVER WRITES. There is no invoice record — the confirmed order IS the receivable — so
|
|
25
|
+
* rendering the same order twice produces two identical documents. See the header of
|
|
26
|
+
* `InvoiceBehavior` for why storing one would be a mistake, and why statements are the opposite
|
|
27
|
+
* case.
|
|
28
|
+
*
|
|
29
|
+
* @module @mj-biz-apps/orders-actions
|
|
30
|
+
*/
|
|
31
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
32
|
+
import type { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
33
|
+
export { DEFAULT_INVOICE_TEMPLATE } from '../services/invoice-renderer.js';
|
|
34
|
+
export type { RenderedInvoice } from '../services/invoice-renderer.js';
|
|
35
|
+
/**
|
|
36
|
+
* Render an order as an invoice, quote or credit memo.
|
|
37
|
+
*
|
|
38
|
+
* Inputs: `OrderID` (required), `CompanyID`, `AsOfDate`, `TemplateName`, `Locale`, `CurrencyCode`,
|
|
39
|
+
* `Format`, `ShowDiagnostics`. Outputs: `Invoices`, `HTML`, `DocumentCount`, `Notes`.
|
|
40
|
+
*/
|
|
41
|
+
export declare class GenerateInvoiceAction extends BaseAction {
|
|
42
|
+
/**
|
|
43
|
+
* AN ACTION MUST NOT THROW AT ITS CALLER. The layers below guard their inputs by throwing —
|
|
44
|
+
* `RequireUUID` is what keeps an id out of a SQL string — and a workflow, an agent or a print
|
|
45
|
+
* button calling this gets an exception rather than a result it can branch on. So the whole body
|
|
46
|
+
* runs behind this, and every failure comes back as a Success=false with a code.
|
|
47
|
+
*/
|
|
48
|
+
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
49
|
+
private render;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Registers {@link GenerateInvoiceAction}.
|
|
53
|
+
*
|
|
54
|
+
* WITHOUT THIS ANCHOR the class is tree-shaken out of the bundle, the `@RegisterClass` decorator
|
|
55
|
+
* never runs, and `ActionEngine` falls back to no implementation — which surfaces as an action that
|
|
56
|
+
* exists in metadata and does nothing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function LoadGenerateInvoiceAction(): void;
|
|
59
|
+
//# sourceMappingURL=generate-invoice.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-invoice.action.d.ts","sourceRoot":"","sources":["../../src/custom/generate-invoice.action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAe,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAWrG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,YAAY,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAmCvE;;;;;GAKG;AACH,qBACa,qBAAsB,SAAQ,UAAU;IACjD;;;;;OAKG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;YAYzE,MAAM;CAwGvB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
|