@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.
@@ -1,348 +0,0 @@
1
- import type { AddressSelection } from "./address-types.js";
2
- import { z } from "zod";
3
- export type ContactPreference = "email" | "phone" | "any";
4
- export type TimePreference = "morning" | "afternoon" | "evening" | "any";
5
- export type MovingAddress = AddressSelection & {
6
- rawQuery?: string;
7
- };
8
- export interface DistanceResult {
9
- distanceMiles: number;
10
- durationMinutes: number;
11
- }
12
- export declare function readAddressDisplay(address: MovingAddress | null, fallback: string): string;
13
- export declare function hasStructuredMovingAddress(address: MovingAddress | null): boolean;
14
- export declare function hasCoordinates(address: MovingAddress | null): address is MovingAddress & {
15
- address: NonNullable<MovingAddress["address"]> & {
16
- latitude: number;
17
- longitude: number;
18
- };
19
- };
20
- export declare function formatDuration(minutes: number): string;
21
- export interface MovingLeadPayloadInput {
22
- brand: string;
23
- source: string;
24
- name: string;
25
- email: string;
26
- phone: string;
27
- preferredContact: ContactPreference;
28
- preferredTime: TimePreference;
29
- additionalNotes: string;
30
- fromAddress: MovingAddress | null;
31
- fromRaw: string;
32
- toAddress: MovingAddress | null;
33
- toRaw: string;
34
- moveDate: string;
35
- flexibleDate: boolean;
36
- propertySize: string;
37
- floorFrom: string;
38
- floorTo: string;
39
- hasLiftFrom: boolean;
40
- hasLiftTo: boolean;
41
- packingRequired: boolean;
42
- storageRequired: boolean;
43
- dismantlingRequired: boolean;
44
- specialItems: string;
45
- distance: DistanceResult | null;
46
- }
47
- export declare const movingLeadPayloadSchema: z.ZodObject<{
48
- lead_type: z.ZodLiteral<"moving">;
49
- brand: z.ZodString;
50
- source: z.ZodString;
51
- intent: z.ZodLiteral<"moving_quote">;
52
- name: z.ZodString;
53
- email: z.ZodString;
54
- phone: z.ZodString;
55
- preferred_contact: z.ZodEnum<{
56
- email: "email";
57
- phone: "phone";
58
- any: "any";
59
- }>;
60
- preferred_time: z.ZodEnum<{
61
- any: "any";
62
- morning: "morning";
63
- afternoon: "afternoon";
64
- evening: "evening";
65
- }>;
66
- message: z.ZodString;
67
- meta: z.ZodObject<{
68
- from_address: z.ZodString;
69
- to_address: z.ZodString;
70
- from_postcode: z.ZodNullable<z.ZodString>;
71
- to_postcode: z.ZodNullable<z.ZodString>;
72
- move_date: z.ZodString;
73
- flexible_date: z.ZodBoolean;
74
- property_size: z.ZodString;
75
- floor_from: z.ZodNumber;
76
- floor_to: z.ZodNumber;
77
- has_lift_from: z.ZodBoolean;
78
- has_lift_to: z.ZodBoolean;
79
- packing_required: z.ZodBoolean;
80
- storage_required: z.ZodBoolean;
81
- dismantling_required: z.ZodBoolean;
82
- special_items: z.ZodArray<z.ZodString>;
83
- additional_notes: z.ZodString;
84
- distance_miles: z.ZodNullable<z.ZodNumber>;
85
- duration_minutes: z.ZodNullable<z.ZodNumber>;
86
- pickup_region: z.ZodNullable<z.ZodString>;
87
- delivery_region: z.ZodNullable<z.ZodString>;
88
- pickup_location: z.ZodObject<{
89
- display: z.ZodString;
90
- raw_query: z.ZodNullable<z.ZodString>;
91
- postcode: z.ZodNullable<z.ZodString>;
92
- latitude: z.ZodNullable<z.ZodNumber>;
93
- longitude: z.ZodNullable<z.ZodNumber>;
94
- udprn: z.ZodNullable<z.ZodNumber>;
95
- normalized: z.ZodNullable<z.ZodObject<{
96
- address_line1: z.ZodString;
97
- address_line2: z.ZodString;
98
- city: z.ZodString;
99
- state_region: z.ZodString;
100
- postal_code: z.ZodString;
101
- country_code: z.ZodString;
102
- latitude: z.ZodNullable<z.ZodNumber>;
103
- longitude: z.ZodNullable<z.ZodNumber>;
104
- udprn: z.ZodNullable<z.ZodNumber>;
105
- }, z.core.$strip>>;
106
- directory_region: z.ZodNullable<z.ZodObject<{
107
- major_region_code: z.ZodString;
108
- major_region_label: z.ZodString;
109
- confidence: z.ZodNumber;
110
- match_source: z.ZodString;
111
- }, z.core.$strip>>;
112
- }, z.core.$strip>;
113
- delivery_location: z.ZodObject<{
114
- display: z.ZodString;
115
- raw_query: z.ZodNullable<z.ZodString>;
116
- postcode: z.ZodNullable<z.ZodString>;
117
- latitude: z.ZodNullable<z.ZodNumber>;
118
- longitude: z.ZodNullable<z.ZodNumber>;
119
- udprn: z.ZodNullable<z.ZodNumber>;
120
- normalized: z.ZodNullable<z.ZodObject<{
121
- address_line1: z.ZodString;
122
- address_line2: z.ZodString;
123
- city: z.ZodString;
124
- state_region: z.ZodString;
125
- postal_code: z.ZodString;
126
- country_code: z.ZodString;
127
- latitude: z.ZodNullable<z.ZodNumber>;
128
- longitude: z.ZodNullable<z.ZodNumber>;
129
- udprn: z.ZodNullable<z.ZodNumber>;
130
- }, z.core.$strip>>;
131
- directory_region: z.ZodNullable<z.ZodObject<{
132
- major_region_code: z.ZodString;
133
- major_region_label: z.ZodString;
134
- confidence: z.ZodNumber;
135
- match_source: z.ZodString;
136
- }, z.core.$strip>>;
137
- }, z.core.$strip>;
138
- }, z.core.$strip>;
139
- }, z.core.$strip>;
140
- export declare const movingBrokerCapturePayloadSchema: z.ZodObject<{
141
- source_type: z.ZodLiteral<"web">;
142
- name: z.ZodString;
143
- email: z.ZodString;
144
- phone: z.ZodString;
145
- message: z.ZodString;
146
- region: z.ZodString;
147
- tags: z.ZodArray<z.ZodString>;
148
- meta: z.ZodObject<{
149
- lead_type: z.ZodLiteral<"moving">;
150
- brand: z.ZodString;
151
- source: z.ZodString;
152
- intent: z.ZodLiteral<"moving_quote">;
153
- name: z.ZodString;
154
- email: z.ZodString;
155
- phone: z.ZodString;
156
- preferred_contact: z.ZodEnum<{
157
- email: "email";
158
- phone: "phone";
159
- any: "any";
160
- }>;
161
- preferred_time: z.ZodEnum<{
162
- any: "any";
163
- morning: "morning";
164
- afternoon: "afternoon";
165
- evening: "evening";
166
- }>;
167
- message: z.ZodString;
168
- meta: z.ZodObject<{
169
- from_address: z.ZodString;
170
- to_address: z.ZodString;
171
- from_postcode: z.ZodNullable<z.ZodString>;
172
- to_postcode: z.ZodNullable<z.ZodString>;
173
- move_date: z.ZodString;
174
- flexible_date: z.ZodBoolean;
175
- property_size: z.ZodString;
176
- floor_from: z.ZodNumber;
177
- floor_to: z.ZodNumber;
178
- has_lift_from: z.ZodBoolean;
179
- has_lift_to: z.ZodBoolean;
180
- packing_required: z.ZodBoolean;
181
- storage_required: z.ZodBoolean;
182
- dismantling_required: z.ZodBoolean;
183
- special_items: z.ZodArray<z.ZodString>;
184
- additional_notes: z.ZodString;
185
- distance_miles: z.ZodNullable<z.ZodNumber>;
186
- duration_minutes: z.ZodNullable<z.ZodNumber>;
187
- pickup_region: z.ZodNullable<z.ZodString>;
188
- delivery_region: z.ZodNullable<z.ZodString>;
189
- pickup_location: z.ZodObject<{
190
- display: z.ZodString;
191
- raw_query: z.ZodNullable<z.ZodString>;
192
- postcode: z.ZodNullable<z.ZodString>;
193
- latitude: z.ZodNullable<z.ZodNumber>;
194
- longitude: z.ZodNullable<z.ZodNumber>;
195
- udprn: z.ZodNullable<z.ZodNumber>;
196
- normalized: z.ZodNullable<z.ZodObject<{
197
- address_line1: z.ZodString;
198
- address_line2: z.ZodString;
199
- city: z.ZodString;
200
- state_region: z.ZodString;
201
- postal_code: z.ZodString;
202
- country_code: z.ZodString;
203
- latitude: z.ZodNullable<z.ZodNumber>;
204
- longitude: z.ZodNullable<z.ZodNumber>;
205
- udprn: z.ZodNullable<z.ZodNumber>;
206
- }, z.core.$strip>>;
207
- directory_region: z.ZodNullable<z.ZodObject<{
208
- major_region_code: z.ZodString;
209
- major_region_label: z.ZodString;
210
- confidence: z.ZodNumber;
211
- match_source: z.ZodString;
212
- }, z.core.$strip>>;
213
- }, z.core.$strip>;
214
- delivery_location: z.ZodObject<{
215
- display: z.ZodString;
216
- raw_query: z.ZodNullable<z.ZodString>;
217
- postcode: z.ZodNullable<z.ZodString>;
218
- latitude: z.ZodNullable<z.ZodNumber>;
219
- longitude: z.ZodNullable<z.ZodNumber>;
220
- udprn: z.ZodNullable<z.ZodNumber>;
221
- normalized: z.ZodNullable<z.ZodObject<{
222
- address_line1: z.ZodString;
223
- address_line2: z.ZodString;
224
- city: z.ZodString;
225
- state_region: z.ZodString;
226
- postal_code: z.ZodString;
227
- country_code: z.ZodString;
228
- latitude: z.ZodNullable<z.ZodNumber>;
229
- longitude: z.ZodNullable<z.ZodNumber>;
230
- udprn: z.ZodNullable<z.ZodNumber>;
231
- }, z.core.$strip>>;
232
- directory_region: z.ZodNullable<z.ZodObject<{
233
- major_region_code: z.ZodString;
234
- major_region_label: z.ZodString;
235
- confidence: z.ZodNumber;
236
- match_source: z.ZodString;
237
- }, z.core.$strip>>;
238
- }, z.core.$strip>;
239
- }, z.core.$strip>;
240
- }, z.core.$strip>;
241
- }, z.core.$strip>;
242
- export declare const movingLeadSubmissionSchema: z.ZodObject<{
243
- lead_type: z.ZodLiteral<"moving">;
244
- brand: z.ZodString;
245
- source: z.ZodString;
246
- intent: z.ZodLiteral<"moving_quote">;
247
- name: z.ZodString;
248
- email: z.ZodString;
249
- phone: z.ZodString;
250
- preferred_contact: z.ZodEnum<{
251
- email: "email";
252
- phone: "phone";
253
- any: "any";
254
- }>;
255
- preferred_time: z.ZodEnum<{
256
- any: "any";
257
- morning: "morning";
258
- afternoon: "afternoon";
259
- evening: "evening";
260
- }>;
261
- message: z.ZodString;
262
- meta: z.ZodObject<{
263
- from_address: z.ZodString;
264
- to_address: z.ZodString;
265
- from_postcode: z.ZodNullable<z.ZodString>;
266
- to_postcode: z.ZodNullable<z.ZodString>;
267
- move_date: z.ZodString;
268
- flexible_date: z.ZodBoolean;
269
- property_size: z.ZodString;
270
- floor_from: z.ZodNumber;
271
- floor_to: z.ZodNumber;
272
- has_lift_from: z.ZodBoolean;
273
- has_lift_to: z.ZodBoolean;
274
- packing_required: z.ZodBoolean;
275
- storage_required: z.ZodBoolean;
276
- dismantling_required: z.ZodBoolean;
277
- special_items: z.ZodArray<z.ZodString>;
278
- additional_notes: z.ZodString;
279
- distance_miles: z.ZodNullable<z.ZodNumber>;
280
- duration_minutes: z.ZodNullable<z.ZodNumber>;
281
- pickup_region: z.ZodNullable<z.ZodString>;
282
- delivery_region: z.ZodNullable<z.ZodString>;
283
- pickup_location: z.ZodObject<{
284
- display: z.ZodString;
285
- raw_query: z.ZodNullable<z.ZodString>;
286
- postcode: z.ZodNullable<z.ZodString>;
287
- latitude: z.ZodNullable<z.ZodNumber>;
288
- longitude: z.ZodNullable<z.ZodNumber>;
289
- udprn: z.ZodNullable<z.ZodNumber>;
290
- normalized: z.ZodNullable<z.ZodObject<{
291
- address_line1: z.ZodString;
292
- address_line2: z.ZodString;
293
- city: z.ZodString;
294
- state_region: z.ZodString;
295
- postal_code: z.ZodString;
296
- country_code: z.ZodString;
297
- latitude: z.ZodNullable<z.ZodNumber>;
298
- longitude: z.ZodNullable<z.ZodNumber>;
299
- udprn: z.ZodNullable<z.ZodNumber>;
300
- }, z.core.$strip>>;
301
- directory_region: z.ZodNullable<z.ZodObject<{
302
- major_region_code: z.ZodString;
303
- major_region_label: z.ZodString;
304
- confidence: z.ZodNumber;
305
- match_source: z.ZodString;
306
- }, z.core.$strip>>;
307
- }, z.core.$strip>;
308
- delivery_location: z.ZodObject<{
309
- display: z.ZodString;
310
- raw_query: z.ZodNullable<z.ZodString>;
311
- postcode: z.ZodNullable<z.ZodString>;
312
- latitude: z.ZodNullable<z.ZodNumber>;
313
- longitude: z.ZodNullable<z.ZodNumber>;
314
- udprn: z.ZodNullable<z.ZodNumber>;
315
- normalized: z.ZodNullable<z.ZodObject<{
316
- address_line1: z.ZodString;
317
- address_line2: z.ZodString;
318
- city: z.ZodString;
319
- state_region: z.ZodString;
320
- postal_code: z.ZodString;
321
- country_code: z.ZodString;
322
- latitude: z.ZodNullable<z.ZodNumber>;
323
- longitude: z.ZodNullable<z.ZodNumber>;
324
- udprn: z.ZodNullable<z.ZodNumber>;
325
- }, z.core.$strip>>;
326
- directory_region: z.ZodNullable<z.ZodObject<{
327
- major_region_code: z.ZodString;
328
- major_region_label: z.ZodString;
329
- confidence: z.ZodNumber;
330
- match_source: z.ZodString;
331
- }, z.core.$strip>>;
332
- }, z.core.$strip>;
333
- }, z.core.$strip>;
334
- }, z.core.$strip>;
335
- export type MovingLeadPayload = z.infer<typeof movingLeadPayloadSchema>;
336
- export type MovingBrokerCapturePayload = z.infer<typeof movingBrokerCapturePayloadSchema>;
337
- export declare function buildMovingLeadPayload(input: MovingLeadPayloadInput): MovingLeadPayload;
338
- export declare function buildMovingBrokerCapturePayload(payload: MovingLeadPayload): MovingBrokerCapturePayload;
339
- export declare function readQuoteSubmitError(response: Response): Promise<string>;
340
- export interface MovingLeadReadinessContext {
341
- fromAddress?: MovingAddress | null;
342
- toAddress?: MovingAddress | null;
343
- }
344
- export declare function isMovingLeadReady(payload: MovingLeadPayload, context?: MovingLeadReadinessContext): boolean;
345
- export declare function getMovingLeadValidationItems(payload: MovingLeadPayload, context?: MovingLeadReadinessContext): {
346
- label: string;
347
- valid: boolean;
348
- }[];
@@ -1,267 +0,0 @@
1
- import { z } from "zod";
2
- export function readAddressDisplay(address, fallback) {
3
- return address?.display || address?.rawQuery || fallback;
4
- }
5
- export function hasStructuredMovingAddress(address) {
6
- const line1 = address?.normalized?.address_line1 || address?.address?.line_1 || "";
7
- const city = address?.normalized?.city || address?.address?.post_town || "";
8
- return line1.trim().length > 0 && city.trim().length > 0;
9
- }
10
- export function hasCoordinates(address) {
11
- return Boolean(address?.address &&
12
- typeof address.address.latitude === "number" &&
13
- typeof address.address.longitude === "number");
14
- }
15
- export function formatDuration(minutes) {
16
- if (minutes < 60)
17
- return `${minutes} min`;
18
- const hours = Math.floor(minutes / 60);
19
- const remainder = minutes % 60;
20
- return remainder ? `${hours} hr ${remainder} min` : `${hours} hr`;
21
- }
22
- const optionalNullableString = z.string().nullable();
23
- const contactPreferenceSchema = z.enum(["email", "phone", "any"]);
24
- const timePreferenceSchema = z.enum(["morning", "afternoon", "evening", "any"]);
25
- const movingAddressLocationSchema = z.object({
26
- display: z.string(),
27
- raw_query: optionalNullableString,
28
- postcode: optionalNullableString,
29
- latitude: z.number().nullable(),
30
- longitude: z.number().nullable(),
31
- udprn: z.number().nullable(),
32
- normalized: z.object({
33
- address_line1: z.string(),
34
- address_line2: z.string(),
35
- city: z.string(),
36
- state_region: z.string(),
37
- postal_code: z.string(),
38
- country_code: z.string(),
39
- latitude: z.number().nullable(),
40
- longitude: z.number().nullable(),
41
- udprn: z.number().nullable(),
42
- }).nullable(),
43
- directory_region: z.object({
44
- major_region_code: z.string(),
45
- major_region_label: z.string(),
46
- confidence: z.number(),
47
- match_source: z.string(),
48
- }).nullable(),
49
- });
50
- export const movingLeadPayloadSchema = z.object({
51
- lead_type: z.literal("moving"),
52
- brand: z.string().min(1),
53
- source: z.string().min(1),
54
- intent: z.literal("moving_quote"),
55
- name: z.string(),
56
- email: z.string(),
57
- phone: z.string(),
58
- preferred_contact: contactPreferenceSchema,
59
- preferred_time: timePreferenceSchema,
60
- message: z.string(),
61
- meta: z.object({
62
- from_address: z.string(),
63
- to_address: z.string(),
64
- from_postcode: optionalNullableString,
65
- to_postcode: optionalNullableString,
66
- move_date: z.string(),
67
- flexible_date: z.boolean(),
68
- property_size: z.string().min(1),
69
- floor_from: z.number().int().min(0),
70
- floor_to: z.number().int().min(0),
71
- has_lift_from: z.boolean(),
72
- has_lift_to: z.boolean(),
73
- packing_required: z.boolean(),
74
- storage_required: z.boolean(),
75
- dismantling_required: z.boolean(),
76
- special_items: z.array(z.string()),
77
- additional_notes: z.string(),
78
- distance_miles: z.number().nullable(),
79
- duration_minutes: z.number().nullable(),
80
- pickup_region: optionalNullableString,
81
- delivery_region: optionalNullableString,
82
- pickup_location: movingAddressLocationSchema,
83
- delivery_location: movingAddressLocationSchema,
84
- }),
85
- });
86
- export const movingBrokerCapturePayloadSchema = z.object({
87
- source_type: z.literal("web"),
88
- name: z.string(),
89
- email: z.string(),
90
- phone: z.string(),
91
- message: z.string(),
92
- region: z.string(),
93
- tags: z.array(z.string()).min(1),
94
- meta: movingLeadPayloadSchema,
95
- });
96
- export const movingLeadSubmissionSchema = movingLeadPayloadSchema.superRefine((payload, ctx) => {
97
- if (!payload.meta.from_address.trim()) {
98
- ctx.addIssue({ code: "custom", path: ["meta", "from_address"], message: "Pickup address is required." });
99
- }
100
- if (!payload.meta.to_address.trim()) {
101
- ctx.addIssue({ code: "custom", path: ["meta", "to_address"], message: "Delivery address is required." });
102
- }
103
- if (!payload.name.trim()) {
104
- ctx.addIssue({ code: "custom", path: ["name"], message: "Name is required." });
105
- }
106
- if (!payload.email.trim() && !payload.phone.trim()) {
107
- ctx.addIssue({ code: "custom", path: ["email"], message: "Email or phone is required." });
108
- }
109
- if (payload.email.trim() && !z.email().safeParse(payload.email).success) {
110
- ctx.addIssue({ code: "custom", path: ["email"], message: "Email must be valid." });
111
- }
112
- });
113
- function readAddressPostcode(address) {
114
- return address?.normalized?.postal_code || address?.address?.postcode || null;
115
- }
116
- function readAddressLatitude(address) {
117
- return address?.normalized?.latitude ?? address?.address?.latitude ?? null;
118
- }
119
- function readAddressLongitude(address) {
120
- return address?.normalized?.longitude ?? address?.address?.longitude ?? null;
121
- }
122
- function readAddressUdprn(address) {
123
- return address?.normalized?.udprn ?? address?.address?.udprn ?? null;
124
- }
125
- function buildAddressLocation(address, fallback) {
126
- const normalized = address?.normalized;
127
- return {
128
- display: readAddressDisplay(address, fallback),
129
- raw_query: address?.rawQuery || fallback || null,
130
- postcode: readAddressPostcode(address),
131
- latitude: readAddressLatitude(address),
132
- longitude: readAddressLongitude(address),
133
- udprn: readAddressUdprn(address),
134
- normalized: normalized
135
- ? {
136
- address_line1: normalized.address_line1,
137
- address_line2: normalized.address_line2,
138
- city: normalized.city,
139
- state_region: normalized.state_region,
140
- postal_code: normalized.postal_code,
141
- country_code: normalized.country_code,
142
- latitude: normalized.latitude ?? null,
143
- longitude: normalized.longitude ?? null,
144
- udprn: normalized.udprn ?? null,
145
- }
146
- : null,
147
- directory_region: address?.directory_region ?? null,
148
- };
149
- }
150
- export function buildMovingLeadPayload(input) {
151
- const from = readAddressDisplay(input.fromAddress, input.fromRaw);
152
- const to = readAddressDisplay(input.toAddress, input.toRaw);
153
- return movingLeadPayloadSchema.parse({
154
- lead_type: "moving",
155
- brand: input.brand,
156
- source: input.source,
157
- intent: "moving_quote",
158
- name: input.name,
159
- email: input.email,
160
- phone: input.phone,
161
- preferred_contact: input.preferredContact,
162
- preferred_time: input.preferredTime,
163
- message: input.additionalNotes || `Moving request from ${from || "pickup"} to ${to || "delivery"}.`,
164
- meta: {
165
- from_address: from,
166
- to_address: to,
167
- from_postcode: input.fromAddress?.normalized?.postal_code ?? null,
168
- to_postcode: input.toAddress?.normalized?.postal_code ?? null,
169
- move_date: input.moveDate,
170
- flexible_date: input.flexibleDate,
171
- property_size: input.propertySize,
172
- floor_from: Number(input.floorFrom),
173
- floor_to: Number(input.floorTo),
174
- has_lift_from: input.hasLiftFrom,
175
- has_lift_to: input.hasLiftTo,
176
- packing_required: input.packingRequired,
177
- storage_required: input.storageRequired,
178
- dismantling_required: input.dismantlingRequired,
179
- special_items: input.specialItems
180
- .split(",")
181
- .map((item) => item.trim())
182
- .filter(Boolean),
183
- additional_notes: input.additionalNotes,
184
- distance_miles: input.distance?.distanceMiles ?? null,
185
- duration_minutes: input.distance?.durationMinutes ?? null,
186
- pickup_region: input.fromAddress?.directory_region?.major_region_code ?? null,
187
- delivery_region: input.toAddress?.directory_region?.major_region_code ?? null,
188
- pickup_location: buildAddressLocation(input.fromAddress, input.fromRaw),
189
- delivery_location: buildAddressLocation(input.toAddress, input.toRaw),
190
- },
191
- });
192
- }
193
- export function buildMovingBrokerCapturePayload(payload) {
194
- const region = payload.meta.pickup_region || payload.meta.from_postcode || payload.meta.pickup_location.postcode || "";
195
- return movingBrokerCapturePayloadSchema.parse({
196
- source_type: "web",
197
- name: payload.name,
198
- email: payload.email,
199
- phone: payload.phone,
200
- message: payload.message,
201
- region,
202
- tags: ["moving", "direct", "main_site", payload.brand],
203
- meta: payload,
204
- });
205
- }
206
- // readQuoteSubmitError surfaces a human-readable reason from a failed /api/leads
207
- // response. The lead route returns friendly `message` fields for its own
208
- // rejections (cross-origin, app-not-available, contact-required, …); terse
209
- // pass-through backend codes (e.g. "invalid input") fall back to a status-based
210
- // message so the user is never shown a raw internal string.
211
- export async function readQuoteSubmitError(response) {
212
- const fallback = response.status >= 500
213
- ? "Something went wrong on our end. Please try again shortly."
214
- : "We could not submit this request. Please check the details and try again.";
215
- try {
216
- const body = (await response.json());
217
- const message = typeof body.message === "string" ? body.message.trim() : "";
218
- if (message && message.toLowerCase() !== "invalid input") {
219
- return message;
220
- }
221
- }
222
- catch {
223
- // Non-JSON or empty body — use the status-based fallback.
224
- }
225
- return fallback;
226
- }
227
- export function isMovingLeadReady(payload, context = {}) {
228
- if (!movingLeadSubmissionSchema.safeParse(payload).success)
229
- return false;
230
- if ("fromAddress" in context && !hasStructuredMovingAddress(context.fromAddress ?? null))
231
- return false;
232
- if ("toAddress" in context && !hasStructuredMovingAddress(context.toAddress ?? null))
233
- return false;
234
- return true;
235
- }
236
- export function getMovingLeadValidationItems(payload, context = {}) {
237
- const result = movingLeadSubmissionSchema.safeParse(payload);
238
- const issuePaths = new Set(result.success ? [] : result.error.issues.map((issue) => issue.path.join(".")));
239
- const fromAddressValid = issuePaths.has("meta.from_address")
240
- ? false
241
- : "fromAddress" in context
242
- ? hasStructuredMovingAddress(context.fromAddress ?? null)
243
- : true;
244
- const toAddressValid = issuePaths.has("meta.to_address")
245
- ? false
246
- : "toAddress" in context
247
- ? hasStructuredMovingAddress(context.toAddress ?? null)
248
- : true;
249
- return [
250
- {
251
- label: "Pickup address",
252
- valid: fromAddressValid,
253
- },
254
- {
255
- label: "Delivery address",
256
- valid: toAddressValid,
257
- },
258
- {
259
- label: "Name",
260
- valid: !issuePaths.has("name"),
261
- },
262
- {
263
- label: "Email or phone",
264
- valid: !issuePaths.has("email"),
265
- },
266
- ];
267
- }
@@ -1,76 +0,0 @@
1
- import "server-only";
2
- import { createChannelClient, type ChannelCheckoutStatusParams, type ChannelMutationOptions } from "./index.js";
3
- import type { AddCartItemInput, CartResponse, CheckoutAddressesInput, CheckoutCustomerInput, CheckoutFulfillmentInput, CheckoutOptions, CheckoutPayInput, CheckoutPayResponse, CheckoutStatusResponse, Order } from "./types.js";
4
- export interface CartCookieAttributes {
5
- httpOnly: true;
6
- secure: boolean;
7
- sameSite: "lax";
8
- path: "/";
9
- maxAge: number;
10
- }
11
- export declare const cartCookie: {
12
- readonly name: "cart_token";
13
- readonly attributes: (isProduction?: boolean) => CartCookieAttributes;
14
- /**
15
- * The client mints the token (the server accepts any sufficiently-random
16
- * bearer key and creates the cart row on first use).
17
- */
18
- readonly mint: () => string;
19
- /** Tolerant read: an absent or garbage cookie means "no cart yet". */
20
- readonly parse: (raw: string | undefined) => string | null;
21
- };
22
- type CartClient = Pick<ReturnType<typeof createChannelClient>, "cart" | "checkout">;
23
- export interface CreateCartOptions {
24
- /** The channel client, or a lazy resolver (the singleton pattern). */
25
- client: CartClient | (() => CartClient);
26
- }
27
- /**
28
- * Cart + checkout, with the token threading done for you. Every method returns
29
- * the cart's underlying ORDER — checkout steps are addressed by its id.
30
- */
31
- export declare function createCart(options: CreateCartOptions): {
32
- readonly cookie: {
33
- readonly name: "cart_token";
34
- readonly attributes: (isProduction?: boolean) => CartCookieAttributes;
35
- /**
36
- * The client mints the token (the server accepts any sufficiently-random
37
- * bearer key and creates the cart row on first use).
38
- */
39
- readonly mint: () => string;
40
- /** Tolerant read: an absent or garbage cookie means "no cart yet". */
41
- readonly parse: (raw: string | undefined) => string | null;
42
- };
43
- /** Null when the token has no cart yet — a new visitor, not an error. */
44
- readonly get: (cartToken: string) => Promise<Order | null>;
45
- readonly addItem: (input: AddCartItemInput) => Promise<CartResponse>;
46
- readonly updateItem: (itemId: string, cartToken: string, quantity: number) => Promise<CartResponse>;
47
- readonly removeItem: (itemId: string, cartToken: string) => Promise<CartResponse>;
48
- readonly clear: (cartToken: string) => Promise<CartResponse>;
49
- /**
50
- * Call in the same Server Action that sets the session cookie: the guest's
51
- * cart follows the customer into their account instead of evaporating at
52
- * the sign-in door.
53
- */
54
- readonly mergeOnSignIn: (guestCartToken: string, customerCartToken: string) => Promise<CartResponse>;
55
- /** Checkout steps, addressed by the order the cart became. */
56
- readonly checkout: {
57
- readonly options: (orderId: string, cartToken: string) => Promise<CheckoutOptions>;
58
- readonly status: (orderId: string, params?: ChannelCheckoutStatusParams) => Promise<CheckoutStatusResponse>;
59
- readonly setCustomer: (orderId: string, input: CheckoutCustomerInput) => Promise<CartResponse>;
60
- readonly setAddresses: (orderId: string, input: CheckoutAddressesInput) => Promise<CartResponse>;
61
- readonly setFulfillment: (orderId: string, input: CheckoutFulfillmentInput) => Promise<CartResponse>;
62
- /**
63
- * Returns the Stripe-hosted redirect URL. `return_url` is REQUIRED for a
64
- * channel checkout (our API's host means nothing to your shopper) and
65
- * must be on the channel's registered site_url — the server refuses
66
- * anything else, because an unchecked return URL is an open redirect.
67
- */
68
- readonly pay: (orderId: string, input: CheckoutPayInput & {
69
- return_url: string;
70
- }, attempt: ChannelMutationOptions & {
71
- idempotencyKey: string;
72
- }) => Promise<CheckoutPayResponse>;
73
- };
74
- };
75
- export type CartKit = ReturnType<typeof createCart>;
76
- export {};