@huloglobal/vendure-plugin-quotations 0.9.0 → 0.10.1
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/CHANGELOG.md +62 -0
- package/README.md +57 -0
- package/dist/client-ip.d.ts +59 -0
- package/dist/client-ip.d.ts.map +1 -0
- package/dist/client-ip.js +145 -0
- package/dist/client-ip.js.map +1 -0
- package/dist/email-layout.d.ts +104 -0
- package/dist/email-layout.d.ts.map +1 -0
- package/dist/email-layout.js +250 -0
- package/dist/email-layout.js.map +1 -0
- package/dist/emails.d.ts +57 -0
- package/dist/emails.d.ts.map +1 -0
- package/dist/emails.js +124 -0
- package/dist/emails.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/payment.service.d.ts.map +1 -1
- package/dist/payment.service.js +4 -1
- package/dist/payment.service.js.map +1 -1
- package/dist/pdf.d.ts.map +1 -1
- package/dist/pdf.js +18 -9
- package/dist/pdf.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -1
- package/dist/pricing.d.ts +58 -3
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +90 -9
- package/dist/pricing.js.map +1 -1
- package/dist/pro.service.d.ts.map +1 -1
- package/dist/pro.service.js +25 -5
- package/dist/pro.service.js.map +1 -1
- package/dist/quotation.controller.d.ts +5 -3
- package/dist/quotation.controller.d.ts.map +1 -1
- package/dist/quotation.controller.js +30 -27
- package/dist/quotation.controller.js.map +1 -1
- package/dist/quotation.service.d.ts +31 -5
- package/dist/quotation.service.d.ts.map +1 -1
- package/dist/quotation.service.js +161 -38
- package/dist/quotation.service.js.map +1 -1
- package/dist/quote-version.d.ts.map +1 -1
- package/dist/quote-version.js +3 -0
- package/dist/quote-version.js.map +1 -1
- package/dist/rate-limit.d.ts +15 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +35 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/templates.d.ts +0 -3
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +2 -39
- package/dist/templates.js.map +1 -1
- package/dist/types.d.ts +20 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/dist/types.js.map +1 -1
- package/package.json +5 -5
- package/ui/components/quotations.component.ts +51 -15
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,68 @@ documented here. The format follows
|
|
|
5
5
|
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project
|
|
6
6
|
adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.10.1] — 2026-11-29
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **VAT was added twice on channels whose prices include tax.** A storefront request was priced from the
|
|
12
|
+
channel's variant price, which on a *prices include tax* channel already carries VAT, and 20% was then
|
|
13
|
+
added on top (a basket of £834.42 inc. VAT became a £1,001.30 quote). Quotes now have a
|
|
14
|
+
`pricesIncludeTax` setting: a request, and a new admin quote, follow the channel. On a VAT-inclusive quote
|
|
15
|
+
the lines and a fixed discount are gross, the total is the basket total exactly, and the VAT inside it is
|
|
16
|
+
split out (net = total ÷ (1 + rate)); `subTotalPence`/`discountPence` stay ex-VAT and
|
|
17
|
+
subtotal − discount + VAT = total, so conversion, the order surcharge, deposits, reports, webhooks and
|
|
18
|
+
events read them as before. The quote page, the PDF and the admin show "Unit inc. VAT", "Subtotal (inc.
|
|
19
|
+
VAT)", "Total" and "Includes VAT (x%)". Converting such a quote adds no VAT surcharge (the draft order
|
|
20
|
+
already matches), and the checkout re-balance ignores Vendure's per-line net rounding.
|
|
21
|
+
- **Requests use the variant's VAT rate** (its tax category in the channel's default tax zone) instead of
|
|
22
|
+
the quote default; a request mixing rates uses the rate covering the most value and the trail asks staff
|
|
23
|
+
to check it.
|
|
24
|
+
- **The per-IP request limit counted the storefront server, not the shopper,** when a storefront relays
|
|
25
|
+
requests server-side, so ten requests an hour were shared by every visitor. New option
|
|
26
|
+
`trustedClientIp: { secret, header?, secretHeader?, trustedProxies? }`: `x-real-client-ip` is believed only
|
|
27
|
+
with the shared secret (header `x-quotations-proxy` by default, or HULO Checkout Guard's
|
|
28
|
+
`x-checkout-guard-proxy`) and, if listed, from a trusted peer. Off by default. The counted address is
|
|
29
|
+
stored on the quote (`requestIp`).
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Existing quotes are not changed: they keep `pricesIncludeTax = 0`, as they were priced. Requests that
|
|
33
|
+
nobody has edited or sent yet (status *requested*) on a VAT-inclusive channel are re-priced once at start-up,
|
|
34
|
+
with a "repriced" trail entry showing the old and new totals. Quotes already sent are left as they are.
|
|
35
|
+
- Templates saved before this release stay ex-VAT; new templates carry the quote's setting.
|
|
36
|
+
- The acceptance fingerprint is unchanged for ex-VAT quotes (the setting is added only when it is on).
|
|
37
|
+
|
|
38
|
+
## [0.10.0] — 2026-11-16
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
- **Every e-mail restyled to one shared design:** a 600px white card on a light grey background, the store's
|
|
42
|
+
logo (or its name) over a 3px accent bar, a clear heading, the quote's reference, validity and total in a
|
|
43
|
+
summary box, a button, a "Kind regards" sign-off with the store's reply-to address, and a footer strip with
|
|
44
|
+
the store's address, phone, website and footer note. Inline styles and tables only, every value escaped,
|
|
45
|
+
and every message now has a plain-text part. It uses the existing **Accent colour**, **Logo URL** and
|
|
46
|
+
footer settings, so nothing needs setting up. Restyled: the quote e-mail, test sends (now with a "Test
|
|
47
|
+
send" warning box), the chaser, the expiry reminder (its heading names the date), follow-up steps, the
|
|
48
|
+
pay-link e-mails for the whole amount, a deposit or the balance (the pay button plus a secondary "View
|
|
49
|
+
your quotation" button, and the amount due now), and the request acknowledgement (which had no HTML
|
|
50
|
+
part). Store notifications (new request, first view, accepted, declined) and discount-approval requests
|
|
51
|
+
and outcomes use the same design, more compact; they were plain text. The weekly report uses the shared
|
|
52
|
+
design from the licence SDK 0.15.7 with the store's logo and accent colour.
|
|
53
|
+
- Your own e-mail templates are used as they are: the summary box and button go where the template has the
|
|
54
|
+
quote link on a line of its own (else before its sign-off), and no second sign-off is added when the
|
|
55
|
+
template has one.
|
|
56
|
+
- Default texts: British English, "Kind regards", "e-mail"; the request acknowledgement no longer promises
|
|
57
|
+
a reply "usually within one working day" (nothing in the plugin ensures that). Stored templates are not
|
|
58
|
+
changed.
|
|
59
|
+
- Licence SDK `^0.15.7`; dev dependencies refreshed to the latest minor versions (TypeScript 5.9, Vitest
|
|
60
|
+
2.1, @types/nodemailer 6.4). Held back: TypeScript 7, Vitest 5 (the monorepo harness pins Vitest 2) and
|
|
61
|
+
@types/nodemailer 8 (the types for nodemailer 8+, while the peer range starts at 6).
|
|
62
|
+
|
|
63
|
+
### Fixed
|
|
64
|
+
- The plain-text part of the pay-link e-mails had no link (it said "with the button below"); it now carries
|
|
65
|
+
the pay link and the quote link.
|
|
66
|
+
- The public quote page and the accept/decline form are rate limited per client address (120 page views
|
|
67
|
+
and 20 responses a minute; 429 after that), as the PDF download already was.
|
|
68
|
+
- Store notification subjects are kept to one line whatever the requester typed.
|
|
69
|
+
|
|
8
70
|
## [0.9.0] — 2026-11-13
|
|
9
71
|
|
|
10
72
|
Parity with HULO Quotations for WordPress (free 0.1.4 and Pro).
|
package/README.md
CHANGED
|
@@ -96,6 +96,43 @@ discards bots. A request posted with the customer's shop session (cookie or
|
|
|
96
96
|
bearer token) is linked to their account and shows under "My quotes"; guest
|
|
97
97
|
requests are never linked by e-mail address.
|
|
98
98
|
|
|
99
|
+
**Prices and VAT.** Catalogue lines are priced the way the channel prices
|
|
100
|
+
them. On a channel with *prices include tax* the variant price already
|
|
101
|
+
carries VAT, so the quote is VAT-inclusive: its total is the basket total and
|
|
102
|
+
the VAT inside it is shown separately ("Includes VAT (20%)"). Otherwise VAT is
|
|
103
|
+
added on top. The rate is the variant's own (its tax category in the channel's
|
|
104
|
+
default tax zone). New admin quotes follow the channel too, and the editor's
|
|
105
|
+
Pricing step has a **Line prices include VAT** switch.
|
|
106
|
+
|
|
107
|
+
### Posting from your storefront's server
|
|
108
|
+
|
|
109
|
+
If your storefront relays the request from its own server, every visitor
|
|
110
|
+
reaches the API from that server's address and shares one per-IP budget. Pass
|
|
111
|
+
the visitor's address in `x-real-client-ip` with a shared secret, and tell the
|
|
112
|
+
plugin to trust it (off by default; the header is ignored without the secret):
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
QuotationsPlugin.init({
|
|
116
|
+
// …
|
|
117
|
+
trustedClientIp: {
|
|
118
|
+
secret: process.env.QUOTATIONS_PROXY_SECRET, // sent by the relay in `x-quotations-proxy`
|
|
119
|
+
// secretHeader: 'x-checkout-guard-proxy', // reuse HULO Checkout Guard's header and secret
|
|
120
|
+
// trustedProxies: ['127.0.0.1', '::1'], // optional: only from these socket peers
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// In the storefront's server code:
|
|
127
|
+
headers: {
|
|
128
|
+
'content-type': 'application/json', 'vendure-token': CHANNEL_TOKEN,
|
|
129
|
+
'x-real-client-ip': visitorIp, 'x-quotations-proxy': process.env.QUOTATIONS_PROXY_SECRET,
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The address the request was counted against is kept on the quote
|
|
134
|
+
(`requestIp`) for the admin.
|
|
135
|
+
|
|
99
136
|
## "My quotes" for signed-in customers
|
|
100
137
|
|
|
101
138
|
```ts
|
|
@@ -109,6 +146,26 @@ const res = await fetch('https://shop.example.com/quotations/my', {
|
|
|
109
146
|
Only quotes linked to the customer's account are listed (staff link them with
|
|
110
147
|
the customer picker); drafts are never shown.
|
|
111
148
|
|
|
149
|
+
## E-mails
|
|
150
|
+
|
|
151
|
+
Every message the plugin sends shares one design: a 600px white card, your
|
|
152
|
+
logo (or business name) over a 3px bar in your accent colour, a heading, the
|
|
153
|
+
quote's reference, validity and total in a summary box, a button, a "Kind
|
|
154
|
+
regards" sign-off with your reply-to address, and a footer strip with your
|
|
155
|
+
address, phone, website and footer note. Inline styles only, with a
|
|
156
|
+
plain-text part. It is set from **Settings** (business name, logo URL, accent
|
|
157
|
+
colour, reply-to, address, phone, website, footer note); nothing extra.
|
|
158
|
+
|
|
159
|
+
- **To customers:** the quote, test sends (marked "Test send"), the chaser,
|
|
160
|
+
the expiry reminder, follow-up steps, pay-link e-mails (whole amount,
|
|
161
|
+
deposit or balance) and the request acknowledgement. Your subject and body
|
|
162
|
+
templates are used as written; the summary box and button go where the
|
|
163
|
+
body has `{{quoteUrl}}` on a line of its own, else before your sign-off.
|
|
164
|
+
- **To your team (compact):** new request, first view, accepted, declined,
|
|
165
|
+
approval requested, approved or not.
|
|
166
|
+
- **Weekly report:** the licence SDK's report layout with your logo and
|
|
167
|
+
accent colour.
|
|
168
|
+
|
|
112
169
|
## PDF
|
|
113
170
|
|
|
114
171
|
`GET /quotations/quote/:token/pdf` (the customer link, rate-limited, never
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trusting a storefront's server-side relay for the shopper's address.
|
|
3
|
+
*
|
|
4
|
+
* A storefront that posts quote requests from its own server (a Qwik
|
|
5
|
+
* `server$`, a Next.js route, a PHP form handler) reaches the API from one
|
|
6
|
+
* address, so every visitor would share one per-IP rate-limit bucket. The
|
|
7
|
+
* relay can pass the visitor's address in `x-real-client-ip`, but any client
|
|
8
|
+
* can set that header, so it is believed only when the request also carries
|
|
9
|
+
* a shared secret (`x-quotations-proxy` by default, the same pattern as HULO
|
|
10
|
+
* Checkout Guard's `x-checkout-guard-proxy`) and, when `trustedProxies` is
|
|
11
|
+
* set, only from one of those socket peers. Off unless a secret is configured.
|
|
12
|
+
*/
|
|
13
|
+
export interface QuotationsTrustedClientIpOptions {
|
|
14
|
+
/** The shared secret the relay sends. Without one the client-IP header is never trusted. */
|
|
15
|
+
secret?: string;
|
|
16
|
+
/** Header carrying the visitor's address. Default `x-real-client-ip`. */
|
|
17
|
+
header?: string;
|
|
18
|
+
/** Header carrying the secret. Default `x-quotations-proxy`. */
|
|
19
|
+
secretHeader?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional extra check: the socket peers (IPv4/IPv6, plain or CIDR) the
|
|
22
|
+
* relayed request may arrive from (your reverse proxies). Unset: any peer
|
|
23
|
+
* that presents the secret.
|
|
24
|
+
*/
|
|
25
|
+
trustedProxies?: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare const DEFAULT_CLIENT_IP_HEADER = "x-real-client-ip";
|
|
28
|
+
export declare const DEFAULT_CLIENT_IP_SECRET_HEADER = "x-quotations-proxy";
|
|
29
|
+
export interface ClientIpRequest {
|
|
30
|
+
headers: Record<string, string | string[] | undefined>;
|
|
31
|
+
ip?: string;
|
|
32
|
+
socket?: {
|
|
33
|
+
remoteAddress?: string;
|
|
34
|
+
} | null;
|
|
35
|
+
}
|
|
36
|
+
/** Trims, strips IPv6 brackets, `::ffff:` and an IPv4 `:port`; `null` unless a valid address remains. */
|
|
37
|
+
export declare function normaliseIp(candidate: string | null | undefined): string | null;
|
|
38
|
+
interface Cidr {
|
|
39
|
+
network: bigint;
|
|
40
|
+
mask: bigint;
|
|
41
|
+
}
|
|
42
|
+
export declare function parseCidr(entry: string): Cidr | null;
|
|
43
|
+
export declare function ipInList(ip: string | null | undefined, list: string[]): boolean;
|
|
44
|
+
/** Validates the options once (bad proxy entries fail at boot, not per request). */
|
|
45
|
+
export declare function resolveClientIpOptions(opts?: QuotationsTrustedClientIpOptions): {
|
|
46
|
+
secret: string;
|
|
47
|
+
header: string;
|
|
48
|
+
secretHeader: string;
|
|
49
|
+
trustedProxies: string[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The visitor's address for a public request: the relayed header when the
|
|
53
|
+
* relay proved itself (secret matches and, if configured, the peer is a
|
|
54
|
+
* trusted proxy), else `req.ip` (Express applies the host's `trust proxy`),
|
|
55
|
+
* else the socket peer. `null` when nothing usable is present.
|
|
56
|
+
*/
|
|
57
|
+
export declare function requestClientIp(req: ClientIpRequest | null | undefined, opts?: QuotationsTrustedClientIpOptions): string | null;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=client-ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.d.ts","sourceRoot":"","sources":["../src/client-ip.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gCAAgC;IAC7C,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAC3D,eAAO,MAAM,+BAA+B,uBAAuB,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC9C;AAQD,yGAAyG;AACzG,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAW/E;AAmCD,UAAU,IAAI;IAAG,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAEhD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAmBpD;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAK/E;AAQD,oFAAoF;AACpF,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,gCAAgC;;;;;EAW7E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,gCAAgC,GAAG,MAAM,GAAG,IAAI,CAY/H"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CLIENT_IP_SECRET_HEADER = exports.DEFAULT_CLIENT_IP_HEADER = void 0;
|
|
4
|
+
exports.normaliseIp = normaliseIp;
|
|
5
|
+
exports.parseCidr = parseCidr;
|
|
6
|
+
exports.ipInList = ipInList;
|
|
7
|
+
exports.resolveClientIpOptions = resolveClientIpOptions;
|
|
8
|
+
exports.requestClientIp = requestClientIp;
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const net_1 = require("net");
|
|
11
|
+
exports.DEFAULT_CLIENT_IP_HEADER = 'x-real-client-ip';
|
|
12
|
+
exports.DEFAULT_CLIENT_IP_SECRET_HEADER = 'x-quotations-proxy';
|
|
13
|
+
function headerValue(headers, name) {
|
|
14
|
+
const raw = headers === null || headers === void 0 ? void 0 : headers[name];
|
|
15
|
+
if (Array.isArray(raw))
|
|
16
|
+
return raw[0];
|
|
17
|
+
return typeof raw === 'string' ? raw : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Trims, strips IPv6 brackets, `::ffff:` and an IPv4 `:port`; `null` unless a valid address remains. */
|
|
20
|
+
function normaliseIp(candidate) {
|
|
21
|
+
if (!candidate)
|
|
22
|
+
return null;
|
|
23
|
+
let v = String(candidate).trim();
|
|
24
|
+
if (!v)
|
|
25
|
+
return null;
|
|
26
|
+
if (v.startsWith('[')) {
|
|
27
|
+
const close = v.indexOf(']');
|
|
28
|
+
v = close > 0 ? v.slice(1, close) : v.slice(1);
|
|
29
|
+
}
|
|
30
|
+
if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(v))
|
|
31
|
+
v = v.slice(7);
|
|
32
|
+
if (/^\d+\.\d+\.\d+\.\d+:\d+$/.test(v))
|
|
33
|
+
v = v.slice(0, v.lastIndexOf(':'));
|
|
34
|
+
return (0, net_1.isIP)(v) ? v : null;
|
|
35
|
+
}
|
|
36
|
+
const V6_ALL_ONES = (BigInt(1) << BigInt(128)) - BigInt(1);
|
|
37
|
+
const V4_MAPPED = BigInt(0xffff) << BigInt(32);
|
|
38
|
+
function ipToBigInt(ip) {
|
|
39
|
+
const version = (0, net_1.isIP)(ip);
|
|
40
|
+
if (version === 4) {
|
|
41
|
+
const p = ip.split('.').map(Number);
|
|
42
|
+
return V4_MAPPED | (BigInt(p[0]) << BigInt(24)) | (BigInt(p[1]) << BigInt(16)) | (BigInt(p[2]) << BigInt(8)) | BigInt(p[3]);
|
|
43
|
+
}
|
|
44
|
+
if (version !== 6)
|
|
45
|
+
return null;
|
|
46
|
+
let s = ip;
|
|
47
|
+
const embedded = s.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
|
|
48
|
+
if (embedded) {
|
|
49
|
+
const p = embedded[2].split('.').map(Number);
|
|
50
|
+
s = `${embedded[1]}${((p[0] << 8) | p[1]).toString(16)}:${((p[2] << 8) | p[3]).toString(16)}`;
|
|
51
|
+
}
|
|
52
|
+
const parts = s.split('::');
|
|
53
|
+
if (parts.length > 2)
|
|
54
|
+
return null;
|
|
55
|
+
const head = parts[0] ? parts[0].split(':') : [];
|
|
56
|
+
const tail = parts.length === 2 && parts[1] ? parts[1].split(':') : [];
|
|
57
|
+
const fill = parts.length === 2 ? 8 - head.length - tail.length : 0;
|
|
58
|
+
if (fill < 0)
|
|
59
|
+
return null;
|
|
60
|
+
const groups = [...head, ...new Array(fill).fill('0'), ...tail];
|
|
61
|
+
if (groups.length !== 8)
|
|
62
|
+
return null;
|
|
63
|
+
let out = BigInt(0);
|
|
64
|
+
for (const g of groups) {
|
|
65
|
+
const n = parseInt(g, 16);
|
|
66
|
+
if (!Number.isFinite(n) || n < 0 || n > 0xffff)
|
|
67
|
+
return null;
|
|
68
|
+
out = (out << BigInt(16)) | BigInt(n);
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function parseCidr(entry) {
|
|
73
|
+
const raw = String(entry || '').trim();
|
|
74
|
+
if (!raw)
|
|
75
|
+
return null;
|
|
76
|
+
const slash = raw.lastIndexOf('/');
|
|
77
|
+
const ip = normaliseIp(slash >= 0 ? raw.slice(0, slash) : raw);
|
|
78
|
+
if (!ip)
|
|
79
|
+
return null;
|
|
80
|
+
const maxBits = (0, net_1.isIP)(ip) === 4 ? 32 : 128;
|
|
81
|
+
let prefix = maxBits;
|
|
82
|
+
if (slash >= 0) {
|
|
83
|
+
const p = raw.slice(slash + 1);
|
|
84
|
+
if (!/^\d{1,3}$/.test(p))
|
|
85
|
+
return null;
|
|
86
|
+
prefix = Number(p);
|
|
87
|
+
if (prefix > maxBits)
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const bits = ipToBigInt(ip);
|
|
91
|
+
if (bits === null)
|
|
92
|
+
return null;
|
|
93
|
+
const length = maxBits === 32 ? prefix + 96 : prefix;
|
|
94
|
+
const mask = length === 0 ? BigInt(0) : V6_ALL_ONES ^ ((BigInt(1) << BigInt(128 - length)) - BigInt(1));
|
|
95
|
+
return { network: bits & mask, mask };
|
|
96
|
+
}
|
|
97
|
+
function ipInList(ip, list) {
|
|
98
|
+
const norm = normaliseIp(ip);
|
|
99
|
+
const bits = norm ? ipToBigInt(norm) : null;
|
|
100
|
+
if (bits === null)
|
|
101
|
+
return false;
|
|
102
|
+
return list.map(parseCidr).some(c => !!c && (bits & c.mask) === c.network);
|
|
103
|
+
}
|
|
104
|
+
function secretsMatch(presented, expected) {
|
|
105
|
+
const a = Buffer.from(presented, 'utf8');
|
|
106
|
+
const b = Buffer.from(expected, 'utf8');
|
|
107
|
+
return a.length === b.length && (0, crypto_1.timingSafeEqual)(a, b);
|
|
108
|
+
}
|
|
109
|
+
/** Validates the options once (bad proxy entries fail at boot, not per request). */
|
|
110
|
+
function resolveClientIpOptions(opts) {
|
|
111
|
+
const trustedProxies = ((opts === null || opts === void 0 ? void 0 : opts.trustedProxies) || []).map(s => String(s).trim()).filter(Boolean);
|
|
112
|
+
for (const e of trustedProxies) {
|
|
113
|
+
if (!parseCidr(e))
|
|
114
|
+
throw new Error(`QuotationsPlugin trustedClientIp.trustedProxies: "${e}" is not an IPv4/IPv6 address or CIDR`);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
secret: String((opts === null || opts === void 0 ? void 0 : opts.secret) || '').trim(),
|
|
118
|
+
header: ((opts === null || opts === void 0 ? void 0 : opts.header) || exports.DEFAULT_CLIENT_IP_HEADER).trim().toLowerCase(),
|
|
119
|
+
secretHeader: ((opts === null || opts === void 0 ? void 0 : opts.secretHeader) || exports.DEFAULT_CLIENT_IP_SECRET_HEADER).trim().toLowerCase(),
|
|
120
|
+
trustedProxies,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The visitor's address for a public request: the relayed header when the
|
|
125
|
+
* relay proved itself (secret matches and, if configured, the peer is a
|
|
126
|
+
* trusted proxy), else `req.ip` (Express applies the host's `trust proxy`),
|
|
127
|
+
* else the socket peer. `null` when nothing usable is present.
|
|
128
|
+
*/
|
|
129
|
+
function requestClientIp(req, opts) {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
if (!req)
|
|
132
|
+
return null;
|
|
133
|
+
const o = resolveClientIpOptions(opts);
|
|
134
|
+
if (o.secret) {
|
|
135
|
+
const presented = headerValue(req.headers, o.secretHeader);
|
|
136
|
+
const peerOk = !o.trustedProxies.length || ipInList((_a = req.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress, o.trustedProxies);
|
|
137
|
+
if (presented && peerOk && secretsMatch(presented, o.secret)) {
|
|
138
|
+
const relayed = normaliseIp(headerValue(req.headers, o.header));
|
|
139
|
+
if (relayed)
|
|
140
|
+
return relayed;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return normaliseIp(req.ip) || normaliseIp((_b = req.socket) === null || _b === void 0 ? void 0 : _b.remoteAddress);
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=client-ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.js","sourceRoot":"","sources":["../src/client-ip.ts"],"names":[],"mappings":";;;AA8CA,kCAWC;AAqCD,8BAmBC;AAED,4BAKC;AASD,wDAWC;AAQD,0CAYC;AAhKD,mCAAyC;AACzC,6BAA2B;AA6Bd,QAAA,wBAAwB,GAAG,kBAAkB,CAAC;AAC9C,QAAA,+BAA+B,GAAG,oBAAoB,CAAC;AAQpE,SAAS,WAAW,CAAC,OAAmC,EAAE,IAAY;IAClE,MAAM,GAAG,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,IAAI,CAAC,CAAC;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACtC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC;AAED,yGAAyG;AACzG,SAAgB,WAAW,CAAC,SAAoC;IAC5D,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,CAAC,C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a 600px white card
|
|
3
|
+
* on a light grey background, the store's logo (or name) over a 3px accent
|
|
4
|
+
* bar, a 22px heading, body text, info and warning boxes, buttons, a
|
|
5
|
+
* "Kind regards" sign-off and a small footer strip with the store's own
|
|
6
|
+
* details. Inline styles and tables only (some senders strip <style>), every
|
|
7
|
+
* interpolated value escaped. Each message also gets a plain-text part.
|
|
8
|
+
*
|
|
9
|
+
* Pure functions, no I/O: the service builds an EmailDoc and an EmailBrand
|
|
10
|
+
* and sends the html and text it gets back.
|
|
11
|
+
*/
|
|
12
|
+
export interface EmailBrand {
|
|
13
|
+
/** shown as the header when there is no logo, and in the sign-off */
|
|
14
|
+
storeName: string;
|
|
15
|
+
/** absolute https URL of the store's logo */
|
|
16
|
+
logoUrl?: string;
|
|
17
|
+
/** accent colour (#rrggbb); anything else falls back to the default */
|
|
18
|
+
accent?: string;
|
|
19
|
+
/** shown under the sign-off when set */
|
|
20
|
+
supportEmail?: string;
|
|
21
|
+
/** the store's own footer text (address, phone, website, legal note), one item per line */
|
|
22
|
+
footerLines?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface EmailButton {
|
|
25
|
+
url: string;
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
export type EmailBlock =
|
|
29
|
+
/** A paragraph of plain text: escaped, line breaks kept, bare URLs linked. `textOnly` keeps it out of the HTML. */
|
|
30
|
+
{
|
|
31
|
+
type: 'p';
|
|
32
|
+
text: string;
|
|
33
|
+
textOnly?: boolean;
|
|
34
|
+
label?: string;
|
|
35
|
+
}
|
|
36
|
+
/** A grey info box: a row of label/value columns (`columns`) and/or label/value rows. */
|
|
37
|
+
| {
|
|
38
|
+
type: 'info';
|
|
39
|
+
title?: string;
|
|
40
|
+
columns?: EmailField[];
|
|
41
|
+
rows?: EmailField[];
|
|
42
|
+
}
|
|
43
|
+
/** An amber warning box. */
|
|
44
|
+
| {
|
|
45
|
+
type: 'warn';
|
|
46
|
+
title?: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}
|
|
49
|
+
/** A primary (accent) button and an optional secondary (outlined) one. */
|
|
50
|
+
| {
|
|
51
|
+
type: 'buttons';
|
|
52
|
+
primary?: EmailButton;
|
|
53
|
+
secondary?: EmailButton;
|
|
54
|
+
}
|
|
55
|
+
/** A small uppercase label over a bulleted list. */
|
|
56
|
+
| {
|
|
57
|
+
type: 'list';
|
|
58
|
+
title?: string;
|
|
59
|
+
items: string[];
|
|
60
|
+
};
|
|
61
|
+
export interface EmailField {
|
|
62
|
+
label: string;
|
|
63
|
+
value: string;
|
|
64
|
+
mono?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface EmailDoc {
|
|
67
|
+
/** hidden preview line shown by mail clients after the subject */
|
|
68
|
+
preheader?: string;
|
|
69
|
+
heading: string;
|
|
70
|
+
blocks: EmailBlock[];
|
|
71
|
+
/**
|
|
72
|
+
* 'auto' (default): "Kind regards," + the store name, unless the body
|
|
73
|
+
* already ends with a sign-off of its own (merchant templates usually do).
|
|
74
|
+
* 'none': no sign-off (staff notifications). A string: that name instead
|
|
75
|
+
* of the store name.
|
|
76
|
+
*/
|
|
77
|
+
signOff?: 'auto' | 'none' | {
|
|
78
|
+
name: string;
|
|
79
|
+
};
|
|
80
|
+
/** tighter spacing and no sign-off: store and staff notifications */
|
|
81
|
+
compact?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare const DEFAULT_ACCENT = "#155dfc";
|
|
84
|
+
export declare function esc(s: unknown): string;
|
|
85
|
+
/** A #rgb / #rrggbb colour, else the default (the value lands in a style attribute). */
|
|
86
|
+
export declare function safeAccent(c: unknown): string;
|
|
87
|
+
/** Only absolute http(s) URLs reach an href or src. */
|
|
88
|
+
export declare function safeUrl(u: unknown): string;
|
|
89
|
+
export declare function isSignOff(text: string): boolean;
|
|
90
|
+
/** True when one of the last two text paragraphs is a sign-off. */
|
|
91
|
+
export declare function hasOwnSignOff(blocks: EmailBlock[]): boolean;
|
|
92
|
+
/** Split a plain-text template body into paragraph blocks (blank line = new paragraph). */
|
|
93
|
+
export declare function paragraphs(body: string, opts?: {
|
|
94
|
+
textOnlyIf?: (p: string) => boolean;
|
|
95
|
+
}): EmailBlock[];
|
|
96
|
+
/** The HTML part. */
|
|
97
|
+
export declare function renderEmailHtml(doc: EmailDoc, brand: EmailBrand): string;
|
|
98
|
+
/** The plain-text part: the same content, readable without HTML. */
|
|
99
|
+
export declare function renderEmailText(doc: EmailDoc, brand: EmailBrand): string;
|
|
100
|
+
export declare function renderEmail(doc: EmailDoc, brand: EmailBrand): {
|
|
101
|
+
html: string;
|
|
102
|
+
text: string;
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=email-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-layout.d.ts","sourceRoot":"","sources":["../src/email-layout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,UAAU;IACvB,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAAG,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAE3D,MAAM,MAAM,UAAU;AAClB,mHAAmH;AACjH;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE;AACjE,yFAAyF;GACvF;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC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