@sonordev/contracts 2.25.0 → 2.27.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/CHANGELOG.md +12 -0
- package/README.md +67 -0
- package/dist/booking-intake-normalize.d.ts +152 -0
- package/dist/booking-intake.d.ts +68 -0
- package/dist/booking-intake.js +221 -0
- package/dist/booking-intake.mjs +203 -0
- package/dist/property-interest.d.ts +100 -0
- package/dist/property-interest.js +261 -0
- package/dist/property-interest.mjs +244 -0
- package/dist/quote-screen.d.ts +29 -0
- package/dist/quote-screen.js +194 -0
- package/dist/quote-screen.mjs +190 -0
- package/dist/quote-screen.vectors.d.ts +23 -0
- package/dist/resonance-confirmation.d.ts +238 -0
- package/dist/resonance-confirmation.js +163 -0
- package/dist/resonance-confirmation.mjs +131 -0
- package/dist/resonance.d.ts +266 -2
- package/dist/resonance.js +263 -6
- package/dist/resonance.mjs +246 -7
- package/dist/schema-placeholders.d.ts +2 -2
- package/dist/seo-pages.js +3 -3
- package/dist/seo-pages.mjs +3 -3
- package/dist/sites-normalize.d.ts +7 -0
- package/dist/sites.d.ts +1 -3
- package/dist/sites.js +3 -3
- package/dist/sites.mjs +3 -3
- package/package.json +22 -2
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// src/contracts/sites-normalize.ts
|
|
2
|
+
function normalizeSiteHost(site) {
|
|
3
|
+
if (!site || typeof site !== "string") return null;
|
|
4
|
+
let s = site.trim().toLowerCase();
|
|
5
|
+
if (!s) return null;
|
|
6
|
+
s = s.replace(/^https?:\/\//, "");
|
|
7
|
+
const slash = s.indexOf("/");
|
|
8
|
+
if (slash >= 0) s = s.slice(0, slash);
|
|
9
|
+
const colon = s.indexOf(":");
|
|
10
|
+
if (colon >= 0) s = s.slice(0, colon);
|
|
11
|
+
s = s.replace(/\.+$/, "");
|
|
12
|
+
return s || null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/contracts/public-url-host.ts
|
|
16
|
+
function isPrivateIpv4(a, b) {
|
|
17
|
+
return a === 127 || a === 10 || a === 0 || a === 192 && b === 168 || a === 172 && b >= 16 && b <= 31 || a === 169 && b === 254 || a === 100 && b >= 64 && b <= 127 || a >= 224;
|
|
18
|
+
}
|
|
19
|
+
function ipv6Words(host) {
|
|
20
|
+
if (!host.includes(":") || !/^[a-f\d:.]+$/.test(host)) return null;
|
|
21
|
+
let canonical;
|
|
22
|
+
try {
|
|
23
|
+
canonical = new URL(`http://[${host}]/`).hostname.slice(1, -1);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const sides = canonical.split("::");
|
|
28
|
+
const left = sides[0] ? sides[0].split(":") : [];
|
|
29
|
+
const right = sides.length > 1 && sides[1] ? sides[1].split(":") : [];
|
|
30
|
+
return [...left, ...Array(sides.length > 1 ? 8 - left.length - right.length : 0).fill("0"), ...right].map((word) => parseInt(word, 16));
|
|
31
|
+
}
|
|
32
|
+
function isBlockedPublicUrlHost(rawHost) {
|
|
33
|
+
const host = rawHost.toLowerCase().replace(/^\[|\]$/g, "");
|
|
34
|
+
const blockedName = host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
35
|
+
if (host.includes(":") && host.includes("%")) return true;
|
|
36
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
37
|
+
const blockedIp = !!ipv4 && isPrivateIpv4(Number(ipv4[1]), Number(ipv4[2]));
|
|
38
|
+
const words = ipv6Words(host);
|
|
39
|
+
const blockedIpv6 = !!words && // Unspecified/loopback, unique-local, link-local, deprecated site-local
|
|
40
|
+
// and multicast destinations aren't public logo/webhook endpoints.
|
|
41
|
+
(words.every((word) => word === 0) || words.slice(0, 7).every((word) => word === 0) && words[7] === 1 || (words[0] & 65024) === 64512 || (words[0] & 65472) === 65152 || (words[0] & 65472) === 65216 || (words[0] & 65280) === 65280 || // IPv4-mapped and older IPv4-compatible forms carry an IPv4 destination.
|
|
42
|
+
words.slice(0, 5).every((word) => word === 0) && [0, 65535].includes(words[5]) && isPrivateIpv4(words[6] >> 8, words[6] & 255));
|
|
43
|
+
return blockedName || blockedIp || blockedIpv6;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/contracts/booking-intake-normalize.ts
|
|
47
|
+
var BOOKING_BUSINESS_STEPS = ["off", "optional", "required"];
|
|
48
|
+
function parseBookingBusinessStep(value) {
|
|
49
|
+
return BOOKING_BUSINESS_STEPS.includes(value) ? value : "off";
|
|
50
|
+
}
|
|
51
|
+
function bookingAsksBusiness(step) {
|
|
52
|
+
return parseBookingBusinessStep(step) !== "off";
|
|
53
|
+
}
|
|
54
|
+
var BOOKING_GUEST_BUSINESS_FIELDS = { company: "company", website: "website", noWebsite: "noWebsite" };
|
|
55
|
+
var BOOKING_COMPANY_MAX = 120;
|
|
56
|
+
var BOOKING_WEBSITE_INPUT_MAX = 300;
|
|
57
|
+
var BOOKING_WEBSITE_URL_MAX = 300;
|
|
58
|
+
var NAME_WHITESPACE = /[\t\n\v\f\r \u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]+/gu;
|
|
59
|
+
var NAME_REMOVED = /[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
60
|
+
var characters = (text) => Array.from(text).length;
|
|
61
|
+
function normalizeBookingCompany(value) {
|
|
62
|
+
if (typeof value !== "string") return null;
|
|
63
|
+
const text = value.replace(NAME_WHITESPACE, " ").replace(NAME_REMOVED, "").replace(/ {2,}/g, " ").trim();
|
|
64
|
+
return text || null;
|
|
65
|
+
}
|
|
66
|
+
var INVALID = { ok: false, reason: "invalid" };
|
|
67
|
+
var TOO_LONG = { ok: false, reason: "too_long" };
|
|
68
|
+
var PUBLIC_TLD = /^(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/;
|
|
69
|
+
var HOST_LABEL = /^[a-z0-9_-]{1,63}$/;
|
|
70
|
+
function normalizeGuestWebsite(value) {
|
|
71
|
+
if (value === null || value === void 0) return null;
|
|
72
|
+
if (typeof value !== "string") return INVALID;
|
|
73
|
+
const text = value.trim();
|
|
74
|
+
if (!text) return null;
|
|
75
|
+
if (characters(text) > BOOKING_WEBSITE_INPUT_MAX) return TOO_LONG;
|
|
76
|
+
if (/[\s\p{Cc}\p{Cf}\\]/u.test(text)) return INVALID;
|
|
77
|
+
let candidate;
|
|
78
|
+
const looksLikeScheme = /^[a-z][a-z0-9+.-]*:/i.test(text);
|
|
79
|
+
const hostWithPort = /^[^/?#@:]+:\d+(?:[/?#]|$)/.test(text);
|
|
80
|
+
if (looksLikeScheme && !hostWithPort) {
|
|
81
|
+
const explicit = /^https?:\/\/(.*)$/i.exec(text);
|
|
82
|
+
if (!explicit || explicit[1].startsWith("/")) return INVALID;
|
|
83
|
+
candidate = text;
|
|
84
|
+
} else {
|
|
85
|
+
if (text.startsWith("/")) return INVALID;
|
|
86
|
+
candidate = `https://${text}`;
|
|
87
|
+
}
|
|
88
|
+
let url;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(candidate);
|
|
91
|
+
} catch {
|
|
92
|
+
return INVALID;
|
|
93
|
+
}
|
|
94
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return INVALID;
|
|
95
|
+
if (url.username || url.password || url.port) return INVALID;
|
|
96
|
+
if (url.hostname.startsWith("[")) return INVALID;
|
|
97
|
+
const host = normalizeSiteHost(url.hostname);
|
|
98
|
+
if (!host || host.length > 253) return INVALID;
|
|
99
|
+
const labels = host.split(".");
|
|
100
|
+
if (labels.length < 2 || !labels.every((label) => HOST_LABEL.test(label))) return INVALID;
|
|
101
|
+
if (!PUBLIC_TLD.test(labels[labels.length - 1])) return INVALID;
|
|
102
|
+
if (isBlockedPublicUrlHost(host)) return INVALID;
|
|
103
|
+
const canonical = `${url.protocol}//${host}${url.pathname.replace(/\/+$/, "")}`;
|
|
104
|
+
if (canonical.length > BOOKING_WEBSITE_URL_MAX) return TOO_LONG;
|
|
105
|
+
const shown = labels[0] === "www" && labels.length > 2 ? labels.slice(1).join(".") : host;
|
|
106
|
+
return { ok: true, url: canonical, host: shown };
|
|
107
|
+
}
|
|
108
|
+
var BOOKING_BUSINESS_EXEMPT_SOURCES = ["portal"];
|
|
109
|
+
function bookingBusinessExempt(source, verifiedMember) {
|
|
110
|
+
return verifiedMember === true && typeof source === "string" && BOOKING_BUSINESS_EXEMPT_SOURCES.includes(source);
|
|
111
|
+
}
|
|
112
|
+
function checkBookingBusinessAnswers(step, input, opts = {}) {
|
|
113
|
+
const enforced = bookingAsksBusiness(step) && !bookingBusinessExempt(opts.source, opts.verifiedMember);
|
|
114
|
+
const required = enforced && parseBookingBusinessStep(step) === "required";
|
|
115
|
+
const errors = {};
|
|
116
|
+
const dropped = {};
|
|
117
|
+
let company = normalizeBookingCompany(input?.company);
|
|
118
|
+
if (company !== null && characters(company) > BOOKING_COMPANY_MAX) {
|
|
119
|
+
if (enforced) errors.company = "too_long";
|
|
120
|
+
else dropped.company = "too_long";
|
|
121
|
+
company = null;
|
|
122
|
+
} else if (company === null && required) {
|
|
123
|
+
errors.company = "required";
|
|
124
|
+
}
|
|
125
|
+
const noWebsite = input?.noWebsite === true;
|
|
126
|
+
let website = null;
|
|
127
|
+
if (!noWebsite) {
|
|
128
|
+
const parsed = normalizeGuestWebsite(input?.website);
|
|
129
|
+
if (parsed === null) website = null;
|
|
130
|
+
else if (parsed.ok) website = parsed.url;
|
|
131
|
+
else if (enforced) errors.website = parsed.reason;
|
|
132
|
+
else dropped.website = parsed.reason;
|
|
133
|
+
}
|
|
134
|
+
if (errors.company || errors.website) return { ok: false, errors };
|
|
135
|
+
return { ok: true, value: { company, website, noWebsite, dropped } };
|
|
136
|
+
}
|
|
137
|
+
var BOOKING_BUSINESS_ERROR_TEXT = {
|
|
138
|
+
company_required: "Please add your company name, or your own name if you work for yourself.",
|
|
139
|
+
company_too_long: `That name's a little long. Please keep it to ${BOOKING_COMPANY_MAX} characters or fewer.`,
|
|
140
|
+
website_invalid: "That doesn't look like a web address. Try something like yourcompany.com.",
|
|
141
|
+
website_too_long: "That address is too long. The main address is enough, like yourcompany.com."
|
|
142
|
+
};
|
|
143
|
+
function describeBookingBusinessErrors(errors) {
|
|
144
|
+
const text = {};
|
|
145
|
+
if (errors.company) text.company = errors.company === "required" ? BOOKING_BUSINESS_ERROR_TEXT.company_required : BOOKING_BUSINESS_ERROR_TEXT.company_too_long;
|
|
146
|
+
if (errors.website) text.website = errors.website === "invalid" ? BOOKING_BUSINESS_ERROR_TEXT.website_invalid : BOOKING_BUSINESS_ERROR_TEXT.website_too_long;
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/contracts/booking-intake.ts
|
|
151
|
+
var BOOKING_INTAKE_CONTRACT_VERSION = 1;
|
|
152
|
+
var BOOKING_INTAKE_JSON_SCHEMA = {
|
|
153
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
154
|
+
$id: "https://sonor.io/schemas/booking-intake.v1.json",
|
|
155
|
+
title: "BookingGuestBusinessAnswers",
|
|
156
|
+
description: "What a guest tells a booking about their business: a company name (their own name if they work for themselves), a website address if they have one, and a flag for 'we don't have a website yet', which wins over any website sent with it.",
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
company: {
|
|
160
|
+
type: ["string", "null"],
|
|
161
|
+
maxLength: BOOKING_COMPANY_MAX,
|
|
162
|
+
description: "Company name. Required when the booking type's business step is required. The length is measured after cleaning: extra whitespace and control characters don't count."
|
|
163
|
+
},
|
|
164
|
+
website: {
|
|
165
|
+
type: ["string", "null"],
|
|
166
|
+
maxLength: BOOKING_WEBSITE_INPUT_MAX,
|
|
167
|
+
description: "A public http or https address, or a bare domain like example.com. Credentials, ports, IP addresses and the local names localhost, .local and .internal are refused. The query and fragment are dropped and the path is kept. The length is measured after trimming."
|
|
168
|
+
},
|
|
169
|
+
noWebsite: {
|
|
170
|
+
type: ["boolean", "null"],
|
|
171
|
+
description: "True when the guest has no website yet. A website sent with it is ignored."
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function bookingBusinessDetails(row, contact) {
|
|
176
|
+
const fromRow = {
|
|
177
|
+
company: normalizeBookingCompany(row?.guest_company),
|
|
178
|
+
website: readWebsite(row?.guest_website),
|
|
179
|
+
noWebsite: row?.guest_no_website === true
|
|
180
|
+
};
|
|
181
|
+
const fromContact = {
|
|
182
|
+
company: normalizeBookingCompany(contact?.company),
|
|
183
|
+
website: readWebsite(contact?.website)
|
|
184
|
+
};
|
|
185
|
+
const company = fromRow.company ?? fromContact.company;
|
|
186
|
+
const website = fromRow.website ?? (fromRow.noWebsite ? null : fromContact.website);
|
|
187
|
+
const noWebsite = fromRow.noWebsite && website === null;
|
|
188
|
+
const guestAnswered = fromRow.company !== null || fromRow.website !== null || fromRow.noWebsite;
|
|
189
|
+
const contactSupplied = fromRow.company === null && fromContact.company !== null || fromRow.website === null && website !== null;
|
|
190
|
+
return {
|
|
191
|
+
company,
|
|
192
|
+
website: website?.url ?? null,
|
|
193
|
+
websiteHost: website?.host ?? null,
|
|
194
|
+
noWebsite,
|
|
195
|
+
from: guestAnswered ? "booking" : contactSupplied ? "contact" : null
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function readWebsite(value) {
|
|
199
|
+
const parsed = normalizeGuestWebsite(value);
|
|
200
|
+
return parsed && parsed.ok ? { url: parsed.url, host: parsed.host } : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { BOOKING_BUSINESS_ERROR_TEXT, BOOKING_BUSINESS_EXEMPT_SOURCES, BOOKING_BUSINESS_STEPS, BOOKING_COMPANY_MAX, BOOKING_GUEST_BUSINESS_FIELDS, BOOKING_INTAKE_CONTRACT_VERSION, BOOKING_INTAKE_JSON_SCHEMA, BOOKING_WEBSITE_INPUT_MAX, BOOKING_WEBSITE_URL_MAX, bookingAsksBusiness, bookingBusinessDetails, bookingBusinessExempt, checkBookingBusinessAnswers, describeBookingBusinessErrors, normalizeBookingCompany, normalizeGuestWebsite, parseBookingBusinessStep };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Value } from './wire-schema';
|
|
2
|
+
export declare const PROPERTY_INTEREST_CATEGORY: 'real_estate_interest';
|
|
3
|
+
export declare const PROPERTY_INTEREST_EVENT_NAMES: readonly ['property_exposed', 'gallery_open', 'detail_open', 'property_selected'];
|
|
4
|
+
export declare const PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS = 28;
|
|
5
|
+
export declare const PROPERTY_INTEREST_MAX_WINDOW_DAYS = 90;
|
|
6
|
+
export declare const PROPERTY_INTEREST_MAX_LISTINGS = 50;
|
|
7
|
+
export declare class PropertyInterestValidationError extends Error {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
constructor(path: string, reason: string);
|
|
10
|
+
}
|
|
11
|
+
declare const eventProperties: import("./wire-schema").Field<{
|
|
12
|
+
schema_version: 1;
|
|
13
|
+
listing_id: string;
|
|
14
|
+
surface: "collection" | "detail";
|
|
15
|
+
} & {
|
|
16
|
+
ordinal?: number | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
declare const event: import("./wire-schema").Field<{
|
|
19
|
+
category: "real_estate_interest";
|
|
20
|
+
name: "detail_open" | "gallery_open" | "property_exposed" | "property_selected";
|
|
21
|
+
properties: {
|
|
22
|
+
schema_version: 1;
|
|
23
|
+
listing_id: string;
|
|
24
|
+
surface: "collection" | "detail";
|
|
25
|
+
} & {
|
|
26
|
+
ordinal?: number | undefined;
|
|
27
|
+
};
|
|
28
|
+
} & {}>;
|
|
29
|
+
export type PropertyInterestEventProperties = Value<typeof eventProperties>;
|
|
30
|
+
export type PropertyInterestEvent = Value<typeof event>;
|
|
31
|
+
export declare const parsePropertyInterestEventProperties: (value: unknown) => PropertyInterestEventProperties;
|
|
32
|
+
export declare const parsePropertyInterestEvent: (value: unknown) => PropertyInterestEvent;
|
|
33
|
+
export declare const PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA: import("./wire-schema").JsonSchema;
|
|
34
|
+
export declare const PROPERTY_INTEREST_EVENT_JSON_SCHEMA: import("./wire-schema").JsonSchema;
|
|
35
|
+
declare const reportRequest: import("./wire-schema").Field<{
|
|
36
|
+
site: string;
|
|
37
|
+
} & {
|
|
38
|
+
from?: string | undefined;
|
|
39
|
+
to?: string | undefined;
|
|
40
|
+
listingIds?: string[] | undefined;
|
|
41
|
+
cursor?: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export type PropertyInterestReportRequest = Value<typeof reportRequest>;
|
|
44
|
+
export declare const parsePropertyInterestReportRequest: (value: unknown) => PropertyInterestReportRequest;
|
|
45
|
+
export declare const PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA: import("./wire-schema").JsonSchema;
|
|
46
|
+
/** Basis points rounded to nearest, with halves rounded up. A missing denominator stays null. */
|
|
47
|
+
export declare function propertyInterestRateBps(eligibleSessions: number, exposureSessions: number): number | null;
|
|
48
|
+
declare const report: import("./wire-schema").Field<{
|
|
49
|
+
schemaVersion: 1;
|
|
50
|
+
scope: "site";
|
|
51
|
+
site: string;
|
|
52
|
+
from: string;
|
|
53
|
+
to: string;
|
|
54
|
+
observedAt: string;
|
|
55
|
+
properties: ({
|
|
56
|
+
listingId: string;
|
|
57
|
+
displayAddress: string | null;
|
|
58
|
+
slug: string | null;
|
|
59
|
+
status: "active" | "expired" | "pending" | "sold" | "withdrawn" | null;
|
|
60
|
+
surfaces: ({
|
|
61
|
+
surface: "collection" | "detail";
|
|
62
|
+
exposureSessions: number;
|
|
63
|
+
missingSessionEvents: number;
|
|
64
|
+
actions: {
|
|
65
|
+
gallery_open: {
|
|
66
|
+
eligibleSessions: number;
|
|
67
|
+
unmatchedSessions: number;
|
|
68
|
+
rateBps: number | null;
|
|
69
|
+
} & {};
|
|
70
|
+
detail_open: {
|
|
71
|
+
eligibleSessions: number;
|
|
72
|
+
unmatchedSessions: number;
|
|
73
|
+
rateBps: number | null;
|
|
74
|
+
} & {};
|
|
75
|
+
property_selected: {
|
|
76
|
+
eligibleSessions: number;
|
|
77
|
+
unmatchedSessions: number;
|
|
78
|
+
rateBps: number | null;
|
|
79
|
+
} & {};
|
|
80
|
+
} & {};
|
|
81
|
+
} & {})[];
|
|
82
|
+
acceptedTourInquiries: ({
|
|
83
|
+
state: "available";
|
|
84
|
+
count: number;
|
|
85
|
+
source: "native_listing_accepted_tour_form";
|
|
86
|
+
} & {}) | ({
|
|
87
|
+
state: "unavailable";
|
|
88
|
+
count: null;
|
|
89
|
+
source: null;
|
|
90
|
+
} & {});
|
|
91
|
+
} & {})[];
|
|
92
|
+
hasMore: boolean;
|
|
93
|
+
nextCursor: string | null;
|
|
94
|
+
} & {}>;
|
|
95
|
+
export type PropertyInterestReport = Value<typeof report>;
|
|
96
|
+
export declare const parsePropertyInterestReport: (value: unknown) => PropertyInterestReport;
|
|
97
|
+
export declare const PROPERTY_INTEREST_REPORT_JSON_SCHEMA: import("./wire-schema").JsonSchema;
|
|
98
|
+
/** Binds a closed response to its query. The native owner still authenticates site and listing scope. */
|
|
99
|
+
export declare function parsePropertyInterestReportForRequest(value: unknown, request: unknown): PropertyInterestReport;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/contracts/public-url-host.ts
|
|
4
|
+
function isPrivateIpv4(a, b) {
|
|
5
|
+
return a === 127 || a === 10 || a === 0 || a === 192 && b === 168 || a === 172 && b >= 16 && b <= 31 || a === 169 && b === 254 || a === 100 && b >= 64 && b <= 127 || a >= 224;
|
|
6
|
+
}
|
|
7
|
+
function ipv6Words(host) {
|
|
8
|
+
if (!host.includes(":") || !/^[a-f\d:.]+$/.test(host)) return null;
|
|
9
|
+
let canonical;
|
|
10
|
+
try {
|
|
11
|
+
canonical = new URL(`http://[${host}]/`).hostname.slice(1, -1);
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const sides = canonical.split("::");
|
|
16
|
+
const left = sides[0] ? sides[0].split(":") : [];
|
|
17
|
+
const right = sides.length > 1 && sides[1] ? sides[1].split(":") : [];
|
|
18
|
+
return [...left, ...Array(sides.length > 1 ? 8 - left.length - right.length : 0).fill("0"), ...right].map((word) => parseInt(word, 16));
|
|
19
|
+
}
|
|
20
|
+
function isBlockedPublicUrlHost(rawHost) {
|
|
21
|
+
const host = rawHost.toLowerCase().replace(/^\[|\]$/g, "");
|
|
22
|
+
const blockedName = host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
23
|
+
if (host.includes(":") && host.includes("%")) return true;
|
|
24
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
25
|
+
const blockedIp = !!ipv4 && isPrivateIpv4(Number(ipv4[1]), Number(ipv4[2]));
|
|
26
|
+
const words = ipv6Words(host);
|
|
27
|
+
const blockedIpv6 = !!words && // Unspecified/loopback, unique-local, link-local, deprecated site-local
|
|
28
|
+
// and multicast destinations aren't public logo/webhook endpoints.
|
|
29
|
+
(words.every((word) => word === 0) || words.slice(0, 7).every((word) => word === 0) && words[7] === 1 || (words[0] & 65024) === 64512 || (words[0] & 65472) === 65152 || (words[0] & 65472) === 65216 || (words[0] & 65280) === 65280 || // IPv4-mapped and older IPv4-compatible forms carry an IPv4 destination.
|
|
30
|
+
words.slice(0, 5).every((word) => word === 0) && [0, 65535].includes(words[5]) && isPrivateIpv4(words[6] >> 8, words[6] & 255));
|
|
31
|
+
return blockedName || blockedIp || blockedIpv6;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/contracts/sites-normalize.ts
|
|
35
|
+
function normalizeSiteHost(site2) {
|
|
36
|
+
if (!site2 || typeof site2 !== "string") return null;
|
|
37
|
+
let s = site2.trim().toLowerCase();
|
|
38
|
+
if (!s) return null;
|
|
39
|
+
s = s.replace(/^https?:\/\//, "");
|
|
40
|
+
const slash = s.indexOf("/");
|
|
41
|
+
if (slash >= 0) s = s.slice(0, slash);
|
|
42
|
+
const colon = s.indexOf(":");
|
|
43
|
+
if (colon >= 0) s = s.slice(0, colon);
|
|
44
|
+
s = s.replace(/\.+$/, "");
|
|
45
|
+
return s || null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/contracts/sites.ts
|
|
49
|
+
function isNormalizedSiteHost(value) {
|
|
50
|
+
return typeof value === "string" && value.length > 0 && normalizeSiteHost(value) === value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/contracts/wire-schema.ts
|
|
54
|
+
function createWireSchema(fail2, isValidationError) {
|
|
55
|
+
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
56
|
+
const field = (schema, read) => ({ schema, read });
|
|
57
|
+
const text2 = (max = 200, pattern, min = 1) => field({ type: "string", minLength: min, maxLength: max, ...pattern ? { pattern: pattern.source } : {} }, (v, p) => typeof v === "string" && v.length >= min && v.length <= max && (!pattern || pattern.test(v)) ? v : fail2(p, "invalid string"));
|
|
58
|
+
const choice2 = (...values) => field({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v : fail2(p, "unsupported value"));
|
|
59
|
+
const literal2 = (value) => field({ const: value }, (v, p) => v === value ? value : fail2(p, "unexpected value"));
|
|
60
|
+
const integer2 = (min = 0, max = Number.MAX_SAFE_INTEGER) => field({ type: "integer", minimum: min, maximum: max }, (v, p) => typeof v === "number" && Number.isSafeInteger(v) && v >= min && v <= max ? v : fail2(p, "invalid integer"));
|
|
61
|
+
const bool2 = field({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v : fail2(p, "must be boolean"));
|
|
62
|
+
const optional2 = (f) => ({ ...f, optional: true });
|
|
63
|
+
const nullable2 = (f) => field({ anyOf: [f.schema, { type: "null" }] }, (v, p) => v === null ? null : f.read(v, p));
|
|
64
|
+
const list2 = (f, max = 100, min = 0) => field({ type: "array", items: f.schema, minItems: min, maxItems: max }, (v, p) => {
|
|
65
|
+
if (!Array.isArray(v) || v.length < min || v.length > max) fail2(p, "invalid array");
|
|
66
|
+
return v.map((x, i) => f.read(x, `${p}[${i}]`));
|
|
67
|
+
});
|
|
68
|
+
const object2 = (fields) => field({ type: "object", additionalProperties: false, properties: Object.fromEntries(Object.entries(fields).map(([k, f]) => [k, f.schema])), required: Object.keys(fields).filter((k) => !("optional" in fields[k])) }, (v, p) => {
|
|
69
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) fail2(p, "must be a plain object");
|
|
70
|
+
const source = v, result = {};
|
|
71
|
+
for (const key of Reflect.ownKeys(source)) if (typeof key !== "string" || !own(fields, key)) fail2(p, "unknown field");
|
|
72
|
+
for (const [key, f] of Object.entries(fields)) {
|
|
73
|
+
if (!own(source, key)) {
|
|
74
|
+
if ("optional" in f) continue;
|
|
75
|
+
fail2(`${p}.${key}`, "required");
|
|
76
|
+
}
|
|
77
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
78
|
+
if (!own(descriptor, "value")) fail2(`${p}.${key}`, "accessors are not wire data");
|
|
79
|
+
result[key] = f.read(descriptor.value, `${p}.${key}`);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
});
|
|
83
|
+
const union2 = (...fields) => field({ oneOf: fields.map((f) => f.schema) }, (v, p) => {
|
|
84
|
+
const found = [];
|
|
85
|
+
for (const f of fields) {
|
|
86
|
+
try {
|
|
87
|
+
found.push(f.read(v, p));
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (!isValidationError(e)) throw e;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return found.length === 1 ? found[0] : fail2(p, "must match exactly one supported shape");
|
|
93
|
+
});
|
|
94
|
+
const refine2 = (f, check) => field(f.schema, (v, p) => {
|
|
95
|
+
const result = f.read(v, p);
|
|
96
|
+
check(result, p);
|
|
97
|
+
return result;
|
|
98
|
+
});
|
|
99
|
+
return { field, text: text2, choice: choice2, literal: literal2, integer: integer2, bool: bool2, optional: optional2, nullable: nullable2, list: list2, object: object2, union: union2, refine: refine2 };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/contracts/wire-uuid.ts
|
|
103
|
+
var UUID_V1_TO_V8_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89aAbB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
104
|
+
|
|
105
|
+
// src/contracts/property-interest.ts
|
|
106
|
+
var PROPERTY_INTEREST_CATEGORY = "real_estate_interest";
|
|
107
|
+
var PROPERTY_INTEREST_EVENT_NAMES = ["property_exposed", "gallery_open", "detail_open", "property_selected"];
|
|
108
|
+
var PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS = 28;
|
|
109
|
+
var PROPERTY_INTEREST_MAX_WINDOW_DAYS = 90;
|
|
110
|
+
var PROPERTY_INTEREST_MAX_LISTINGS = 50;
|
|
111
|
+
var PropertyInterestValidationError = class extends Error {
|
|
112
|
+
constructor(path, reason) {
|
|
113
|
+
super(`${path}: ${reason}`);
|
|
114
|
+
this.path = path;
|
|
115
|
+
this.name = "PropertyInterestValidationError";
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var fail = (path, reason) => {
|
|
119
|
+
throw new PropertyInterestValidationError(path, reason);
|
|
120
|
+
};
|
|
121
|
+
var { bool, choice, integer, list, literal, nullable, object, optional, refine, text, union } = createWireSchema(fail, (error) => error instanceof PropertyInterestValidationError);
|
|
122
|
+
var listingId = text(36, UUID_V1_TO_V8_PATTERN);
|
|
123
|
+
var surface = choice("collection", "detail");
|
|
124
|
+
var site = refine(text(253), (value, at) => {
|
|
125
|
+
if (!isNormalizedSiteHost(value) || isBlockedPublicUrlHost(value)) fail(at, "requires a normalized public site host");
|
|
126
|
+
});
|
|
127
|
+
var instant = refine(text(24, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (value, at) => {
|
|
128
|
+
const epoch = Date.parse(value);
|
|
129
|
+
if (!Number.isFinite(epoch) || new Date(epoch).toISOString().replace(".000Z", "Z") !== value.replace(".000Z", "Z")) {
|
|
130
|
+
fail(at, "requires a valid UTC instant");
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
var dayMs = 864e5;
|
|
134
|
+
var eventProperties = object({
|
|
135
|
+
schema_version: literal(1),
|
|
136
|
+
listing_id: listingId,
|
|
137
|
+
surface,
|
|
138
|
+
ordinal: optional(integer(1, 1e3))
|
|
139
|
+
});
|
|
140
|
+
var event = object({ category: literal(PROPERTY_INTEREST_CATEGORY), name: choice(...PROPERTY_INTEREST_EVENT_NAMES), properties: eventProperties });
|
|
141
|
+
var parsePropertyInterestEventProperties = (value) => eventProperties.read(value, "propertyInterestEventProperties");
|
|
142
|
+
var parsePropertyInterestEvent = (value) => event.read(value, "propertyInterestEvent");
|
|
143
|
+
var PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA = eventProperties.schema;
|
|
144
|
+
var PROPERTY_INTEREST_EVENT_JSON_SCHEMA = event.schema;
|
|
145
|
+
function checkWindow(from, to, at) {
|
|
146
|
+
const duration = Date.parse(to) - Date.parse(from);
|
|
147
|
+
if (duration <= 0 || duration > PROPERTY_INTEREST_MAX_WINDOW_DAYS * dayMs) fail(at, "requires a positive window of at most 90 days");
|
|
148
|
+
}
|
|
149
|
+
function unique(values, at) {
|
|
150
|
+
if (new Set(values).size !== values.length) fail(at, "duplicate identity");
|
|
151
|
+
}
|
|
152
|
+
var reportRequest = refine(object({
|
|
153
|
+
site,
|
|
154
|
+
from: optional(instant),
|
|
155
|
+
to: optional(instant),
|
|
156
|
+
listingIds: optional(list(listingId, PROPERTY_INTEREST_MAX_LISTINGS, 1)),
|
|
157
|
+
cursor: optional(listingId)
|
|
158
|
+
}), (value, at) => {
|
|
159
|
+
if (value.from && value.to) checkWindow(value.from, value.to, at);
|
|
160
|
+
else if (value.from || value.to) fail(at, "requires both window endpoints or neither");
|
|
161
|
+
if (value.listingIds) unique(value.listingIds.map((id) => id.toLowerCase()), at + ".listingIds");
|
|
162
|
+
if (value.cursor && (!value.from || !value.to || value.listingIds)) {
|
|
163
|
+
fail(at + ".cursor", "requires the original broad report window");
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
var parsePropertyInterestReportRequest = (value) => reportRequest.read(value, "propertyInterestReportRequest");
|
|
167
|
+
var PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA = reportRequest.schema;
|
|
168
|
+
function propertyInterestRateBps(eligibleSessions, exposureSessions) {
|
|
169
|
+
const eligible = integer().read(eligibleSessions, "propertyInterestRate.eligibleSessions");
|
|
170
|
+
const exposure = integer().read(exposureSessions, "propertyInterestRate.exposureSessions");
|
|
171
|
+
if (eligible > exposure) fail("propertyInterestRate", "eligible sessions exceed the exposure cohort");
|
|
172
|
+
if (exposure === 0) return null;
|
|
173
|
+
const denominator = BigInt(exposure);
|
|
174
|
+
return Number((BigInt(eligible) * 10000n + denominator / 2n) / denominator);
|
|
175
|
+
}
|
|
176
|
+
var action = object({ eligibleSessions: integer(), unmatchedSessions: integer(), rateBps: nullable(integer(0, 1e4)) });
|
|
177
|
+
var surfaceReport = refine(object({
|
|
178
|
+
surface,
|
|
179
|
+
exposureSessions: integer(),
|
|
180
|
+
missingSessionEvents: integer(),
|
|
181
|
+
actions: object({ gallery_open: action, detail_open: action, property_selected: action })
|
|
182
|
+
}), (value, at) => {
|
|
183
|
+
for (const [name, counts] of Object.entries(value.actions)) {
|
|
184
|
+
if (counts.eligibleSessions > value.exposureSessions || counts.rateBps !== propertyInterestRateBps(counts.eligibleSessions, value.exposureSessions)) {
|
|
185
|
+
fail(at + ".actions." + name, "requires the exact exposure-normalized rate");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
var tourInquiries = union(
|
|
190
|
+
object({ state: literal("available"), count: integer(), source: literal("native_listing_accepted_tour_form") }),
|
|
191
|
+
object({ state: literal("unavailable"), count: literal(null), source: literal(null) })
|
|
192
|
+
);
|
|
193
|
+
var propertyReport = refine(object({
|
|
194
|
+
listingId,
|
|
195
|
+
displayAddress: nullable(text(240, /^[^\x00-\x1f\x7f]+$/)),
|
|
196
|
+
slug: nullable(text(200, /^[a-z0-9]+(?:-[a-z0-9]+)*$/)),
|
|
197
|
+
status: nullable(choice("active", "pending", "sold", "expired", "withdrawn")),
|
|
198
|
+
surfaces: list(surfaceReport, 2, 2),
|
|
199
|
+
acceptedTourInquiries: tourInquiries
|
|
200
|
+
}), (value, at) => {
|
|
201
|
+
unique(value.surfaces.map((row) => row.surface), at + ".surfaces");
|
|
202
|
+
});
|
|
203
|
+
var report = refine(object({
|
|
204
|
+
schemaVersion: literal(1),
|
|
205
|
+
scope: literal("site"),
|
|
206
|
+
site,
|
|
207
|
+
from: instant,
|
|
208
|
+
to: instant,
|
|
209
|
+
observedAt: instant,
|
|
210
|
+
properties: list(propertyReport, PROPERTY_INTEREST_MAX_LISTINGS),
|
|
211
|
+
hasMore: bool,
|
|
212
|
+
nextCursor: nullable(listingId)
|
|
213
|
+
}), (value, at) => {
|
|
214
|
+
checkWindow(value.from, value.to, at);
|
|
215
|
+
if (Date.parse(value.to) > Date.parse(value.observedAt)) fail(at + ".to", "window extends past the observation");
|
|
216
|
+
unique(value.properties.map((row) => row.listingId.toLowerCase()), at + ".properties");
|
|
217
|
+
if (value.hasMore !== (value.nextCursor !== null)) fail(at + ".hasMore", "must agree with the next cursor");
|
|
218
|
+
if (value.nextCursor && (value.properties.length !== PROPERTY_INTEREST_MAX_LISTINGS || value.properties[value.properties.length - 1]?.listingId.toLowerCase() !== value.nextCursor.toLowerCase())) {
|
|
219
|
+
fail(at + ".nextCursor", "requires the final listing of a full bounded result");
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
var parsePropertyInterestReport = (value) => report.read(value, "propertyInterestReport");
|
|
223
|
+
var PROPERTY_INTEREST_REPORT_JSON_SCHEMA = report.schema;
|
|
224
|
+
function parsePropertyInterestReportForRequest(value, request) {
|
|
225
|
+
const result = parsePropertyInterestReport(value);
|
|
226
|
+
const expected = parsePropertyInterestReportRequest(request);
|
|
227
|
+
const at = "propertyInterestReport";
|
|
228
|
+
if (result.site !== expected.site) fail(at + ".site", "does not match the requested site");
|
|
229
|
+
const from = Date.parse(result.from), to = Date.parse(result.to);
|
|
230
|
+
if (expected.from && expected.to) {
|
|
231
|
+
if (from !== Date.parse(expected.from) || to !== Date.parse(expected.to)) {
|
|
232
|
+
fail(at + ".from", "does not match the requested window");
|
|
233
|
+
}
|
|
234
|
+
} else if (to - from !== PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS * dayMs) {
|
|
235
|
+
fail(at + ".from", "does not match the default window duration");
|
|
236
|
+
}
|
|
237
|
+
if (expected.listingIds) {
|
|
238
|
+
const requestedIds = new Set(expected.listingIds.map((id) => id.toLowerCase()));
|
|
239
|
+
if (result.hasMore || result.properties.length !== requestedIds.size || result.properties.some((row) => !requestedIds.has(row.listingId.toLowerCase()))) {
|
|
240
|
+
fail(at + ".properties", "requires exactly the requested listings without pagination");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
exports.PROPERTY_INTEREST_CATEGORY = PROPERTY_INTEREST_CATEGORY;
|
|
247
|
+
exports.PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS = PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS;
|
|
248
|
+
exports.PROPERTY_INTEREST_EVENT_JSON_SCHEMA = PROPERTY_INTEREST_EVENT_JSON_SCHEMA;
|
|
249
|
+
exports.PROPERTY_INTEREST_EVENT_NAMES = PROPERTY_INTEREST_EVENT_NAMES;
|
|
250
|
+
exports.PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA = PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA;
|
|
251
|
+
exports.PROPERTY_INTEREST_MAX_LISTINGS = PROPERTY_INTEREST_MAX_LISTINGS;
|
|
252
|
+
exports.PROPERTY_INTEREST_MAX_WINDOW_DAYS = PROPERTY_INTEREST_MAX_WINDOW_DAYS;
|
|
253
|
+
exports.PROPERTY_INTEREST_REPORT_JSON_SCHEMA = PROPERTY_INTEREST_REPORT_JSON_SCHEMA;
|
|
254
|
+
exports.PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA = PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA;
|
|
255
|
+
exports.PropertyInterestValidationError = PropertyInterestValidationError;
|
|
256
|
+
exports.parsePropertyInterestEvent = parsePropertyInterestEvent;
|
|
257
|
+
exports.parsePropertyInterestEventProperties = parsePropertyInterestEventProperties;
|
|
258
|
+
exports.parsePropertyInterestReport = parsePropertyInterestReport;
|
|
259
|
+
exports.parsePropertyInterestReportForRequest = parsePropertyInterestReportForRequest;
|
|
260
|
+
exports.parsePropertyInterestReportRequest = parsePropertyInterestReportRequest;
|
|
261
|
+
exports.propertyInterestRateBps = propertyInterestRateBps;
|