@mj-biz-apps/orders-server 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 (71) hide show
  1. package/LICENSE +183 -0
  2. package/README.md +47 -2
  3. package/dist/CheckoutServerExtension.d.ts +96 -0
  4. package/dist/CheckoutServerExtension.d.ts.map +1 -0
  5. package/dist/CheckoutServerExtension.js +554 -0
  6. package/dist/CheckoutServerExtension.js.map +1 -0
  7. package/dist/PaymentWebhookExtension.d.ts +17 -0
  8. package/dist/PaymentWebhookExtension.d.ts.map +1 -0
  9. package/dist/PaymentWebhookExtension.js +151 -0
  10. package/dist/PaymentWebhookExtension.js.map +1 -0
  11. package/dist/__tests__/CheckoutServerExtension.test.d.ts +2 -0
  12. package/dist/__tests__/CheckoutServerExtension.test.d.ts.map +1 -0
  13. package/dist/__tests__/CheckoutServerExtension.test.js +257 -0
  14. package/dist/__tests__/CheckoutServerExtension.test.js.map +1 -0
  15. package/dist/__tests__/checkout-edge-policy.test.d.ts +2 -0
  16. package/dist/__tests__/checkout-edge-policy.test.d.ts.map +1 -0
  17. package/dist/__tests__/checkout-edge-policy.test.js +70 -0
  18. package/dist/__tests__/checkout-edge-policy.test.js.map +1 -0
  19. package/dist/__tests__/checkout-host-page.test.d.ts +2 -0
  20. package/dist/__tests__/checkout-host-page.test.d.ts.map +1 -0
  21. package/dist/__tests__/checkout-host-page.test.js +86 -0
  22. package/dist/__tests__/checkout-host-page.test.js.map +1 -0
  23. package/dist/__tests__/server-extensions-manifest.test.d.ts +2 -0
  24. package/dist/__tests__/server-extensions-manifest.test.d.ts.map +1 -0
  25. package/dist/__tests__/server-extensions-manifest.test.js +29 -0
  26. package/dist/__tests__/server-extensions-manifest.test.js.map +1 -0
  27. package/dist/checkout-edge-policy.d.ts +44 -0
  28. package/dist/checkout-edge-policy.d.ts.map +1 -0
  29. package/dist/checkout-edge-policy.js +84 -0
  30. package/dist/checkout-edge-policy.js.map +1 -0
  31. package/dist/checkout-host-page.d.ts +43 -0
  32. package/dist/checkout-host-page.d.ts.map +1 -0
  33. package/dist/checkout-host-page.js +445 -0
  34. package/dist/checkout-host-page.js.map +1 -0
  35. package/dist/config.d.ts +6 -0
  36. package/dist/config.d.ts.map +1 -0
  37. package/dist/config.js +6 -0
  38. package/dist/config.js.map +1 -0
  39. package/dist/custom/generate-invoice.action.d.ts +59 -0
  40. package/dist/custom/generate-invoice.action.d.ts.map +1 -0
  41. package/dist/custom/generate-invoice.action.js +208 -0
  42. package/dist/custom/generate-invoice.action.js.map +1 -0
  43. package/dist/custom/open-payment-intent.action.d.ts +39 -0
  44. package/dist/custom/open-payment-intent.action.d.ts.map +1 -0
  45. package/dist/custom/open-payment-intent.action.js +169 -0
  46. package/dist/custom/open-payment-intent.action.js.map +1 -0
  47. package/dist/custom/send-document.action.d.ts +78 -0
  48. package/dist/custom/send-document.action.d.ts.map +1 -0
  49. package/dist/custom/send-document.action.js +277 -0
  50. package/dist/custom/send-document.action.js.map +1 -0
  51. package/dist/generated/class-registrations-manifest.d.ts +7 -0
  52. package/dist/generated/class-registrations-manifest.d.ts.map +1 -0
  53. package/dist/generated/class-registrations-manifest.js +7 -0
  54. package/dist/generated/class-registrations-manifest.js.map +1 -0
  55. package/dist/generated/generated.d.ts +3536 -0
  56. package/dist/generated/generated.d.ts.map +1 -0
  57. package/dist/generated/generated.js +18371 -0
  58. package/dist/generated/generated.js.map +1 -0
  59. package/dist/index.d.ts +28 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +105 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/server-extensions-manifest.d.ts +14 -0
  64. package/dist/server-extensions-manifest.d.ts.map +1 -0
  65. package/dist/server-extensions-manifest.js +15 -0
  66. package/dist/server-extensions-manifest.js.map +1 -0
  67. package/dist/services/invoice-renderer.d.ts +80 -0
  68. package/dist/services/invoice-renderer.d.ts.map +1 -0
  69. package/dist/services/invoice-renderer.js +103 -0
  70. package/dist/services/invoice-renderer.js.map +1 -0
  71. package/package.json +65 -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,48 @@
