@c1m-public/channel-client 0.17.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.
@@ -1,3 +1,417 @@
1
- export type { AddressLookupNormalizedAddress, AddressLookupRegionSuggestion, AddressSelection, LookupAddress, } from "./address-types.js";
2
- export * from "./address-model.js";
3
- export * from "./quote-model.js";
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Address shapes from the platform's address-lookup response.
5
+ *
6
+ * These are copied here deliberately rather than imported. The saas monorepo
7
+ * declares them across `@mml/shared-types` and `@mml/shared-ui`, and neither is
8
+ * reachable from a commissioned site -- which is the whole reason this package
9
+ * exists. A domain model should not depend on a UI package in any case.
10
+ *
11
+ * They describe a wire response, so treat them as a contract: change them only
12
+ * when the address-lookup API changes.
13
+ */
14
+ interface LookupAddress {
15
+ postcode: string;
16
+ line_1: string;
17
+ line_2: string;
18
+ line_3: string;
19
+ post_town: string;
20
+ county: string;
21
+ country: string;
22
+ building_name: string;
23
+ building_number: string;
24
+ thoroughfare: string;
25
+ organisation_name: string;
26
+ udprn: number;
27
+ longitude: number;
28
+ latitude: number;
29
+ }
30
+ interface AddressLookupNormalizedAddress {
31
+ address_line1: string;
32
+ address_line2: string;
33
+ city: string;
34
+ state_region: string;
35
+ postal_code: string;
36
+ country_code: string;
37
+ latitude?: number;
38
+ longitude?: number;
39
+ udprn?: number;
40
+ }
41
+ interface AddressLookupRegionSuggestion {
42
+ major_region_code: string;
43
+ major_region_label: string;
44
+ confidence: number;
45
+ match_source: string;
46
+ }
47
+ /**
48
+ * What an address picker hands back when someone selects a suggestion. The
49
+ * saas monorepo calls this `AddressAutocompleteResult` and ties it to a React
50
+ * component; the shape is the part that matters to the domain model.
51
+ */
52
+ interface AddressSelection {
53
+ display: string;
54
+ address: LookupAddress | null;
55
+ normalized?: AddressLookupNormalizedAddress;
56
+ directory_region?: AddressLookupRegionSuggestion | null;
57
+ }
58
+
59
+ type ContactPreference = "email" | "phone" | "any";
60
+ type TimePreference = "morning" | "afternoon" | "evening" | "any";
61
+ type MovingAddress = AddressSelection & {
62
+ rawQuery?: string;
63
+ };
64
+ interface DistanceResult {
65
+ distanceMiles: number;
66
+ durationMinutes: number;
67
+ }
68
+ declare function readAddressDisplay(address: MovingAddress | null, fallback: string): string;
69
+ declare function hasStructuredMovingAddress(address: MovingAddress | null): boolean;
70
+ declare function hasCoordinates(address: MovingAddress | null): address is MovingAddress & {
71
+ address: NonNullable<MovingAddress["address"]> & {
72
+ latitude: number;
73
+ longitude: number;
74
+ };
75
+ };
76
+ declare function formatDuration(minutes: number): string;
77
+ interface MovingLeadPayloadInput {
78
+ brand: string;
79
+ source: string;
80
+ name: string;
81
+ email: string;
82
+ phone: string;
83
+ preferredContact: ContactPreference;
84
+ preferredTime: TimePreference;
85
+ additionalNotes: string;
86
+ fromAddress: MovingAddress | null;
87
+ fromRaw: string;
88
+ toAddress: MovingAddress | null;
89
+ toRaw: string;
90
+ moveDate: string;
91
+ flexibleDate: boolean;
92
+ propertySize: string;
93
+ floorFrom: string;
94
+ floorTo: string;
95
+ hasLiftFrom: boolean;
96
+ hasLiftTo: boolean;
97
+ packingRequired: boolean;
98
+ storageRequired: boolean;
99
+ dismantlingRequired: boolean;
100
+ specialItems: string;
101
+ distance: DistanceResult | null;
102
+ }
103
+ declare const movingLeadPayloadSchema: z.ZodObject<{
104
+ lead_type: z.ZodLiteral<"moving">;
105
+ brand: z.ZodString;
106
+ source: z.ZodString;
107
+ intent: z.ZodLiteral<"moving_quote">;
108
+ name: z.ZodString;
109
+ email: z.ZodString;
110
+ phone: z.ZodString;
111
+ preferred_contact: z.ZodEnum<{
112
+ email: "email";
113
+ phone: "phone";
114
+ any: "any";
115
+ }>;
116
+ preferred_time: z.ZodEnum<{
117
+ any: "any";
118
+ morning: "morning";
119
+ afternoon: "afternoon";
120
+ evening: "evening";
121
+ }>;
122
+ message: z.ZodString;
123
+ meta: z.ZodObject<{
124
+ from_address: z.ZodString;
125
+ to_address: z.ZodString;
126
+ from_postcode: z.ZodNullable<z.ZodString>;
127
+ to_postcode: z.ZodNullable<z.ZodString>;
128
+ move_date: z.ZodString;
129
+ flexible_date: z.ZodBoolean;
130
+ property_size: z.ZodString;
131
+ floor_from: z.ZodNumber;
132
+ floor_to: z.ZodNumber;
133
+ has_lift_from: z.ZodBoolean;
134
+ has_lift_to: z.ZodBoolean;
135
+ packing_required: z.ZodBoolean;
136
+ storage_required: z.ZodBoolean;
137
+ dismantling_required: z.ZodBoolean;
138
+ special_items: z.ZodArray<z.ZodString>;
139
+ additional_notes: z.ZodString;
140
+ distance_miles: z.ZodNullable<z.ZodNumber>;
141
+ duration_minutes: z.ZodNullable<z.ZodNumber>;
142
+ pickup_region: z.ZodNullable<z.ZodString>;
143
+ delivery_region: z.ZodNullable<z.ZodString>;
144
+ pickup_location: z.ZodObject<{
145
+ display: z.ZodString;
146
+ raw_query: z.ZodNullable<z.ZodString>;
147
+ postcode: z.ZodNullable<z.ZodString>;
148
+ latitude: z.ZodNullable<z.ZodNumber>;
149
+ longitude: z.ZodNullable<z.ZodNumber>;
150
+ udprn: z.ZodNullable<z.ZodNumber>;
151
+ normalized: z.ZodNullable<z.ZodObject<{
152
+ address_line1: z.ZodString;
153
+ address_line2: z.ZodString;
154
+ city: z.ZodString;
155
+ state_region: z.ZodString;
156
+ postal_code: z.ZodString;
157
+ country_code: z.ZodString;
158
+ latitude: z.ZodNullable<z.ZodNumber>;
159
+ longitude: z.ZodNullable<z.ZodNumber>;
160
+ udprn: z.ZodNullable<z.ZodNumber>;
161
+ }, z.core.$strip>>;
162
+ directory_region: z.ZodNullable<z.ZodObject<{
163
+ major_region_code: z.ZodString;
164
+ major_region_label: z.ZodString;
165
+ confidence: z.ZodNumber;
166
+ match_source: z.ZodString;
167
+ }, z.core.$strip>>;
168
+ }, z.core.$strip>;
169
+ delivery_location: z.ZodObject<{
170
+ display: z.ZodString;
171
+ raw_query: z.ZodNullable<z.ZodString>;
172
+ postcode: z.ZodNullable<z.ZodString>;
173
+ latitude: z.ZodNullable<z.ZodNumber>;
174
+ longitude: z.ZodNullable<z.ZodNumber>;
175
+ udprn: z.ZodNullable<z.ZodNumber>;
176
+ normalized: z.ZodNullable<z.ZodObject<{
177
+ address_line1: z.ZodString;
178
+ address_line2: z.ZodString;
179
+ city: z.ZodString;
180
+ state_region: z.ZodString;
181
+ postal_code: z.ZodString;
182
+ country_code: z.ZodString;
183
+ latitude: z.ZodNullable<z.ZodNumber>;
184
+ longitude: z.ZodNullable<z.ZodNumber>;
185
+ udprn: z.ZodNullable<z.ZodNumber>;
186
+ }, z.core.$strip>>;
187
+ directory_region: z.ZodNullable<z.ZodObject<{
188
+ major_region_code: z.ZodString;
189
+ major_region_label: z.ZodString;
190
+ confidence: z.ZodNumber;
191
+ match_source: z.ZodString;
192
+ }, z.core.$strip>>;
193
+ }, z.core.$strip>;
194
+ }, z.core.$strip>;
195
+ }, z.core.$strip>;
196
+ declare const movingBrokerCapturePayloadSchema: z.ZodObject<{
197
+ source_type: z.ZodLiteral<"web">;
198
+ name: z.ZodString;
199
+ email: z.ZodString;
200
+ phone: z.ZodString;
201
+ message: z.ZodString;
202
+ region: z.ZodString;
203
+ tags: z.ZodArray<z.ZodString>;
204
+ meta: z.ZodObject<{
205
+ lead_type: z.ZodLiteral<"moving">;
206
+ brand: z.ZodString;
207
+ source: z.ZodString;
208
+ intent: z.ZodLiteral<"moving_quote">;
209
+ name: z.ZodString;
210
+ email: z.ZodString;
211
+ phone: z.ZodString;
212
+ preferred_contact: z.ZodEnum<{
213
+ email: "email";
214
+ phone: "phone";
215
+ any: "any";
216
+ }>;
217
+ preferred_time: z.ZodEnum<{
218
+ any: "any";
219
+ morning: "morning";
220
+ afternoon: "afternoon";
221
+ evening: "evening";
222
+ }>;
223
+ message: z.ZodString;
224
+ meta: z.ZodObject<{
225
+ from_address: z.ZodString;
226
+ to_address: z.ZodString;
227
+ from_postcode: z.ZodNullable<z.ZodString>;
228
+ to_postcode: z.ZodNullable<z.ZodString>;
229
+ move_date: z.ZodString;
230
+ flexible_date: z.ZodBoolean;
231
+ property_size: z.ZodString;
232
+ floor_from: z.ZodNumber;
233
+ floor_to: z.ZodNumber;
234
+ has_lift_from: z.ZodBoolean;
235
+ has_lift_to: z.ZodBoolean;
236
+ packing_required: z.ZodBoolean;
237
+ storage_required: z.ZodBoolean;
238
+ dismantling_required: z.ZodBoolean;
239
+ special_items: z.ZodArray<z.ZodString>;
240
+ additional_notes: z.ZodString;
241
+ distance_miles: z.ZodNullable<z.ZodNumber>;
242
+ duration_minutes: z.ZodNullable<z.ZodNumber>;
243
+ pickup_region: z.ZodNullable<z.ZodString>;
244
+ delivery_region: z.ZodNullable<z.ZodString>;
245
+ pickup_location: z.ZodObject<{
246
+ display: z.ZodString;
247
+ raw_query: z.ZodNullable<z.ZodString>;
248
+ postcode: z.ZodNullable<z.ZodString>;
249
+ latitude: z.ZodNullable<z.ZodNumber>;
250
+ longitude: z.ZodNullable<z.ZodNumber>;
251
+ udprn: z.ZodNullable<z.ZodNumber>;
252
+ normalized: z.ZodNullable<z.ZodObject<{
253
+ address_line1: z.ZodString;
254
+ address_line2: z.ZodString;
255
+ city: z.ZodString;
256
+ state_region: z.ZodString;
257
+ postal_code: z.ZodString;
258
+ country_code: z.ZodString;
259
+ latitude: z.ZodNullable<z.ZodNumber>;
260
+ longitude: z.ZodNullable<z.ZodNumber>;
261
+ udprn: z.ZodNullable<z.ZodNumber>;
262
+ }, z.core.$strip>>;
263
+ directory_region: z.ZodNullable<z.ZodObject<{
264
+ major_region_code: z.ZodString;
265
+ major_region_label: z.ZodString;
266
+ confidence: z.ZodNumber;
267
+ match_source: z.ZodString;
268
+ }, z.core.$strip>>;
269
+ }, z.core.$strip>;
270
+ delivery_location: z.ZodObject<{
271
+ display: z.ZodString;
272
+ raw_query: z.ZodNullable<z.ZodString>;
273
+ postcode: z.ZodNullable<z.ZodString>;
274
+ latitude: z.ZodNullable<z.ZodNumber>;
275
+ longitude: z.ZodNullable<z.ZodNumber>;
276
+ udprn: z.ZodNullable<z.ZodNumber>;
277
+ normalized: z.ZodNullable<z.ZodObject<{
278
+ address_line1: z.ZodString;
279
+ address_line2: z.ZodString;
280
+ city: z.ZodString;
281
+ state_region: z.ZodString;
282
+ postal_code: z.ZodString;
283
+ country_code: z.ZodString;
284
+ latitude: z.ZodNullable<z.ZodNumber>;
285
+ longitude: z.ZodNullable<z.ZodNumber>;
286
+ udprn: z.ZodNullable<z.ZodNumber>;
287
+ }, z.core.$strip>>;
288
+ directory_region: z.ZodNullable<z.ZodObject<{
289
+ major_region_code: z.ZodString;
290
+ major_region_label: z.ZodString;
291
+ confidence: z.ZodNumber;
292
+ match_source: z.ZodString;
293
+ }, z.core.$strip>>;
294
+ }, z.core.$strip>;
295
+ }, z.core.$strip>;
296
+ }, z.core.$strip>;
297
+ }, z.core.$strip>;
298
+ declare const movingLeadSubmissionSchema: z.ZodObject<{
299
+ lead_type: z.ZodLiteral<"moving">;
300
+ brand: z.ZodString;
301
+ source: z.ZodString;
302
+ intent: z.ZodLiteral<"moving_quote">;
303
+ name: z.ZodString;
304
+ email: z.ZodString;
305
+ phone: z.ZodString;
306
+ preferred_contact: z.ZodEnum<{
307
+ email: "email";
308
+ phone: "phone";
309
+ any: "any";
310
+ }>;
311
+ preferred_time: z.ZodEnum<{
312
+ any: "any";
313
+ morning: "morning";
314
+ afternoon: "afternoon";
315
+ evening: "evening";
316
+ }>;
317
+ message: z.ZodString;
318
+ meta: z.ZodObject<{
319
+ from_address: z.ZodString;
320
+ to_address: z.ZodString;
321
+ from_postcode: z.ZodNullable<z.ZodString>;
322
+ to_postcode: z.ZodNullable<z.ZodString>;
323
+ move_date: z.ZodString;
324
+ flexible_date: z.ZodBoolean;
325
+ property_size: z.ZodString;
326
+ floor_from: z.ZodNumber;
327
+ floor_to: z.ZodNumber;
328
+ has_lift_from: z.ZodBoolean;
329
+ has_lift_to: z.ZodBoolean;
330
+ packing_required: z.ZodBoolean;
331
+ storage_required: z.ZodBoolean;
332
+ dismantling_required: z.ZodBoolean;
333
+ special_items: z.ZodArray<z.ZodString>;
334
+ additional_notes: z.ZodString;
335
+ distance_miles: z.ZodNullable<z.ZodNumber>;
336
+ duration_minutes: z.ZodNullable<z.ZodNumber>;
337
+ pickup_region: z.ZodNullable<z.ZodString>;
338
+ delivery_region: z.ZodNullable<z.ZodString>;
339
+ pickup_location: z.ZodObject<{
340
+ display: z.ZodString;
341
+ raw_query: z.ZodNullable<z.ZodString>;
342
+ postcode: z.ZodNullable<z.ZodString>;
343
+ latitude: z.ZodNullable<z.ZodNumber>;
344
+ longitude: z.ZodNullable<z.ZodNumber>;
345
+ udprn: z.ZodNullable<z.ZodNumber>;
346
+ normalized: z.ZodNullable<z.ZodObject<{
347
+ address_line1: z.ZodString;
348
+ address_line2: z.ZodString;
349
+ city: z.ZodString;
350
+ state_region: z.ZodString;
351
+ postal_code: z.ZodString;
352
+ country_code: z.ZodString;
353
+ latitude: z.ZodNullable<z.ZodNumber>;
354
+ longitude: z.ZodNullable<z.ZodNumber>;
355
+ udprn: z.ZodNullable<z.ZodNumber>;
356
+ }, z.core.$strip>>;
357
+ directory_region: z.ZodNullable<z.ZodObject<{
358
+ major_region_code: z.ZodString;
359
+ major_region_label: z.ZodString;
360
+ confidence: z.ZodNumber;
361
+ match_source: z.ZodString;
362
+ }, z.core.$strip>>;
363
+ }, z.core.$strip>;
364
+ delivery_location: z.ZodObject<{
365
+ display: z.ZodString;
366
+ raw_query: z.ZodNullable<z.ZodString>;
367
+ postcode: z.ZodNullable<z.ZodString>;
368
+ latitude: z.ZodNullable<z.ZodNumber>;
369
+ longitude: z.ZodNullable<z.ZodNumber>;
370
+ udprn: z.ZodNullable<z.ZodNumber>;
371
+ normalized: z.ZodNullable<z.ZodObject<{
372
+ address_line1: z.ZodString;
373
+ address_line2: z.ZodString;
374
+ city: z.ZodString;
375
+ state_region: z.ZodString;
376
+ postal_code: z.ZodString;
377
+ country_code: z.ZodString;
378
+ latitude: z.ZodNullable<z.ZodNumber>;
379
+ longitude: z.ZodNullable<z.ZodNumber>;
380
+ udprn: z.ZodNullable<z.ZodNumber>;
381
+ }, z.core.$strip>>;
382
+ directory_region: z.ZodNullable<z.ZodObject<{
383
+ major_region_code: z.ZodString;
384
+ major_region_label: z.ZodString;
385
+ confidence: z.ZodNumber;
386
+ match_source: z.ZodString;
387
+ }, z.core.$strip>>;
388
+ }, z.core.$strip>;
389
+ }, z.core.$strip>;
390
+ }, z.core.$strip>;
391
+ type MovingLeadPayload = z.infer<typeof movingLeadPayloadSchema>;
392
+ type MovingBrokerCapturePayload = z.infer<typeof movingBrokerCapturePayloadSchema>;
393
+ declare function buildMovingLeadPayload(input: MovingLeadPayloadInput): MovingLeadPayload;
394
+ declare function buildMovingBrokerCapturePayload(payload: MovingLeadPayload): MovingBrokerCapturePayload;
395
+ declare function readQuoteSubmitError(response: Response): Promise<string>;
396
+ interface MovingLeadReadinessContext {
397
+ fromAddress?: MovingAddress | null;
398
+ toAddress?: MovingAddress | null;
399
+ }
400
+ declare function isMovingLeadReady(payload: MovingLeadPayload, context?: MovingLeadReadinessContext): boolean;
401
+ declare function getMovingLeadValidationItems(payload: MovingLeadPayload, context?: MovingLeadReadinessContext): {
402
+ label: string;
403
+ valid: boolean;
404
+ }[];
405
+
406
+ interface ManualMovingAddressFields {
407
+ line1: string;
408
+ line2: string;
409
+ city: string;
410
+ postcode: string;
411
+ }
412
+ declare function readConfirmedAddressLine(address: MovingAddress): string;
413
+ declare function readConfirmedAddressMeta(address: MovingAddress): string;
414
+ declare function readManualInitialAddress(address: MovingAddress | null, fallbackRaw: string): ManualMovingAddressFields;
415
+ declare function buildManualMovingAddress(fields: ManualMovingAddressFields): MovingAddress;
416
+
417
+ export { type AddressLookupNormalizedAddress, type AddressLookupRegionSuggestion, type AddressSelection, type ContactPreference, type DistanceResult, type LookupAddress, type MovingAddress, type MovingBrokerCapturePayload, type MovingLeadPayload, type MovingLeadPayloadInput, type MovingLeadReadinessContext, type TimePreference, buildManualMovingAddress, buildMovingBrokerCapturePayload, buildMovingLeadPayload, formatDuration, getMovingLeadValidationItems, hasCoordinates, hasStructuredMovingAddress, isMovingLeadReady, movingBrokerCapturePayloadSchema, movingLeadPayloadSchema, movingLeadSubmissionSchema, readAddressDisplay, readConfirmedAddressLine, readConfirmedAddressMeta, readManualInitialAddress, readQuoteSubmitError };