@buyingbuddy/react 0.3.3 → 1.0.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.
@@ -0,0 +1,58 @@
1
+ import type { BuyingBuddyErrorCode } from "./types.js";
2
+ /**
3
+ * A server render that did not produce HTML.
4
+ *
5
+ * Every failure throws one of these, carrying a machine-readable `code`. That is
6
+ * a deliberate difference from the PHP SDK this path replaces, whose single
7
+ * transport collapsed a domain authorization failure, a cancelled account, a
8
+ * timeout, a 429 and malformed JSON all into the empty string - so a customer saw
9
+ * a blank widget and no reason, and the explanation the server had actually sent
10
+ * was discarded on the way past.
11
+ *
12
+ * `serverHtml` is that explanation. When the Buying Buddy server refuses a
13
+ * render it usually answers with human-readable HTML saying why - "this domain
14
+ * isn't registered with your Buying Buddy account", with the steps to fix it.
15
+ * Catch the error and show it to yourself in development; do not show it to
16
+ * visitors, who cannot act on it.
17
+ */
18
+ export declare class BuyingBuddyError extends Error {
19
+ /** What went wrong, as a value you can branch on. */
20
+ readonly code: BuyingBuddyErrorCode;
21
+ /** HTTP status, when the request got far enough to have one. */
22
+ readonly status?: number;
23
+ /** Seconds to wait, from the server's `Retry-After`, on a `rate_limited`. */
24
+ readonly retryAfter?: number;
25
+ /** The server's own explanation of the refusal, as HTML. */
26
+ readonly serverHtml?: string;
27
+ /** The server's `msg` field, where it sent one. */
28
+ readonly serverMessage?: string;
29
+ /**
30
+ * The underlying failure, where there was one - the `TimeoutError`, the fetch
31
+ * rejection, the `SyntaxError` from a non-JSON body.
32
+ *
33
+ * Declared here and assigned in the constructor rather than handed to
34
+ * `super(message, { cause })`, which this class did first and which does not
35
+ * compile: the two-argument `Error` constructor is an ES2022 lib declaration
36
+ * and this package's tsconfig is on ES2020. Widening `lib` for one field would
37
+ * let every other module in the package reach ES2022 APIs that the ES2020
38
+ * output target cannot guarantee a runtime for. The property name is the
39
+ * platform's, so `err.cause` reads the same either way.
40
+ */
41
+ readonly cause?: unknown;
42
+ constructor(code: BuyingBuddyErrorCode, message: string, details?: {
43
+ status?: number;
44
+ retryAfter?: number;
45
+ serverHtml?: string;
46
+ serverMessage?: string;
47
+ cause?: unknown;
48
+ });
49
+ }
50
+ /**
51
+ * Is this error one of ours?
52
+ *
53
+ * Prefer this over `instanceof` at a package boundary: two copies of the package
54
+ * in one dependency tree means two distinct classes, and `instanceof` is false
55
+ * across them while the error is plainly still ours.
56
+ */
57
+ export declare function isBuyingBuddyError(e: unknown): e is BuyingBuddyError;
58
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/server/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAEpC,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,6EAA6E;IAC7E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,mDAAmD;IACnD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAGvB,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,KAAK,CAAC,EAAE,OAAO,CAAC;KACZ;CAWT;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAOpE"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A server render that did not produce HTML.
3
+ *
4
+ * Every failure throws one of these, carrying a machine-readable `code`. That is
5
+ * a deliberate difference from the PHP SDK this path replaces, whose single
6
+ * transport collapsed a domain authorization failure, a cancelled account, a
7
+ * timeout, a 429 and malformed JSON all into the empty string - so a customer saw
8
+ * a blank widget and no reason, and the explanation the server had actually sent
9
+ * was discarded on the way past.
10
+ *
11
+ * `serverHtml` is that explanation. When the Buying Buddy server refuses a
12
+ * render it usually answers with human-readable HTML saying why - "this domain
13
+ * isn't registered with your Buying Buddy account", with the steps to fix it.
14
+ * Catch the error and show it to yourself in development; do not show it to
15
+ * visitors, who cannot act on it.
16
+ */
17
+ export class BuyingBuddyError extends Error {
18
+ constructor(code, message, details = {}) {
19
+ super(message);
20
+ this.name = "BuyingBuddyError";
21
+ this.code = code;
22
+ this.cause = details.cause;
23
+ this.status = details.status;
24
+ this.retryAfter = details.retryAfter;
25
+ this.serverHtml = details.serverHtml;
26
+ this.serverMessage = details.serverMessage;
27
+ }
28
+ }
29
+ /**
30
+ * Is this error one of ours?
31
+ *
32
+ * Prefer this over `instanceof` at a package boundary: two copies of the package
33
+ * in one dependency tree means two distinct classes, and `instanceof` is false
34
+ * across them while the error is plainly still ours.
35
+ */
36
+ export function isBuyingBuddyError(e) {
37
+ return (typeof e === "object" &&
38
+ e !== null &&
39
+ e.name === "BuyingBuddyError" &&
40
+ typeof e.code === "string");
41
+ }
42
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/server/errors.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IA8BzC,YACE,IAA0B,EAC1B,OAAe,EACf,UAMI,EAAE;QAEN,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC7C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAU;IAC3C,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACT,CAAwB,CAAC,IAAI,KAAK,kBAAkB;QACrD,OAAQ,CAAwB,CAAC,IAAI,KAAK,QAAQ,CACnD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `@buyingbuddy/react/server` - server-side rendering for Buying Buddy widgets.
3
+ *
4
+ * NO "use client" DIRECTIVE HERE, deliberately, and `scripts/assert-server-only.mjs`
5
+ * fails the publish if one appears. The package root carries it on all three of its
6
+ * emitted modules because those are client components; this entry is the opposite
7
+ * kind of module, and an RSC framework that saw the directive here would push it
8
+ * into the client bundle - where the `"browser"` condition's stub would then throw
9
+ * in the visitor's browser, for a reason nobody would connect to a stray directive.
10
+ *
11
+ * Use this entry for the SEO payload - listing content in the initial HTML - and
12
+ * the package root for widgets that render in the browser. Both can be installed
13
+ * from the same dependency; only your import path differs.
14
+ *
15
+ * `renderWidget` needs no React and works from any server - Express, a Remix
16
+ * loader, `getServerSideProps`. `BuyingBuddyServerWidget` is an async Server
17
+ * Component and works only where those are supported: on anything else, render
18
+ * the mount yourself from `renderWidget` plus `widgetMountProps`.
19
+ */
20
+ export { renderWidget, createVisitorId, SSR_WIDGET_TYPES } from "./renderWidget.js";
21
+ export { BuyingBuddyServerWidget, widgetMountProps, } from "./BuyingBuddyServerWidget.js";
22
+ export { BuyingBuddyError, isBuyingBuddyError } from "./errors.js";
23
+ export type { BuyingBuddyServerWidgetProps, WidgetMountProps, } from "./BuyingBuddyServerWidget.js";
24
+ export type { SsrWidgetType, VisitorContext, RenderWidgetOptions, RenderedWidget, WidgetMetadata, BuyingBuddyErrorCode, } from "./types.js";
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EACL,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,YAAY,EACV,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `@buyingbuddy/react/server` - server-side rendering for Buying Buddy widgets.
3
+ *
4
+ * NO "use client" DIRECTIVE HERE, deliberately, and `scripts/assert-server-only.mjs`
5
+ * fails the publish if one appears. The package root carries it on all three of its
6
+ * emitted modules because those are client components; this entry is the opposite
7
+ * kind of module, and an RSC framework that saw the directive here would push it
8
+ * into the client bundle - where the `"browser"` condition's stub would then throw
9
+ * in the visitor's browser, for a reason nobody would connect to a stray directive.
10
+ *
11
+ * Use this entry for the SEO payload - listing content in the initial HTML - and
12
+ * the package root for widgets that render in the browser. Both can be installed
13
+ * from the same dependency; only your import path differs.
14
+ *
15
+ * `renderWidget` needs no React and works from any server - Express, a Remix
16
+ * loader, `getServerSideProps`. `BuyingBuddyServerWidget` is an async Server
17
+ * Component and works only where those are supported: on anything else, render
18
+ * the mount yourself from `renderWidget` plus `widgetMountProps`.
19
+ */
20
+ export { renderWidget, createVisitorId, SSR_WIDGET_TYPES } from "./renderWidget.js";
21
+ export { BuyingBuddyServerWidget, widgetMountProps, } from "./BuyingBuddyServerWidget.js";
22
+ export { BuyingBuddyError, isBuyingBuddyError } from "./errors.js";
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EACL,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { RenderWidgetOptions, RenderedWidget } from "./types.js";
2
+ /**
3
+ * Widget types this entry point will render, as a runtime value.
4
+ *
5
+ * Kept in step with the `SsrWidgetType` union by a test, because a union is
6
+ * erased at build time and cannot validate anything on its own - a JavaScript
7
+ * consumer, or a TypeScript one who widened the type, reaches this array and
8
+ * nothing else.
9
+ */
10
+ export declare const SSR_WIDGET_TYPES: readonly ["Brokers", "Calculator", "Communities", "FeaturedGallery", "FeaturedList", "LcForm", "ListingDetails", "ListingShowcase", "LoginPanel", "MarketReport", "MarketStats", "OfficeRoster", "QuickSearch", "SearchDetails", "SearchForm"];
11
+ /**
12
+ * Mint a Buying Buddy visitor id.
13
+ *
14
+ * Store the result in a cookie named `mbb-mbbid` on your own response and pass
15
+ * it back as `visitor.mbbid` on later renders. This package cannot do either -
16
+ * it has no response object - so the cookie is yours to own.
17
+ *
18
+ * The format matters: the Buying Buddy API accepts this value on its own as the
19
+ * visitor's identity, so it is a v4 UUID from your platform's CSPRNG and must
20
+ * not be swapped for anything guessable, such as a hash of the current time.
21
+ */
22
+ export declare function createVisitorId(): string;
23
+ /**
24
+ * Server-render one Buying Buddy widget and return its HTML.
25
+ *
26
+ * Call this where your framework runs server-side - a Next.js Server Component or
27
+ * `getServerSideProps`, an Express handler, a Remix loader - and put the result
28
+ * in a `<bb-widget>` mount, using `widgetMountProps` or your own templating.
29
+ * `<BuyingBuddyServerWidget>` does the mounting for you, but it is an async
30
+ * Server Component and so needs a framework that supports those; this function
31
+ * is the one that works everywhere.
32
+ *
33
+ * **The page must also declare `seo="true"`** on `<BuyingBuddyProvider>`. That
34
+ * flag is what tells the widget runtime the markup is already present, so it
35
+ * adopts yours instead of fetching its own. Without it the client fetches anyway
36
+ * and replaces what you rendered; it is a page-level flag, so every Buying Buddy
37
+ * widget on a page that sets it must come through this path.
38
+ *
39
+ * @throws {BuyingBuddyError} on any outcome that is not rendered HTML.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * const { html, meta, filterString } = await renderWidget({
44
+ * type: "OfficeRoster",
45
+ * activationKey: process.env.BUYING_BUDDY_KEY!,
46
+ * domain: "www.example.com",
47
+ * visitor: { ip: (await headers()).get("x-forwarded-for")?.split(",")[0] },
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function renderWidget(options: RenderWidgetOptions): Promise<RenderedWidget>;
52
+ //# sourceMappingURL=renderWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderWidget.d.ts","sourceRoot":"","sources":["../../src/server/renderWidget.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,gPAgBgB,CAAC;AA0C9C;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AA+FD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAoOzB"}
@@ -0,0 +1,344 @@
1
+ import { PKG_VERSION } from "../version.js";
2
+ import { BuyingBuddyError } from "./errors.js";
3
+ /**
4
+ * Widget types this entry point will render, as a runtime value.
5
+ *
6
+ * Kept in step with the `SsrWidgetType` union by a test, because a union is
7
+ * erased at build time and cannot validate anything on its own - a JavaScript
8
+ * consumer, or a TypeScript one who widened the type, reaches this array and
9
+ * nothing else.
10
+ */
11
+ export const SSR_WIDGET_TYPES = [
12
+ "Brokers",
13
+ "Calculator",
14
+ "Communities",
15
+ "FeaturedGallery",
16
+ "FeaturedList",
17
+ "LcForm",
18
+ "ListingDetails",
19
+ "ListingShowcase",
20
+ "LoginPanel",
21
+ "MarketReport",
22
+ "MarketStats",
23
+ "OfficeRoster",
24
+ "QuickSearch",
25
+ "SearchDetails",
26
+ "SearchForm",
27
+ ];
28
+ const DEFAULT_BASE_URL = "https://www.mbb2.com";
29
+ const DEFAULT_TIMEOUT_MS = 3000;
30
+ /**
31
+ * The widget sub-page forms this will put in a request path, as an ALLOW-LIST.
32
+ *
33
+ * A sub-page is interpolated into the PATH rather than sent as a value, because
34
+ * it is not always one segment - `OfficeRoster` uses `roster/<office>` and
35
+ * `agent/name/<agent>`, and nesting them under `widget-page/` is what keeps the
36
+ * trailing pairs parsing as pairs.
37
+ *
38
+ * A CHARACTER CLASS IS NOT ENOUGH HERE, which is what this was first written as.
39
+ * The endpoint reads its path as ZF1 key/value pairs, so any `page` containing an
40
+ * odd number of extra `/` segments injects a NEW PAIR into the request. Review
41
+ * verified that `page = "jo/widget-type/searchresults"` produces
42
+ *
43
+ * .../widget-type/officeroster/widget-page/jo/widget-type/searchresults/...
44
+ *
45
+ * which smuggles a second `widget-type` past the SSR allow-list this module
46
+ * enforces. That matters because the natural implementation reads this slug
47
+ * straight off the incoming URL, so it is visitor-controlled.
48
+ *
49
+ * Matching whole shapes instead closes it: the segment COUNT is fixed by the
50
+ * pattern, so there is no room for a pair. A new sub-page form needs a line here,
51
+ * which is the intended cost.
52
+ */
53
+ const SAFE_PAGE_FORMS = [
54
+ /^index$/,
55
+ // The roster index, and one office. The WordPress plugin appends a trailing
56
+ // slash when the office slug ends in "search", so it is permitted.
57
+ /^roster\/?$/,
58
+ /^roster\/[A-Za-z0-9_-]+\/?$/,
59
+ // One agent, by name.
60
+ /^agent\/name\/[A-Za-z0-9_-]+$/,
61
+ ];
62
+ function isSafePage(page) {
63
+ return SAFE_PAGE_FORMS.some((form) => form.test(page));
64
+ }
65
+ /**
66
+ * Mint a Buying Buddy visitor id.
67
+ *
68
+ * Store the result in a cookie named `mbb-mbbid` on your own response and pass
69
+ * it back as `visitor.mbbid` on later renders. This package cannot do either -
70
+ * it has no response object - so the cookie is yours to own.
71
+ *
72
+ * The format matters: the Buying Buddy API accepts this value on its own as the
73
+ * visitor's identity, so it is a v4 UUID from your platform's CSPRNG and must
74
+ * not be swapped for anything guessable, such as a hash of the current time.
75
+ */
76
+ export function createVisitorId() {
77
+ return crypto.randomUUID();
78
+ }
79
+ /**
80
+ * Normalise a widget type to the wire form: lower case, no `MBBv3_` prefix.
81
+ *
82
+ * Both spellings are accepted because both are in circulation: the client
83
+ * component and this entry's own type union use the bare PascalCase name, while
84
+ * the PHP SDK and every WordPress shortcode use `MBBv3_OfficeRoster`. The widget
85
+ * registry accepts either, so rejecting one here would be this package inventing
86
+ * a restriction the server does not have - and would make someone porting a PHP
87
+ * integration debug a type name that works everywhere else.
88
+ *
89
+ * Normalising before validating is also what keeps the two consistent: an
90
+ * earlier version validated the raw string first, so the prefixed form was
91
+ * rejected and this stripping was unreachable for it. A test caught that.
92
+ */
93
+ function wireType(type) {
94
+ return type.replace(/^MBBv3_/i, "").toLowerCase();
95
+ }
96
+ /** The allow-list, in the same normalised form, so the comparison is total. */
97
+ const SSR_WIRE_TYPES = new Set(SSR_WIDGET_TYPES.map((t) => t.toLowerCase()));
98
+ function asString(v) {
99
+ return typeof v === "string" && v !== "" ? v : undefined;
100
+ }
101
+ /**
102
+ * Pull the metadata block out of a render response.
103
+ *
104
+ * The server sends six of these fields twice - flat on `data` and again inside
105
+ * `data.metadata` - for the benefit of older WordPress plugin versions. They
106
+ * agree, so this reads the flat copies and takes `canonical` from whichever
107
+ * spelling is present: `metadata.canonical` is the one current consumers read,
108
+ * `canonical_link` is kept for the older ones.
109
+ */
110
+ function readMetadata(data) {
111
+ const nested = (data.metadata ?? {});
112
+ return {
113
+ title: asString(data.title),
114
+ h1: asString(data.h1),
115
+ description: asString(data.meta_description),
116
+ keywords: asString(data.meta_keywords),
117
+ ogTags: asString(data.og_tags),
118
+ canonical: asString(nested.canonical) ?? asString(data.canonical_link),
119
+ propertyAddress: asString(data.property_address),
120
+ listingStatus: asString(data.listing_status),
121
+ };
122
+ }
123
+ /**
124
+ * Classify a refusal the server answered 200 to.
125
+ *
126
+ * EVERY outcome from this API is HTTP 200 - a wrong activation key, an
127
+ * unauthorized domain, a cancelled account - with the real answer in the body,
128
+ * so the status line tells you nothing and the body has to be read. The two
129
+ * shapes differ as well: a bare `{success:"false", msg:"..."}` for a request the
130
+ * server rejected before it resolved the account, and the full envelope with an
131
+ * explanatory `data.html` once it did.
132
+ */
133
+ function classifyRefusal(msg, html) {
134
+ const haystack = `${msg ?? ""} ${html ?? ""}`.toLowerCase();
135
+ if (haystack.includes("invalid account")) {
136
+ return {
137
+ code: "invalid_account",
138
+ message: "Buying Buddy did not recognise this activation key. Check the `activationKey` " +
139
+ "against the one in your account.",
140
+ };
141
+ }
142
+ if (haystack.includes("domain not authorized") || haystack.includes("isn't registered")) {
143
+ return {
144
+ code: "domain_not_authorized",
145
+ message: "This domain is not authorized on the Buying Buddy account. Add it in your " +
146
+ "account settings, and check that `domain` is the site's public hostname.",
147
+ };
148
+ }
149
+ return {
150
+ code: "render_refused",
151
+ message: msg
152
+ ? `Buying Buddy declined the render: ${msg}`
153
+ : "Buying Buddy declined the render without stating a reason.",
154
+ };
155
+ }
156
+ /**
157
+ * Server-render one Buying Buddy widget and return its HTML.
158
+ *
159
+ * Call this where your framework runs server-side - a Next.js Server Component or
160
+ * `getServerSideProps`, an Express handler, a Remix loader - and put the result
161
+ * in a `<bb-widget>` mount, using `widgetMountProps` or your own templating.
162
+ * `<BuyingBuddyServerWidget>` does the mounting for you, but it is an async
163
+ * Server Component and so needs a framework that supports those; this function
164
+ * is the one that works everywhere.
165
+ *
166
+ * **The page must also declare `seo="true"`** on `<BuyingBuddyProvider>`. That
167
+ * flag is what tells the widget runtime the markup is already present, so it
168
+ * adopts yours instead of fetching its own. Without it the client fetches anyway
169
+ * and replaces what you rendered; it is a page-level flag, so every Buying Buddy
170
+ * widget on a page that sets it must come through this path.
171
+ *
172
+ * @throws {BuyingBuddyError} on any outcome that is not rendered HTML.
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * const { html, meta, filterString } = await renderWidget({
177
+ * type: "OfficeRoster",
178
+ * activationKey: process.env.BUYING_BUDDY_KEY!,
179
+ * domain: "www.example.com",
180
+ * visitor: { ip: (await headers()).get("x-forwarded-for")?.split(",")[0] },
181
+ * });
182
+ * ```
183
+ */
184
+ export async function renderWidget(options) {
185
+ const { type, activationKey, domain, filter, page = "index", propertyId, visitor, baseUrl = DEFAULT_BASE_URL, timeoutMs = DEFAULT_TIMEOUT_MS, } = options;
186
+ if (!activationKey) {
187
+ throw new BuyingBuddyError("invalid_request", "`activationKey` is required - it is the `acid` value from your Buying Buddy account.");
188
+ }
189
+ if (!domain) {
190
+ throw new BuyingBuddyError("invalid_request", "`domain` is required. A server render cannot detect the site's hostname, and the " +
191
+ "Buying Buddy server checks it against the domains authorized on your account.");
192
+ }
193
+ if (!SSR_WIRE_TYPES.has(wireType(String(type)))) {
194
+ throw new BuyingBuddyError("unsupported_widget", `"${type}" cannot be server-rendered. Render it with <BuyingBuddyWidget> from ` +
195
+ `"@buyingbuddy/react" instead. Server-renderable types: ` +
196
+ `${SSR_WIDGET_TYPES.join(", ")}.`);
197
+ }
198
+ if (!isSafePage(page)) {
199
+ throw new BuyingBuddyError("invalid_request", `\`page\` must be "index", "roster", "roster/<office>" or "agent/name/<agent>", ` +
200
+ `using only letters, digits, "-" and "_" in the slug - received "${page}". ` +
201
+ `The value goes into the request path, so it is matched against known forms ` +
202
+ `rather than escaped.`);
203
+ }
204
+ // The `index` action segment is REQUIRED and is not the widget page: ZF1 reads
205
+ // the third path segment as the controller action, so omitting it dispatches an
206
+ // action called "widget-type" and the request throws. The widget's own page is
207
+ // a later pair. Matches the WordPress plugin's URL exactly.
208
+ const path = page === "index"
209
+ ? `/widget/render/index/widget-type/${wireType(type)}/json-api/nodejs`
210
+ : `/widget/render/index/widget-type/${wireType(type)}/widget-page/${page}/json-api/nodejs`;
211
+ const url = `${baseUrl.replace(/\/+$/, "")}${path}`;
212
+ // `json-api=nodejs` is what makes the server merge this body. PHP only fills
213
+ // $_POST for form-encoded bodies, so without that marker a JSON body is
214
+ // invisible and the request looks like it carries no activation key at all.
215
+ const body = {
216
+ acid: activationKey,
217
+ mbbdomain: domain,
218
+ filter: filter ?? "",
219
+ property_id: propertyId ?? "",
220
+ };
221
+ if (visitor?.mbbid)
222
+ body.mbbid = visitor.mbbid;
223
+ if (visitor?.lacid)
224
+ body.lacid = visitor.lacid;
225
+ const headers = {
226
+ Accept: "*/*",
227
+ "Content-Type": "application/json",
228
+ "Cache-Control": "max-age=0",
229
+ "X-BB-Source": "node-sdk",
230
+ "X-BB-Version": PKG_VERSION,
231
+ "User-Agent": `BuyingBuddy-Node-SSR/${PKG_VERSION}`,
232
+ };
233
+ // Only when there is a visitor to forward. A render with none - a build-time
234
+ // render, a cron job - must send nothing rather than this server's own address,
235
+ // because the server reads this header as the visitor: sending our own IP would
236
+ // put every visitor to the site in one shared rate-limit bucket, which is the
237
+ // problem this header exists to avoid. Sending nothing leaves the connection's
238
+ // own address as the identity, which is the truth.
239
+ if (visitor?.ip)
240
+ headers["X-Forwarded-For"] = visitor.ip;
241
+ let response;
242
+ try {
243
+ response = await fetch(url, {
244
+ method: "POST",
245
+ headers,
246
+ body: JSON.stringify(body),
247
+ signal: AbortSignal.timeout(timeoutMs),
248
+ // This render is part of generating a page; a cached response would mean
249
+ // serving one visitor's resolved widget to another.
250
+ cache: "no-store",
251
+ });
252
+ }
253
+ catch (cause) {
254
+ const timedOut = typeof cause === "object" &&
255
+ cause !== null &&
256
+ (cause.name === "TimeoutError" ||
257
+ cause.name === "AbortError");
258
+ if (timedOut) {
259
+ throw new BuyingBuddyError("timeout", `Buying Buddy did not respond within ${timeoutMs}ms. Do not cache this render - ` +
260
+ `let the next request try again rather than freezing an empty widget into your ` +
261
+ `page cache.`, { cause });
262
+ }
263
+ throw new BuyingBuddyError("network", `Could not reach Buying Buddy at ${baseUrl}.`, { cause });
264
+ }
265
+ if (response.status === 429) {
266
+ const retryAfterHeader = response.headers.get("retry-after");
267
+ const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : undefined;
268
+ throw new BuyingBuddyError("rate_limited", "Buying Buddy rate-limited this render.", {
269
+ status: 429,
270
+ retryAfter: Number.isFinite(retryAfter) ? retryAfter : undefined,
271
+ });
272
+ }
273
+ // Reading the body is its own failure point and has to be wrapped separately:
274
+ // the headers can arrive inside the timeout while the body trickles past it, and
275
+ // then THIS is where the abort surfaces. Unwrapped, a real timeout reached the
276
+ // caller as a bare AbortError with no `code`, so the "do not cache this render"
277
+ // guidance never arrived and `isBuyingBuddyError` was false for it.
278
+ let text;
279
+ try {
280
+ text = await response.text();
281
+ }
282
+ catch (cause) {
283
+ const aborted = typeof cause === "object" &&
284
+ cause !== null &&
285
+ (cause.name === "TimeoutError" ||
286
+ cause.name === "AbortError");
287
+ throw new BuyingBuddyError(aborted ? "timeout" : "network", aborted
288
+ ? `Buying Buddy sent headers but did not finish the response body within ` +
289
+ `${timeoutMs}ms. Do not cache this render - let the next request try again ` +
290
+ `rather than freezing an empty widget into your page cache.`
291
+ : "The connection to Buying Buddy dropped while reading the response.", { status: response.status, cause });
292
+ }
293
+ let payload;
294
+ try {
295
+ payload = JSON.parse(text);
296
+ }
297
+ catch (cause) {
298
+ // A wrong path answers with an HTML error page, not JSON, so this is the
299
+ // shape a typo in `baseUrl` or an unrecognised widget type arrives as.
300
+ throw new BuyingBuddyError("invalid_response", `Buying Buddy returned a non-JSON response (HTTP ${response.status}).`, { status: response.status, serverHtml: text.slice(0, 2000), cause });
301
+ }
302
+ // `JSON.parse` succeeds on the literal body `null`, and on a bare string or
303
+ // number, so a proxy or a misconfigured endpoint can get past the catch above
304
+ // and then throw a raw TypeError on the first property read. That broke this
305
+ // module's one contract - that every failure is a BuyingBuddyError carrying a
306
+ // code - for the one response shape nobody tests.
307
+ if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
308
+ throw new BuyingBuddyError("invalid_response", `Buying Buddy returned JSON that is not a response envelope (HTTP ${response.status}).`, { status: response.status, serverHtml: text.slice(0, 2000) });
309
+ }
310
+ const rawData = payload.data;
311
+ const data = rawData !== null && typeof rawData === "object" && !Array.isArray(rawData)
312
+ ? rawData
313
+ : {};
314
+ const html = asString(data.html);
315
+ const msg = asString(payload.msg);
316
+ // `success` is the STRING "true", in both envelope shapes, and comparing it to
317
+ // a boolean is how a consumer silently treats every failure as a success.
318
+ if (payload.success !== "true") {
319
+ const { code, message } = classifyRefusal(msg, html);
320
+ throw new BuyingBuddyError(code, message, {
321
+ status: response.status,
322
+ serverHtml: html,
323
+ serverMessage: msg,
324
+ });
325
+ }
326
+ if (html === undefined) {
327
+ throw new BuyingBuddyError("invalid_response", "Buying Buddy reported success but sent no widget HTML.", { status: response.status, serverMessage: msg });
328
+ }
329
+ const total = Number(payload.total);
330
+ return {
331
+ html,
332
+ meta: readMetadata(data),
333
+ // `typeof` rather than asString, which maps "" to undefined. Here the two
334
+ // cases differ: a key the server did not send means "nothing to echo, use
335
+ // what was asked for", while an explicit "" means the server resolved this
336
+ // request to no criteria at all - and falling back there would put the
337
+ // original pointer (`id:22`) back on the mount for the client to re-apply,
338
+ // which is the exact loss this field exists to prevent.
339
+ filterString: typeof data.filter_string === "string" ? data.filter_string : filter ?? "",
340
+ total: Number.isFinite(total) ? total : 0,
341
+ mapCenter: asString(data.map_center),
342
+ };
343
+ }
344
+ //# sourceMappingURL=renderWidget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderWidget.js","sourceRoot":"","sources":["../../src/server/renderWidget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQ/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,YAAY;IACZ,aAAa;IACb,iBAAiB;IACjB,cAAc;IACd,QAAQ;IACR,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACZ,cAAc;IACd,aAAa;IACb,cAAc;IACd,aAAa;IACb,eAAe;IACf,YAAY;CAC+B,CAAC;AAE9C,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,eAAe,GAAsB;IACzC,SAAS;IACT,4EAA4E;IAC5E,mEAAmE;IACnE,aAAa;IACb,6BAA6B;IAC7B,sBAAsB;IACtB,+BAA+B;CAChC,CAAC;AAEF,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAA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