@sonordev/contracts 2.23.0 → 2.26.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 +17 -0
- package/README.md +121 -4
- package/dist/property-interest.d.ts +100 -0
- package/dist/property-interest.js +261 -0
- package/dist/property-interest.mjs +244 -0
- package/dist/resonance.d.ts +1151 -118
- package/dist/resonance.js +584 -6
- package/dist/resonance.mjs +526 -7
- package/dist/sales-call-prep.d.ts +666 -0
- package/dist/sales-call-prep.js +334 -0
- package/dist/sales-call-prep.mjs +288 -0
- package/dist/signal-experiments.d.ts +0 -1
- package/dist/signal-experiments.js +4 -1
- package/dist/signal-experiments.mjs +4 -1
- package/dist/wire-uuid.d.ts +5 -0
- package/package.json +11 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// src/contracts/public-url-host.ts
|
|
2
|
+
function isPrivateIpv4(a, b) {
|
|
3
|
+
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;
|
|
4
|
+
}
|
|
5
|
+
function ipv6Words(host) {
|
|
6
|
+
if (!host.includes(":") || !/^[a-f\d:.]+$/.test(host)) return null;
|
|
7
|
+
let canonical;
|
|
8
|
+
try {
|
|
9
|
+
canonical = new URL(`http://[${host}]/`).hostname.slice(1, -1);
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const sides = canonical.split("::");
|
|
14
|
+
const left = sides[0] ? sides[0].split(":") : [];
|
|
15
|
+
const right = sides.length > 1 && sides[1] ? sides[1].split(":") : [];
|
|
16
|
+
return [...left, ...Array(sides.length > 1 ? 8 - left.length - right.length : 0).fill("0"), ...right].map((word) => parseInt(word, 16));
|
|
17
|
+
}
|
|
18
|
+
function isBlockedPublicUrlHost(rawHost) {
|
|
19
|
+
const host = rawHost.toLowerCase().replace(/^\[|\]$/g, "");
|
|
20
|
+
const blockedName = host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
21
|
+
if (host.includes(":") && host.includes("%")) return true;
|
|
22
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
23
|
+
const blockedIp = !!ipv4 && isPrivateIpv4(Number(ipv4[1]), Number(ipv4[2]));
|
|
24
|
+
const words = ipv6Words(host);
|
|
25
|
+
const blockedIpv6 = !!words && // Unspecified/loopback, unique-local, link-local, deprecated site-local
|
|
26
|
+
// and multicast destinations aren't public logo/webhook endpoints.
|
|
27
|
+
(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.
|
|
28
|
+
words.slice(0, 5).every((word) => word === 0) && [0, 65535].includes(words[5]) && isPrivateIpv4(words[6] >> 8, words[6] & 255));
|
|
29
|
+
return blockedName || blockedIp || blockedIpv6;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/contracts/sites-normalize.ts
|
|
33
|
+
function normalizeSiteHost(site2) {
|
|
34
|
+
if (!site2 || typeof site2 !== "string") return null;
|
|
35
|
+
let s = site2.trim().toLowerCase();
|
|
36
|
+
if (!s) return null;
|
|
37
|
+
s = s.replace(/^https?:\/\//, "");
|
|
38
|
+
const slash = s.indexOf("/");
|
|
39
|
+
if (slash >= 0) s = s.slice(0, slash);
|
|
40
|
+
const colon = s.indexOf(":");
|
|
41
|
+
if (colon >= 0) s = s.slice(0, colon);
|
|
42
|
+
s = s.replace(/\.+$/, "");
|
|
43
|
+
return s || null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/contracts/sites.ts
|
|
47
|
+
function isNormalizedSiteHost(value) {
|
|
48
|
+
return typeof value === "string" && value.length > 0 && normalizeSiteHost(value) === value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/contracts/wire-schema.ts
|
|
52
|
+
function createWireSchema(fail2, isValidationError) {
|
|
53
|
+
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
54
|
+
const field = (schema, read) => ({ schema, read });
|
|
55
|
+
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"));
|
|
56
|
+
const choice2 = (...values) => field({ type: "string", enum: values }, (v, p) => typeof v === "string" && values.includes(v) ? v : fail2(p, "unsupported value"));
|
|
57
|
+
const literal2 = (value) => field({ const: value }, (v, p) => v === value ? value : fail2(p, "unexpected value"));
|
|
58
|
+
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"));
|
|
59
|
+
const bool2 = field({ type: "boolean" }, (v, p) => typeof v === "boolean" ? v : fail2(p, "must be boolean"));
|
|
60
|
+
const optional2 = (f) => ({ ...f, optional: true });
|
|
61
|
+
const nullable2 = (f) => field({ anyOf: [f.schema, { type: "null" }] }, (v, p) => v === null ? null : f.read(v, p));
|
|
62
|
+
const list2 = (f, max = 100, min = 0) => field({ type: "array", items: f.schema, minItems: min, maxItems: max }, (v, p) => {
|
|
63
|
+
if (!Array.isArray(v) || v.length < min || v.length > max) fail2(p, "invalid array");
|
|
64
|
+
return v.map((x, i) => f.read(x, `${p}[${i}]`));
|
|
65
|
+
});
|
|
66
|
+
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) => {
|
|
67
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) fail2(p, "must be a plain object");
|
|
68
|
+
const source = v, result = {};
|
|
69
|
+
for (const key of Reflect.ownKeys(source)) if (typeof key !== "string" || !own(fields, key)) fail2(p, "unknown field");
|
|
70
|
+
for (const [key, f] of Object.entries(fields)) {
|
|
71
|
+
if (!own(source, key)) {
|
|
72
|
+
if ("optional" in f) continue;
|
|
73
|
+
fail2(`${p}.${key}`, "required");
|
|
74
|
+
}
|
|
75
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
76
|
+
if (!own(descriptor, "value")) fail2(`${p}.${key}`, "accessors are not wire data");
|
|
77
|
+
result[key] = f.read(descriptor.value, `${p}.${key}`);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
});
|
|
81
|
+
const union2 = (...fields) => field({ oneOf: fields.map((f) => f.schema) }, (v, p) => {
|
|
82
|
+
const found = [];
|
|
83
|
+
for (const f of fields) {
|
|
84
|
+
try {
|
|
85
|
+
found.push(f.read(v, p));
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (!isValidationError(e)) throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return found.length === 1 ? found[0] : fail2(p, "must match exactly one supported shape");
|
|
91
|
+
});
|
|
92
|
+
const refine2 = (f, check) => field(f.schema, (v, p) => {
|
|
93
|
+
const result = f.read(v, p);
|
|
94
|
+
check(result, p);
|
|
95
|
+
return result;
|
|
96
|
+
});
|
|
97
|
+
return { field, text: text2, choice: choice2, literal: literal2, integer: integer2, bool: bool2, optional: optional2, nullable: nullable2, list: list2, object: object2, union: union2, refine: refine2 };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/contracts/wire-uuid.ts
|
|
101
|
+
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}$/;
|
|
102
|
+
|
|
103
|
+
// src/contracts/property-interest.ts
|
|
104
|
+
var PROPERTY_INTEREST_CATEGORY = "real_estate_interest";
|
|
105
|
+
var PROPERTY_INTEREST_EVENT_NAMES = ["property_exposed", "gallery_open", "detail_open", "property_selected"];
|
|
106
|
+
var PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS = 28;
|
|
107
|
+
var PROPERTY_INTEREST_MAX_WINDOW_DAYS = 90;
|
|
108
|
+
var PROPERTY_INTEREST_MAX_LISTINGS = 50;
|
|
109
|
+
var PropertyInterestValidationError = class extends Error {
|
|
110
|
+
constructor(path, reason) {
|
|
111
|
+
super(`${path}: ${reason}`);
|
|
112
|
+
this.path = path;
|
|
113
|
+
this.name = "PropertyInterestValidationError";
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var fail = (path, reason) => {
|
|
117
|
+
throw new PropertyInterestValidationError(path, reason);
|
|
118
|
+
};
|
|
119
|
+
var { bool, choice, integer, list, literal, nullable, object, optional, refine, text, union } = createWireSchema(fail, (error) => error instanceof PropertyInterestValidationError);
|
|
120
|
+
var listingId = text(36, UUID_V1_TO_V8_PATTERN);
|
|
121
|
+
var surface = choice("collection", "detail");
|
|
122
|
+
var site = refine(text(253), (value, at) => {
|
|
123
|
+
if (!isNormalizedSiteHost(value) || isBlockedPublicUrlHost(value)) fail(at, "requires a normalized public site host");
|
|
124
|
+
});
|
|
125
|
+
var instant = refine(text(24, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/), (value, at) => {
|
|
126
|
+
const epoch = Date.parse(value);
|
|
127
|
+
if (!Number.isFinite(epoch) || new Date(epoch).toISOString().replace(".000Z", "Z") !== value.replace(".000Z", "Z")) {
|
|
128
|
+
fail(at, "requires a valid UTC instant");
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
var dayMs = 864e5;
|
|
132
|
+
var eventProperties = object({
|
|
133
|
+
schema_version: literal(1),
|
|
134
|
+
listing_id: listingId,
|
|
135
|
+
surface,
|
|
136
|
+
ordinal: optional(integer(1, 1e3))
|
|
137
|
+
});
|
|
138
|
+
var event = object({ category: literal(PROPERTY_INTEREST_CATEGORY), name: choice(...PROPERTY_INTEREST_EVENT_NAMES), properties: eventProperties });
|
|
139
|
+
var parsePropertyInterestEventProperties = (value) => eventProperties.read(value, "propertyInterestEventProperties");
|
|
140
|
+
var parsePropertyInterestEvent = (value) => event.read(value, "propertyInterestEvent");
|
|
141
|
+
var PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA = eventProperties.schema;
|
|
142
|
+
var PROPERTY_INTEREST_EVENT_JSON_SCHEMA = event.schema;
|
|
143
|
+
function checkWindow(from, to, at) {
|
|
144
|
+
const duration = Date.parse(to) - Date.parse(from);
|
|
145
|
+
if (duration <= 0 || duration > PROPERTY_INTEREST_MAX_WINDOW_DAYS * dayMs) fail(at, "requires a positive window of at most 90 days");
|
|
146
|
+
}
|
|
147
|
+
function unique(values, at) {
|
|
148
|
+
if (new Set(values).size !== values.length) fail(at, "duplicate identity");
|
|
149
|
+
}
|
|
150
|
+
var reportRequest = refine(object({
|
|
151
|
+
site,
|
|
152
|
+
from: optional(instant),
|
|
153
|
+
to: optional(instant),
|
|
154
|
+
listingIds: optional(list(listingId, PROPERTY_INTEREST_MAX_LISTINGS, 1)),
|
|
155
|
+
cursor: optional(listingId)
|
|
156
|
+
}), (value, at) => {
|
|
157
|
+
if (value.from && value.to) checkWindow(value.from, value.to, at);
|
|
158
|
+
else if (value.from || value.to) fail(at, "requires both window endpoints or neither");
|
|
159
|
+
if (value.listingIds) unique(value.listingIds.map((id) => id.toLowerCase()), at + ".listingIds");
|
|
160
|
+
if (value.cursor && (!value.from || !value.to || value.listingIds)) {
|
|
161
|
+
fail(at + ".cursor", "requires the original broad report window");
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
var parsePropertyInterestReportRequest = (value) => reportRequest.read(value, "propertyInterestReportRequest");
|
|
165
|
+
var PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA = reportRequest.schema;
|
|
166
|
+
function propertyInterestRateBps(eligibleSessions, exposureSessions) {
|
|
167
|
+
const eligible = integer().read(eligibleSessions, "propertyInterestRate.eligibleSessions");
|
|
168
|
+
const exposure = integer().read(exposureSessions, "propertyInterestRate.exposureSessions");
|
|
169
|
+
if (eligible > exposure) fail("propertyInterestRate", "eligible sessions exceed the exposure cohort");
|
|
170
|
+
if (exposure === 0) return null;
|
|
171
|
+
const denominator = BigInt(exposure);
|
|
172
|
+
return Number((BigInt(eligible) * 10000n + denominator / 2n) / denominator);
|
|
173
|
+
}
|
|
174
|
+
var action = object({ eligibleSessions: integer(), unmatchedSessions: integer(), rateBps: nullable(integer(0, 1e4)) });
|
|
175
|
+
var surfaceReport = refine(object({
|
|
176
|
+
surface,
|
|
177
|
+
exposureSessions: integer(),
|
|
178
|
+
missingSessionEvents: integer(),
|
|
179
|
+
actions: object({ gallery_open: action, detail_open: action, property_selected: action })
|
|
180
|
+
}), (value, at) => {
|
|
181
|
+
for (const [name, counts] of Object.entries(value.actions)) {
|
|
182
|
+
if (counts.eligibleSessions > value.exposureSessions || counts.rateBps !== propertyInterestRateBps(counts.eligibleSessions, value.exposureSessions)) {
|
|
183
|
+
fail(at + ".actions." + name, "requires the exact exposure-normalized rate");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
var tourInquiries = union(
|
|
188
|
+
object({ state: literal("available"), count: integer(), source: literal("native_listing_accepted_tour_form") }),
|
|
189
|
+
object({ state: literal("unavailable"), count: literal(null), source: literal(null) })
|
|
190
|
+
);
|
|
191
|
+
var propertyReport = refine(object({
|
|
192
|
+
listingId,
|
|
193
|
+
displayAddress: nullable(text(240, /^[^\x00-\x1f\x7f]+$/)),
|
|
194
|
+
slug: nullable(text(200, /^[a-z0-9]+(?:-[a-z0-9]+)*$/)),
|
|
195
|
+
status: nullable(choice("active", "pending", "sold", "expired", "withdrawn")),
|
|
196
|
+
surfaces: list(surfaceReport, 2, 2),
|
|
197
|
+
acceptedTourInquiries: tourInquiries
|
|
198
|
+
}), (value, at) => {
|
|
199
|
+
unique(value.surfaces.map((row) => row.surface), at + ".surfaces");
|
|
200
|
+
});
|
|
201
|
+
var report = refine(object({
|
|
202
|
+
schemaVersion: literal(1),
|
|
203
|
+
scope: literal("site"),
|
|
204
|
+
site,
|
|
205
|
+
from: instant,
|
|
206
|
+
to: instant,
|
|
207
|
+
observedAt: instant,
|
|
208
|
+
properties: list(propertyReport, PROPERTY_INTEREST_MAX_LISTINGS),
|
|
209
|
+
hasMore: bool,
|
|
210
|
+
nextCursor: nullable(listingId)
|
|
211
|
+
}), (value, at) => {
|
|
212
|
+
checkWindow(value.from, value.to, at);
|
|
213
|
+
if (Date.parse(value.to) > Date.parse(value.observedAt)) fail(at + ".to", "window extends past the observation");
|
|
214
|
+
unique(value.properties.map((row) => row.listingId.toLowerCase()), at + ".properties");
|
|
215
|
+
if (value.hasMore !== (value.nextCursor !== null)) fail(at + ".hasMore", "must agree with the next cursor");
|
|
216
|
+
if (value.nextCursor && (value.properties.length !== PROPERTY_INTEREST_MAX_LISTINGS || value.properties[value.properties.length - 1]?.listingId.toLowerCase() !== value.nextCursor.toLowerCase())) {
|
|
217
|
+
fail(at + ".nextCursor", "requires the final listing of a full bounded result");
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
var parsePropertyInterestReport = (value) => report.read(value, "propertyInterestReport");
|
|
221
|
+
var PROPERTY_INTEREST_REPORT_JSON_SCHEMA = report.schema;
|
|
222
|
+
function parsePropertyInterestReportForRequest(value, request) {
|
|
223
|
+
const result = parsePropertyInterestReport(value);
|
|
224
|
+
const expected = parsePropertyInterestReportRequest(request);
|
|
225
|
+
const at = "propertyInterestReport";
|
|
226
|
+
if (result.site !== expected.site) fail(at + ".site", "does not match the requested site");
|
|
227
|
+
const from = Date.parse(result.from), to = Date.parse(result.to);
|
|
228
|
+
if (expected.from && expected.to) {
|
|
229
|
+
if (from !== Date.parse(expected.from) || to !== Date.parse(expected.to)) {
|
|
230
|
+
fail(at + ".from", "does not match the requested window");
|
|
231
|
+
}
|
|
232
|
+
} else if (to - from !== PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS * dayMs) {
|
|
233
|
+
fail(at + ".from", "does not match the default window duration");
|
|
234
|
+
}
|
|
235
|
+
if (expected.listingIds) {
|
|
236
|
+
const requestedIds = new Set(expected.listingIds.map((id) => id.toLowerCase()));
|
|
237
|
+
if (result.hasMore || result.properties.length !== requestedIds.size || result.properties.some((row) => !requestedIds.has(row.listingId.toLowerCase()))) {
|
|
238
|
+
fail(at + ".properties", "requires exactly the requested listings without pagination");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export { PROPERTY_INTEREST_CATEGORY, PROPERTY_INTEREST_DEFAULT_WINDOW_DAYS, PROPERTY_INTEREST_EVENT_JSON_SCHEMA, PROPERTY_INTEREST_EVENT_NAMES, PROPERTY_INTEREST_EVENT_PROPERTIES_JSON_SCHEMA, PROPERTY_INTEREST_MAX_LISTINGS, PROPERTY_INTEREST_MAX_WINDOW_DAYS, PROPERTY_INTEREST_REPORT_JSON_SCHEMA, PROPERTY_INTEREST_REPORT_REQUEST_JSON_SCHEMA, PropertyInterestValidationError, parsePropertyInterestEvent, parsePropertyInterestEventProperties, parsePropertyInterestReport, parsePropertyInterestReportForRequest, parsePropertyInterestReportRequest, propertyInterestRateBps };
|