@c1m-public/channel-client 0.19.0 → 0.20.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/README.md +16 -5
- package/dist/chunk-ATGQYDRM.js +334 -0
- package/dist/chunk-AX6L2XH3.js +599 -0
- package/dist/chunk-JDERR7M5.js +17 -0
- package/dist/chunk-RJQ4YEZV.js +180 -0
- package/dist/dash-next.d.ts +8 -5
- package/dist/dash-next.js +10 -11
- package/dist/dash.d.ts +7 -5
- package/dist/dash.js +3 -16
- package/dist/index.d.ts +1325 -27
- package/dist/index.js +2 -513
- package/dist/moving-lead-model/index.d.ts +417 -3
- package/dist/moving-lead-model/index.js +288 -2
- package/dist/next.d.ts +352 -103
- package/dist/next.js +3 -69
- package/dist/renderer.d.ts +11 -9
- package/dist/renderer.js +75 -95
- package/dist/webhooks.d.ts +28 -26
- package/dist/webhooks.js +1 -228
- package/package.json +5 -3
- package/dist/errors.d.ts +0 -12
- package/dist/errors.js +0 -19
- package/dist/moving-lead-model/address-model.d.ts +0 -12
- package/dist/moving-lead-model/address-model.js +0 -43
- package/dist/moving-lead-model/address-types.d.ts +0 -55
- package/dist/moving-lead-model/address-types.js +0 -12
- package/dist/moving-lead-model/quote-model.d.ts +0 -348
- package/dist/moving-lead-model/quote-model.js +0 -267
- package/dist/next-cart.d.ts +0 -76
- package/dist/next-cart.js +0 -87
- package/dist/next-session.d.ts +0 -121
- package/dist/next-session.js +0 -177
- package/dist/next-webhooks.d.ts +0 -58
- package/dist/next-webhooks.js +0 -109
- package/dist/types.d.ts +0 -1273
- package/dist/types.js +0 -1
package/dist/webhooks.js
CHANGED
|
@@ -1,228 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Channel webhooks — the inbound half of the channel contract.
|
|
3
|
-
*
|
|
4
|
-
* The Channel API lets a headless app read. Webhooks are how it hears back: the
|
|
5
|
-
* `page.published` or `order.paid` event that drives a `revalidatePath` instead
|
|
6
|
-
* of a polling loop.
|
|
7
|
-
*
|
|
8
|
-
* Payloads are deliberately THIN. An event carries identifiers and a few stable,
|
|
9
|
-
* PII-free fields; fetch the detail back through the channel client. Data POSTed
|
|
10
|
-
* to your server can never be reached by a GDPR erasure on ours.
|
|
11
|
-
*/
|
|
12
|
-
import { ChannelConfigurationError } from "./errors.js";
|
|
13
|
-
export const CHANNEL_WEBHOOK_EVENT_TYPES = [
|
|
14
|
-
"order.created",
|
|
15
|
-
"order.paid",
|
|
16
|
-
"order.updated",
|
|
17
|
-
"order.cancelled",
|
|
18
|
-
"order.refunded",
|
|
19
|
-
"lead.created",
|
|
20
|
-
"review.submitted",
|
|
21
|
-
"review.published",
|
|
22
|
-
"page.published",
|
|
23
|
-
"product.created",
|
|
24
|
-
"product.updated",
|
|
25
|
-
"product.deleted",
|
|
26
|
-
];
|
|
27
|
-
export function isChannelWebhookEventType(value) {
|
|
28
|
-
return CHANNEL_WEBHOOK_EVENT_TYPES.includes(value);
|
|
29
|
-
}
|
|
30
|
-
export function isKnownChannelWebhookEvent(event) {
|
|
31
|
-
return isChannelWebhookEventType(event.type);
|
|
32
|
-
}
|
|
33
|
-
export class ChannelWebhookVerificationError extends Error {
|
|
34
|
-
code;
|
|
35
|
-
constructor(message, code) {
|
|
36
|
-
super(message);
|
|
37
|
-
this.code = code;
|
|
38
|
-
this.name = "ChannelWebhookVerificationError";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Structural, not instanceof — works across duplicate package instances and
|
|
43
|
-
* transformed test bundles. Exported so any consumer writing its own route
|
|
44
|
-
* handler can branch on "unverifiable request" without re-deriving this.
|
|
45
|
-
*/
|
|
46
|
-
export function isChannelWebhookVerificationError(error) {
|
|
47
|
-
return (error instanceof ChannelWebhookVerificationError ||
|
|
48
|
-
(typeof error === "object" && error !== null &&
|
|
49
|
-
error.name === "ChannelWebhookVerificationError" &&
|
|
50
|
-
typeof error.code === "string"));
|
|
51
|
-
}
|
|
52
|
-
export const CHANNEL_WEBHOOK_SIGNATURE_HEADER = "X-C1M-Signature";
|
|
53
|
-
export const CHANNEL_WEBHOOK_TIMESTAMP_HEADER = "X-C1M-Timestamp";
|
|
54
|
-
export const CHANNEL_WEBHOOK_EVENT_ID_HEADER = "X-C1M-Event-ID";
|
|
55
|
-
/** Five minutes. Bounds how long a captured request stays replayable. */
|
|
56
|
-
export const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
57
|
-
const encoder = new TextEncoder();
|
|
58
|
-
function toBytes(payload) {
|
|
59
|
-
return typeof payload === "string" ? encoder.encode(payload) : payload;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Compare in time independent of how many leading characters match. A plain
|
|
63
|
-
* `===` on the hex digests leaks, through timing, how much of a forged
|
|
64
|
-
* signature was right — which is enough to reconstruct one byte at a time.
|
|
65
|
-
*/
|
|
66
|
-
function timingSafeEqual(a, b) {
|
|
67
|
-
if (a.length !== b.length)
|
|
68
|
-
return false;
|
|
69
|
-
let diff = 0;
|
|
70
|
-
for (let i = 0; i < a.length; i += 1)
|
|
71
|
-
diff |= a[i] ^ b[i];
|
|
72
|
-
return diff === 0;
|
|
73
|
-
}
|
|
74
|
-
function decodeHex(value) {
|
|
75
|
-
if (value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-f]+$/i.test(value))
|
|
76
|
-
return null;
|
|
77
|
-
const out = new Uint8Array(value.length / 2);
|
|
78
|
-
for (let i = 0; i < out.length; i += 1) {
|
|
79
|
-
const byte = Number.parseInt(value.slice(i * 2, i * 2 + 2), 16);
|
|
80
|
-
if (Number.isNaN(byte))
|
|
81
|
-
return null;
|
|
82
|
-
out[i] = byte;
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Verify a channel webhook signature.
|
|
88
|
-
*
|
|
89
|
-
* The server signs `HMAC-SHA256(secret, "<unix_seconds>.<raw body>")` and sends
|
|
90
|
-
* it as `X-C1M-Signature: sha256=<hex>`. The timestamp is signed too, so it
|
|
91
|
-
* cannot be altered to defeat the replay window.
|
|
92
|
-
*
|
|
93
|
-
* Uses WebCrypto, so it runs unchanged on Node and the edge runtime.
|
|
94
|
-
*
|
|
95
|
-
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
96
|
-
*/
|
|
97
|
-
export async function verifyChannelWebhookSignature(options) {
|
|
98
|
-
const { payload, signature, timestamp, secret } = options;
|
|
99
|
-
const tolerance = options.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
100
|
-
const now = options.now ?? Date.now;
|
|
101
|
-
if (!secret)
|
|
102
|
-
throw new ChannelConfigurationError("secret is required");
|
|
103
|
-
if (!signature) {
|
|
104
|
-
throw new ChannelWebhookVerificationError(`missing ${CHANNEL_WEBHOOK_SIGNATURE_HEADER} header`, "missing_signature");
|
|
105
|
-
}
|
|
106
|
-
if (!timestamp) {
|
|
107
|
-
throw new ChannelWebhookVerificationError(`missing ${CHANNEL_WEBHOOK_TIMESTAMP_HEADER} header`, "missing_timestamp");
|
|
108
|
-
}
|
|
109
|
-
const timestampSeconds = Number(timestamp);
|
|
110
|
-
if (!Number.isFinite(timestampSeconds) || !/^\d+$/.test(timestamp.trim())) {
|
|
111
|
-
throw new ChannelWebhookVerificationError("timestamp is not a unix timestamp", "invalid_timestamp");
|
|
112
|
-
}
|
|
113
|
-
// Replay protection. Skew is checked in BOTH directions: a far-future
|
|
114
|
-
// timestamp is as suspect as a stale one.
|
|
115
|
-
if (tolerance > 0) {
|
|
116
|
-
const ageSeconds = Math.abs(now() / 1_000 - timestampSeconds);
|
|
117
|
-
if (ageSeconds > tolerance) {
|
|
118
|
-
throw new ChannelWebhookVerificationError(`timestamp is outside the ${tolerance}s tolerance`, "timestamp_out_of_tolerance");
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const provided = decodeHex(signature.startsWith("sha256=") ? signature.slice(7) : signature);
|
|
122
|
-
if (!provided) {
|
|
123
|
-
throw new ChannelWebhookVerificationError("signature is not sha256=<hex>", "invalid_signature");
|
|
124
|
-
}
|
|
125
|
-
const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
126
|
-
const body = toBytes(payload);
|
|
127
|
-
const signed = new Uint8Array(timestamp.length + 1 + body.length);
|
|
128
|
-
signed.set(encoder.encode(`${timestamp}.`), 0);
|
|
129
|
-
signed.set(body, timestamp.length + 1);
|
|
130
|
-
const expected = new Uint8Array(await crypto.subtle.sign("HMAC", key, signed));
|
|
131
|
-
if (!timingSafeEqual(expected, provided)) {
|
|
132
|
-
throw new ChannelWebhookVerificationError("signature does not match", "invalid_signature");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Verify and parse a channel webhook in one step, for an App Router route
|
|
137
|
-
* handler:
|
|
138
|
-
*
|
|
139
|
-
* ```ts
|
|
140
|
-
* export async function POST(request: Request) {
|
|
141
|
-
* let event;
|
|
142
|
-
* try {
|
|
143
|
-
* event = await parseChannelWebhookEvent(request, { secret: process.env.C1M_WEBHOOK_SECRET! });
|
|
144
|
-
* } catch {
|
|
145
|
-
* return new Response("invalid signature", { status: 400 });
|
|
146
|
-
* }
|
|
147
|
-
* if (event.type === "page.published") revalidatePath(event.data.route_pattern);
|
|
148
|
-
* return new Response(null, { status: 204 });
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* Delivery is at-least-once: dedupe on `event.id` before acting on anything
|
|
153
|
-
* that is not idempotent.
|
|
154
|
-
*
|
|
155
|
-
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
156
|
-
*/
|
|
157
|
-
export async function parseChannelWebhookEvent(request, options) {
|
|
158
|
-
// Read the raw body BEFORE parsing: the signature covers these exact bytes.
|
|
159
|
-
const payload = await request.text();
|
|
160
|
-
await verifyChannelWebhookSignature({
|
|
161
|
-
payload,
|
|
162
|
-
signature: request.headers.get(CHANNEL_WEBHOOK_SIGNATURE_HEADER),
|
|
163
|
-
timestamp: request.headers.get(CHANNEL_WEBHOOK_TIMESTAMP_HEADER),
|
|
164
|
-
secret: options.secret,
|
|
165
|
-
toleranceSeconds: options.toleranceSeconds,
|
|
166
|
-
now: options.now,
|
|
167
|
-
});
|
|
168
|
-
let event;
|
|
169
|
-
try {
|
|
170
|
-
event = JSON.parse(payload);
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
throw new ChannelWebhookVerificationError("body is not valid JSON", "invalid_payload");
|
|
174
|
-
}
|
|
175
|
-
if (!isEventEnvelope(event)) {
|
|
176
|
-
throw new ChannelWebhookVerificationError("body is not a channel event", "invalid_payload");
|
|
177
|
-
}
|
|
178
|
-
if (!isChannelWebhookEventType(event.type))
|
|
179
|
-
return event;
|
|
180
|
-
if (!isKnownEventData(event.type, event.data)) {
|
|
181
|
-
throw new ChannelWebhookVerificationError("body contains invalid event data", "invalid_payload");
|
|
182
|
-
}
|
|
183
|
-
return event;
|
|
184
|
-
}
|
|
185
|
-
function isRecord(value) {
|
|
186
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
187
|
-
}
|
|
188
|
-
function isEventEnvelope(value) {
|
|
189
|
-
if (!isRecord(value) || !isRecord(value.data))
|
|
190
|
-
return false;
|
|
191
|
-
for (const key of ["id", "type", "api_version", "occurred_at", "workspace_id"]) {
|
|
192
|
-
if (typeof value[key] !== "string" || value[key].trim() === "")
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
return value.channel_id === undefined || typeof value.channel_id === "string";
|
|
196
|
-
}
|
|
197
|
-
function hasStrings(data, keys) {
|
|
198
|
-
return keys.every((key) => typeof data[key] === "string");
|
|
199
|
-
}
|
|
200
|
-
function isKnownEventData(type, value) {
|
|
201
|
-
if (!isRecord(value))
|
|
202
|
-
return false;
|
|
203
|
-
switch (type) {
|
|
204
|
-
case "order.created":
|
|
205
|
-
case "order.paid":
|
|
206
|
-
case "order.updated":
|
|
207
|
-
case "order.cancelled":
|
|
208
|
-
case "order.refunded":
|
|
209
|
-
return hasStrings(value, ["order_id", "order_number", "status", "payment_status", "currency", "created_at"]) &&
|
|
210
|
-
typeof value.total_cents === "number";
|
|
211
|
-
case "lead.created":
|
|
212
|
-
return hasStrings(value, ["lead_id", "source", "created_at"]);
|
|
213
|
-
case "review.submitted":
|
|
214
|
-
return hasStrings(value, ["source", "submitted_at"]) && typeof value.rating === "number";
|
|
215
|
-
case "review.published":
|
|
216
|
-
return hasStrings(value, ["review_id", "source"]) && typeof value.rating === "number" &&
|
|
217
|
-
(value.published_at === undefined || typeof value.published_at === "string");
|
|
218
|
-
case "page.published":
|
|
219
|
-
return hasStrings(value, ["page_id", "route_pattern", "title"]) &&
|
|
220
|
-
(value.published_at === undefined || typeof value.published_at === "string");
|
|
221
|
-
case "product.created":
|
|
222
|
-
case "product.updated":
|
|
223
|
-
case "product.deleted":
|
|
224
|
-
return typeof value.product_id === "string" &&
|
|
225
|
-
(value.slug === undefined || typeof value.slug === "string") &&
|
|
226
|
-
(value.status === undefined || typeof value.status === "string");
|
|
227
|
-
}
|
|
228
|
-
}
|
|
1
|
+
export { CHANNEL_WEBHOOK_EVENT_ID_HEADER, CHANNEL_WEBHOOK_EVENT_TYPES, CHANNEL_WEBHOOK_SIGNATURE_HEADER, CHANNEL_WEBHOOK_TIMESTAMP_HEADER, ChannelWebhookVerificationError, DEFAULT_TOLERANCE_SECONDS, isChannelWebhookEventType, isChannelWebhookVerificationError, isKnownChannelWebhookEvent, parseChannelWebhookEvent, verifyChannelWebhookSignature } from './chunk-RJQ4YEZV.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c1m-public/channel-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Typed server-side client for the MML headless Channel API",
|
|
@@ -69,11 +69,13 @@
|
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"typescript": "5.9.3",
|
|
71
71
|
"zod": "^4.3.6",
|
|
72
|
-
"vitest": "^4.1.4"
|
|
72
|
+
"vitest": "^4.1.4",
|
|
73
|
+
"tsup": "^8.5.1",
|
|
74
|
+
"@c1m-public/transport": "0.0.0"
|
|
73
75
|
},
|
|
74
76
|
"scripts": {
|
|
75
77
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
76
|
-
"build": "pnpm clean &&
|
|
78
|
+
"build": "pnpm clean && tsup",
|
|
77
79
|
"lint": "tsc -p tsconfig.json --noEmit",
|
|
78
80
|
"test": "vitest",
|
|
79
81
|
"test:run": "vitest run",
|
package/dist/errors.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChannelConfigurationError is thrown for a misconfigured client — missing or
|
|
3
|
-
* malformed token, invalid retry/timeout/cache options, missing fetch, missing
|
|
4
|
-
* webhook secret — as opposed to ChannelAPIError, which describes what the
|
|
5
|
-
* network or the API did. Callers can branch on this without string-matching
|
|
6
|
-
* messages; both starters previously invented a local equivalent.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ChannelConfigurationError extends Error {
|
|
9
|
-
constructor(message: string);
|
|
10
|
-
}
|
|
11
|
-
/** Works across duplicate package instances and transformed test bundles. */
|
|
12
|
-
export declare function isChannelConfigurationError(error: unknown): error is ChannelConfigurationError;
|
package/dist/errors.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChannelConfigurationError is thrown for a misconfigured client — missing or
|
|
3
|
-
* malformed token, invalid retry/timeout/cache options, missing fetch, missing
|
|
4
|
-
* webhook secret — as opposed to ChannelAPIError, which describes what the
|
|
5
|
-
* network or the API did. Callers can branch on this without string-matching
|
|
6
|
-
* messages; both starters previously invented a local equivalent.
|
|
7
|
-
*/
|
|
8
|
-
export class ChannelConfigurationError extends Error {
|
|
9
|
-
constructor(message) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = "ChannelConfigurationError";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Works across duplicate package instances and transformed test bundles. */
|
|
15
|
-
export function isChannelConfigurationError(error) {
|
|
16
|
-
return (error instanceof ChannelConfigurationError ||
|
|
17
|
-
(typeof error === "object" && error !== null &&
|
|
18
|
-
error.name === "ChannelConfigurationError"));
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MovingAddress } from "./quote-model.js";
|
|
2
|
-
interface ManualMovingAddressFields {
|
|
3
|
-
line1: string;
|
|
4
|
-
line2: string;
|
|
5
|
-
city: string;
|
|
6
|
-
postcode: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function readConfirmedAddressLine(address: MovingAddress): string;
|
|
9
|
-
export declare function readConfirmedAddressMeta(address: MovingAddress): string;
|
|
10
|
-
export declare function readManualInitialAddress(address: MovingAddress | null, fallbackRaw: string): ManualMovingAddressFields;
|
|
11
|
-
export declare function buildManualMovingAddress(fields: ManualMovingAddressFields): MovingAddress;
|
|
12
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const UK_POSTCODE_RE = /^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i;
|
|
2
|
-
export function readConfirmedAddressLine(address) {
|
|
3
|
-
return address.normalized?.address_line1 || address.address?.line_1 || address.display;
|
|
4
|
-
}
|
|
5
|
-
export function readConfirmedAddressMeta(address) {
|
|
6
|
-
return [
|
|
7
|
-
address.normalized?.address_line2 || address.address?.line_2,
|
|
8
|
-
address.normalized?.city || address.address?.post_town,
|
|
9
|
-
address.normalized?.postal_code || address.address?.postcode,
|
|
10
|
-
].filter(Boolean).join(", ");
|
|
11
|
-
}
|
|
12
|
-
export function readManualInitialAddress(address, fallbackRaw) {
|
|
13
|
-
const raw = address?.rawQuery || fallbackRaw;
|
|
14
|
-
const rawLooksLikePostcode = UK_POSTCODE_RE.test(raw.trim());
|
|
15
|
-
return {
|
|
16
|
-
line1: address?.normalized?.address_line1 || address?.address?.line_1 || (rawLooksLikePostcode ? "" : raw),
|
|
17
|
-
line2: address?.normalized?.address_line2 || [address?.address?.line_2, address?.address?.line_3].filter(Boolean).join(", "),
|
|
18
|
-
city: address?.normalized?.city || address?.address?.post_town || "",
|
|
19
|
-
postcode: address?.normalized?.postal_code || address?.address?.postcode || (rawLooksLikePostcode ? raw.toUpperCase() : ""),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export function buildManualMovingAddress(fields) {
|
|
23
|
-
const line1 = fields.line1.trim();
|
|
24
|
-
const line2 = fields.line2.trim();
|
|
25
|
-
const city = fields.city.trim();
|
|
26
|
-
const postcode = fields.postcode.trim();
|
|
27
|
-
const display = [line1, line2, city, postcode]
|
|
28
|
-
.filter(Boolean)
|
|
29
|
-
.join(", ");
|
|
30
|
-
return {
|
|
31
|
-
display,
|
|
32
|
-
rawQuery: display,
|
|
33
|
-
address: null,
|
|
34
|
-
normalized: {
|
|
35
|
-
address_line1: line1,
|
|
36
|
-
address_line2: line2,
|
|
37
|
-
city,
|
|
38
|
-
state_region: "",
|
|
39
|
-
postal_code: postcode,
|
|
40
|
-
country_code: "GB",
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Address shapes from the platform's address-lookup response.
|
|
3
|
-
*
|
|
4
|
-
* These are copied here deliberately rather than imported. The saas monorepo
|
|
5
|
-
* declares them across `@mml/shared-types` and `@mml/shared-ui`, and neither is
|
|
6
|
-
* reachable from a commissioned site -- which is the whole reason this package
|
|
7
|
-
* exists. A domain model should not depend on a UI package in any case.
|
|
8
|
-
*
|
|
9
|
-
* They describe a wire response, so treat them as a contract: change them only
|
|
10
|
-
* when the address-lookup API changes.
|
|
11
|
-
*/
|
|
12
|
-
export interface LookupAddress {
|
|
13
|
-
postcode: string;
|
|
14
|
-
line_1: string;
|
|
15
|
-
line_2: string;
|
|
16
|
-
line_3: string;
|
|
17
|
-
post_town: string;
|
|
18
|
-
county: string;
|
|
19
|
-
country: string;
|
|
20
|
-
building_name: string;
|
|
21
|
-
building_number: string;
|
|
22
|
-
thoroughfare: string;
|
|
23
|
-
organisation_name: string;
|
|
24
|
-
udprn: number;
|
|
25
|
-
longitude: number;
|
|
26
|
-
latitude: number;
|
|
27
|
-
}
|
|
28
|
-
export interface AddressLookupNormalizedAddress {
|
|
29
|
-
address_line1: string;
|
|
30
|
-
address_line2: string;
|
|
31
|
-
city: string;
|
|
32
|
-
state_region: string;
|
|
33
|
-
postal_code: string;
|
|
34
|
-
country_code: string;
|
|
35
|
-
latitude?: number;
|
|
36
|
-
longitude?: number;
|
|
37
|
-
udprn?: number;
|
|
38
|
-
}
|
|
39
|
-
export interface AddressLookupRegionSuggestion {
|
|
40
|
-
major_region_code: string;
|
|
41
|
-
major_region_label: string;
|
|
42
|
-
confidence: number;
|
|
43
|
-
match_source: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* What an address picker hands back when someone selects a suggestion. The
|
|
47
|
-
* saas monorepo calls this `AddressAutocompleteResult` and ties it to a React
|
|
48
|
-
* component; the shape is the part that matters to the domain model.
|
|
49
|
-
*/
|
|
50
|
-
export interface AddressSelection {
|
|
51
|
-
display: string;
|
|
52
|
-
address: LookupAddress | null;
|
|
53
|
-
normalized?: AddressLookupNormalizedAddress;
|
|
54
|
-
directory_region?: AddressLookupRegionSuggestion | null;
|
|
55
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Address shapes from the platform's address-lookup response.
|
|
3
|
-
*
|
|
4
|
-
* These are copied here deliberately rather than imported. The saas monorepo
|
|
5
|
-
* declares them across `@mml/shared-types` and `@mml/shared-ui`, and neither is
|
|
6
|
-
* reachable from a commissioned site -- which is the whole reason this package
|
|
7
|
-
* exists. A domain model should not depend on a UI package in any case.
|
|
8
|
-
*
|
|
9
|
-
* They describe a wire response, so treat them as a contract: change them only
|
|
10
|
-
* when the address-lookup API changes.
|
|
11
|
-
*/
|
|
12
|
-
export {};
|