1
- # @mj-biz-apps/orders-server
1
+ # `@mj-biz-apps/orders-server`
2
2
 
3
- Placeholder release. See https://github.com/MemberJunction/bizapps-orders
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
+ - `MJ_SERVER_EXTENSIONS` — webhook + checkout edge declarations. MJ bootstrap collects this
37
+ (or `package.json` `memberjunction.serverExtensions`) from hosts that list this package in
38
+ `dynamicPackages.server[]`. Host `mj.config.cjs` `serverExtensions[]` overlays by DriverClass.
39
+ - `GET /checkout/:slug` — public HTML host for a distribution; POSTs stay on the same edge.
40
+ Pre-auth. Host `serverExtensions[]` can set `Enabled: false` to suppress. Settings:
41
+ `TrustedProxyHops` (default 0 — ignore `X-Forwarded-For`; set to the number of reverse
42
+ proxies that append to it), `RateLimitMax` / `RateLimitMaxGlobal`.
43
+
44
+ ## Verifying registration
45
+
46
+ The integration suite is the real check: it resolves entities through the same `ClassFactory` a
47
+ request does, so a missing anchor shows up as a rule not running. If a check fails in a way that
48
+ looks like "the guard didn't fire", suspect a missing anchor before suspecting the guard.
@@ -0,0 +1,96 @@
1
+ import type { Application } from 'express';
2
+ import { BaseServerExtension, type ExtensionHealthResult, type ExtensionInitResult, type ServerExtensionConfig } from '@memberjunction/server-extensions-core';
3
+ interface CheckoutEdgeSettings {
4
+ /** Email of the named checkout service principal; falls back to the system user. */
5
+ ServiceUserEmail?: string;
6
+ /** Name of the env var holding the Cloudflare Turnstile secret. */
7
+ TurnstileSecretEnvVar?: string;
8
+ /** Rate-limit window in ms (default 60000). */
9
+ RateLimitWindowMs?: number;
10
+ /** Max requests per window per client key (default 30). */
11
+ RateLimitMax?: number;
12
+ /**
13
+ * Aggregate max per IP per window across all slugs (default 90).
14
+ * Independent of the per-slug cap.
15
+ */
16
+ RateLimitMaxGlobal?: number;
17
+ /**
18
+ * Number of reverse proxies that append to X-Forwarded-For. 0 (default)
19
+ * ignores XFF and uses the socket address — the leftmost XFF hop is
20
+ * client-supplied and must not key rate limits or Turnstile.
21
+ */
22
+ TrustedProxyHops?: number;
23
+ /**
24
+ * When true, GET `{root}/element/main.js.map` is registered. Default off —
25
+ * the map is original TypeScript on an unauthenticated payment route.
26
+ * Also honoured via env `CHECKOUT_ELEMENT_SOURCEMAP=1` when the setting is unset.
27
+ */
28
+ ServeElementSourceMap?: boolean;
29
+ }
30
+ /** Source maps on the public checkout element are opt-in (dev). Default: do not serve. */
31
+ export declare function shouldServeCheckoutElementSourceMap(settings: Pick<CheckoutEdgeSettings, 'ServeElementSourceMap'>, env?: NodeJS.ProcessEnv): boolean;
32
+ export declare class CheckoutServerExtension extends BaseServerExtension {
33
+ private settings;
34
+ private rateWindows;
35
+ private warnedSystemUserFallback;
36
+ private rootPath;
37
+ private lastReapAt;
38
+ Initialize(app: Application, config: ServerExtensionConfig): Promise<ExtensionInitResult>;
39
+ Shutdown(): Promise<void>;
40
+ HealthCheck(): Promise<ExtensionHealthResult>;
41
+ /** Runs the shared gates (rate limit → origin → turnstile where required) then the handler. */
42
+ private guardAndRun;
43
+ /** OPTIONS preflight: grant CORS only to origins the widget policy allows. */
44
+ private handlePreflight;
45
+ /**
46
+ * Resolves the widget edge policy (allowed origins + turnstile requirement) for this
47
+ * request — by slug on initialize, by session id on the other routes. Returns null when
48
+ * nothing resolves (unknown slug/session): the underlying service will answer with its
49
+ * own refusal.
50
+ */
51
+ private resolveEdgePolicy;
52
+ /** Enforces the per-widget origin allowlist; grants CORS to allowed origins. */
53
+ private applyOriginGate;
54
+ private originAllowed;
55
+ private setCorsHeaders;
56
+ /** Turnstile applies to the abuse-sensitive endpoints: initialize and complete. */
57
+ private isTurnstileGatedPath;
58
+ /**
59
+ * Verifies the Cloudflare Turnstile token. Returns null on success, or [status, message]
60
+ * on refusal. A widget that REQUIRES Turnstile with no secret configured fails closed
61
+ * with a 503 — a silent pass would advertise protection that is not running.
62
+ */
63
+ private verifyTurnstile;
64
+ /**
65
+ * `GET /checkout/:slug` — first-party HTML that talks to the POST edge.
66
+ * Unknown/reserved slugs 404; missing service principal is a 503. The page
67
+ * itself is cache-free; initialize still enforces Active widget + distribution.
68
+ */
69
+ private handleGetHost;
70
+ private sendHostError;
71
+ private applyHostSecurityHeaders;
72
+ private maybeReapExpiredSessions;
73
+ private requestSlug;
74
+ private activeDistributionExists;
75
+ private handleInitialize;
76
+ private handleDraft;
77
+ private handlePaymentIntent;
78
+ private handleComplete;
79
+ /** Fixed-window limiter over a bounded, insertion-ordered map. */
80
+ private rateLimitExceeded;
81
+ /**
82
+ * The client IP for rate limiting and Turnstile. Ignores X-Forwarded-For unless
83
+ * `Settings.TrustedProxyHops` is a positive integer (Nth-from-right hop).
84
+ */
85
+ private clientIp;
86
+ /**
87
+ * The acting principal for checkout writes: the configured service user when present,
88
+ * else MJ's system user (warned once). Resolved per request — the user cache may not be
89
+ * populated when the extension initializes.
90
+ */
91
+ private resolveActingUser;
92
+ }
93
+ /** Tree-shaking anchor — call from the server bootstrap so @RegisterClass is retained. */
94
+ export declare function LoadCheckoutServerExtension(): void;
95
+ export {};
96
+ //# sourceMappingURL=CheckoutServerExtension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckoutServerExtension.d.ts","sourceRoot":"","sources":["../src/CheckoutServerExtension.ts"],"names":[],"mappings":"AAmDA,OAAO,KAAK,EAAE,WAAW,EAAmC,MAAM,SAAS,CAAC;AAI5E,OAAO,EACH,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC7B,MAAM,wCAAwC,CAAC;AAuDhD,UAAU,oBAAoB;IAC1B,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,0FAA0F;AAC1F,wBAAgB,mCAAmC,CAC/C,QAAQ,EAAE,IAAI,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,EAC7D,GAAG,GAAE,MAAM,CAAC,UAAwB,GACrC,OAAO,CAQT;AAOD,qBACa,uBAAwB,SAAQ,mBAAmB;IAC5D,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,WAAW,CAA6D;IAChF,OAAO,CAAC,wBAAwB,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,UAAU,CAAK;IAEV,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA+CzF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,WAAW,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAa1D,+FAA+F;YACjF,WAAW;IAyCzB,8EAA8E;YAChE,eAAe;IAe7B;;;;;OAKG;YACW,iBAAiB;IAsD/B,gFAAgF;IAChF,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAQtB,mFAAmF;IACnF,OAAO,CAAC,oBAAoB;IAI5B;;;;OAIG;YACW,eAAe;IA6B7B;;;;OAIG;YACW,aAAa;IA4C3B,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,wBAAwB;IAWhC,OAAO,CAAC,WAAW;YAOL,wBAAwB;YAaxB,gBAAgB;YAahB,WAAW;YAcX,mBAAmB;YAYnB,cAAc;IAc5B,kEAAkE;IAClE,OAAO,CAAC,iBAAiB;IAkBzB;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;CAkB5B;AAED,0FAA0F;AAC1F,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}