@brainerce/mcp-server 3.2.0 → 3.4.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/dist/bin/http.js +377 -4
- package/dist/bin/stdio.js +377 -4
- package/dist/index.js +377 -4
- package/dist/index.mjs +377 -4
- package/package.json +53 -53
package/dist/index.js
CHANGED
|
@@ -1888,6 +1888,265 @@ const admin = new BrainerceClient({ apiKey: 'brainerce_...' });
|
|
|
1888
1888
|
// OAuth: getOAuthProviders(), configureOAuthProvider()
|
|
1889
1889
|
\`\`\``;
|
|
1890
1890
|
}
|
|
1891
|
+
function getContactInquiriesSection() {
|
|
1892
|
+
return `## Contact Inquiries & Forms (optional)
|
|
1893
|
+
|
|
1894
|
+
Accept messages from one or more contact forms on your storefront. The merchant
|
|
1895
|
+
configures everything in the Brainerce dashboard under **Customers \u2192 Contact
|
|
1896
|
+
Forms**; submissions land in **Customers \u2192 Inquiries** and both sides receive
|
|
1897
|
+
email notifications.
|
|
1898
|
+
|
|
1899
|
+
**IMPORTANT for AI code generators:** the merchant OWNS the form shape. Do not
|
|
1900
|
+
hardcode labels, placeholders, help text, the submit button, or the success
|
|
1901
|
+
message. Render from the schema returned by \`contactForms.get()\` so the
|
|
1902
|
+
storefront reflects whatever the merchant configures \u2014 including new fields
|
|
1903
|
+
they add later, translations they add later, and the success message they
|
|
1904
|
+
write. This is the difference between "a contact form" and "THE merchant's
|
|
1905
|
+
contact form."
|
|
1906
|
+
|
|
1907
|
+
### Two integration paths
|
|
1908
|
+
|
|
1909
|
+
1. **Simple (legacy)** \u2014 pass \`{ name, email, subject, message }\` and submit.
|
|
1910
|
+
Works out of the box, no dashboard setup needed. Backed by a lazily-seeded
|
|
1911
|
+
default form keyed \`"main"\` with five built-in fields (\`name\`, \`email\`,
|
|
1912
|
+
\`phone\`, \`subject\`, \`message\`). Choose this only for throwaway demos.
|
|
1913
|
+
2. **Flexible (recommended, default in \`npx create-brainerce-store\`)** \u2014
|
|
1914
|
+
merchants can configure multiple forms per store (e.g. \`main\`,
|
|
1915
|
+
\`newsletter\`, \`whatsapp_prechat\`), add custom fields (TEXT, TEXTAREA,
|
|
1916
|
+
EMAIL, PHONE, NUMBER, SELECT, MULTI_SELECT, CHECKBOX, URL, DATE), translate
|
|
1917
|
+
everything per locale, hide any non-essential built-in. Fetch the schema
|
|
1918
|
+
with \`contactForms.get(formKey, locale)\` and render dynamically.
|
|
1919
|
+
|
|
1920
|
+
### Simple path (legacy shape)
|
|
1921
|
+
|
|
1922
|
+
\`\`\`typescript
|
|
1923
|
+
import type { CreateInquiryInput, CreateInquiryResponse } from 'brainerce';
|
|
1924
|
+
|
|
1925
|
+
const result = await brainerce.createInquiry({
|
|
1926
|
+
name: 'Jane Doe',
|
|
1927
|
+
email: 'jane@example.com',
|
|
1928
|
+
subject: 'Question about shipping',
|
|
1929
|
+
message: 'Hi, do you ship internationally?',
|
|
1930
|
+
phone: '+1-555-0100', // optional
|
|
1931
|
+
customerId: customer?.id, // optional \u2014 link to logged-in customer
|
|
1932
|
+
metadata: { page: '/contact' }, // optional
|
|
1933
|
+
});
|
|
1934
|
+
// \u2192 { id, status: 'NEW', createdAt }
|
|
1935
|
+
\`\`\`
|
|
1936
|
+
|
|
1937
|
+
### Flexible path \u2014 end-to-end contract
|
|
1938
|
+
|
|
1939
|
+
**Endpoints:**
|
|
1940
|
+
|
|
1941
|
+
| Method | Path | Returns |
|
|
1942
|
+
| ------ | ----------------------------------------------------------------- | ------------------------------ |
|
|
1943
|
+
| GET | \`/stores/:storeId/contact-forms\` | \`ContactFormSummary[]\` |
|
|
1944
|
+
| GET | \`/stores/:storeId/contact-forms/:formKey?locale=xx\` | \`ContactFormPublic\` |
|
|
1945
|
+
| POST | \`/stores/:storeId/inquiries\` | \`CreateInquiryResponse\` |
|
|
1946
|
+
|
|
1947
|
+
All three are public (no API key). The SDK wraps them so you never call them
|
|
1948
|
+
directly \u2014 use \`brainerce.contactForms.list()\`, \`brainerce.contactForms.get()\`,
|
|
1949
|
+
and \`brainerce.createInquiry()\`.
|
|
1950
|
+
|
|
1951
|
+
\`\`\`typescript
|
|
1952
|
+
import type { ContactFormPublic } from 'brainerce';
|
|
1953
|
+
|
|
1954
|
+
// List active forms (optional \u2014 if you want a form picker or route-per-form setup)
|
|
1955
|
+
const forms = await brainerce.contactForms.list();
|
|
1956
|
+
// \u2192 [{ key: 'main', name: 'Contact us', isDefault: true }, ...]
|
|
1957
|
+
|
|
1958
|
+
// Fetch one form's schema \u2014 server pre-resolves translations for the locale
|
|
1959
|
+
// and strips every field the merchant marked isVisible=false.
|
|
1960
|
+
const form = await brainerce.contactForms.get('main', 'en');
|
|
1961
|
+
// \u2192 {
|
|
1962
|
+
// id, key, name, description?, submitButton, successMessage,
|
|
1963
|
+
// fields: [{ key, type, label, placeholder?, helpText?, isRequired,
|
|
1964
|
+
// enumValues?, validation?, defaultValue? }, ...]
|
|
1965
|
+
// }
|
|
1966
|
+
|
|
1967
|
+
// Submit a keyed payload. Unknown keys are stripped, required fields are
|
|
1968
|
+
// enforced, and every value is validated against \`validation\` server-side.
|
|
1969
|
+
await brainerce.createInquiry({
|
|
1970
|
+
formKey: 'main',
|
|
1971
|
+
fields: {
|
|
1972
|
+
email: 'jane@example.com', // built-in keys
|
|
1973
|
+
message: 'Hi...',
|
|
1974
|
+
// ...any custom keys the merchant added via the dashboard
|
|
1975
|
+
},
|
|
1976
|
+
locale: 'en', // stored on the inquiry \u2014 lets staff filter by language
|
|
1977
|
+
sourceMetadata: { page: '/contact' }, // arbitrary provenance (UTM, referrer, etc.)
|
|
1978
|
+
});
|
|
1979
|
+
\`\`\`
|
|
1980
|
+
|
|
1981
|
+
Both shapes go to the same POST endpoint and may be mixed; \`fields\` wins when
|
|
1982
|
+
both provide the same key. Unknown keys (not defined on the form schema) are
|
|
1983
|
+
stripped server-side.
|
|
1984
|
+
|
|
1985
|
+
### Dynamic rendering \u2014 reference implementation
|
|
1986
|
+
|
|
1987
|
+
Render every field type the merchant can pick. Keep this as a \`<DynamicField>\`
|
|
1988
|
+
component so the form is fully driven by \`schema.fields\`.
|
|
1989
|
+
|
|
1990
|
+
\`\`\`tsx
|
|
1991
|
+
import type { ContactFormPublic, ContactFormPublicField } from 'brainerce';
|
|
1992
|
+
|
|
1993
|
+
type FieldValue = string | string[] | boolean;
|
|
1994
|
+
|
|
1995
|
+
function defaultValueFor(f: ContactFormPublicField): FieldValue {
|
|
1996
|
+
if (f.type === 'CHECKBOX') return false;
|
|
1997
|
+
if (f.type === 'MULTI_SELECT') return [];
|
|
1998
|
+
return f.defaultValue ?? '';
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
function isEmpty(v: FieldValue): boolean {
|
|
2002
|
+
if (typeof v === 'string') return v.trim().length === 0;
|
|
2003
|
+
if (Array.isArray(v)) return v.length === 0;
|
|
2004
|
+
return v === false;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
function DynamicField({
|
|
2008
|
+
field,
|
|
2009
|
+
value,
|
|
2010
|
+
onChange,
|
|
2011
|
+
}: {
|
|
2012
|
+
field: ContactFormPublicField;
|
|
2013
|
+
value: FieldValue;
|
|
2014
|
+
onChange: (v: FieldValue) => void;
|
|
2015
|
+
}) {
|
|
2016
|
+
const id = \`contact-\${field.key}\`;
|
|
2017
|
+
const { minLength, maxLength, min, max, pattern } = field.validation ?? {};
|
|
2018
|
+
const strVal = typeof value === 'string' ? value : '';
|
|
2019
|
+
|
|
2020
|
+
// Label \u2014 USE \`field.label\`, NEVER hardcode. Falls back to the key.
|
|
2021
|
+
const label = (
|
|
2022
|
+
<label htmlFor={id} className="mb-1.5 block text-sm font-medium">
|
|
2023
|
+
{field.label}
|
|
2024
|
+
{field.isRequired && <span aria-hidden className="text-red-500"> *</span>}
|
|
2025
|
+
</label>
|
|
2026
|
+
);
|
|
2027
|
+
const help = field.helpText ? <p className="mt-1 text-xs opacity-70">{field.helpText}</p> : null;
|
|
2028
|
+
|
|
2029
|
+
switch (field.type) {
|
|
2030
|
+
case 'TEXTAREA':
|
|
2031
|
+
return (<div>{label}<textarea id={id} required={field.isRequired} maxLength={maxLength} minLength={minLength} rows={6} placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2032
|
+
case 'EMAIL':
|
|
2033
|
+
return (<div>{label}<input id={id} type="email" required={field.isRequired} autoComplete="email" placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2034
|
+
case 'PHONE':
|
|
2035
|
+
return (<div>{label}<input id={id} type="tel" required={field.isRequired} autoComplete="tel" placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2036
|
+
case 'URL':
|
|
2037
|
+
return (<div>{label}<input id={id} type="url" required={field.isRequired} placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2038
|
+
case 'NUMBER':
|
|
2039
|
+
return (<div>{label}<input id={id} type="number" required={field.isRequired} min={min} max={max} placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2040
|
+
case 'DATE':
|
|
2041
|
+
return (<div>{label}<input id={id} type="date" required={field.isRequired} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2042
|
+
case 'SELECT':
|
|
2043
|
+
return (<div>{label}<select id={id} required={field.isRequired} value={strVal} onChange={(e) => onChange(e.target.value)}><option value="">\u2014</option>{field.enumValues?.map((o) => (<option key={o.value} value={o.value}>{o.label}</option>))}</select>{help}</div>);
|
|
2044
|
+
case 'MULTI_SELECT': {
|
|
2045
|
+
const arr = Array.isArray(value) ? value : [];
|
|
2046
|
+
return (<div>{label}<div>{field.enumValues?.map((o) => { const checked = arr.includes(o.value); return (<label key={o.value}><input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked ? [...arr, o.value] : arr.filter((v) => v !== o.value))} /><span>{o.label}</span></label>); })}</div>{help}</div>);
|
|
2047
|
+
}
|
|
2048
|
+
case 'CHECKBOX':
|
|
2049
|
+
return (<div><label htmlFor={id}><input id={id} type="checkbox" required={field.isRequired} checked={value === true} onChange={(e) => onChange(e.target.checked)} /><span>{field.label}</span></label>{help}</div>);
|
|
2050
|
+
case 'TEXT':
|
|
2051
|
+
default:
|
|
2052
|
+
return (<div>{label}<input id={id} type="text" required={field.isRequired} maxLength={maxLength} minLength={minLength} pattern={pattern} placeholder={field.placeholder} value={strVal} onChange={(e) => onChange(e.target.value)} />{help}</div>);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
export function ContactPage() {
|
|
2057
|
+
const [schema, setSchema] = useState<ContactFormPublic | null>(null);
|
|
2058
|
+
const [values, setValues] = useState<Record<string, FieldValue>>({});
|
|
2059
|
+
const [honeypot, setHoneypot] = useState('');
|
|
2060
|
+
const [sent, setSent] = useState(false);
|
|
2061
|
+
const [loading, setLoading] = useState(false);
|
|
2062
|
+
|
|
2063
|
+
// Read the current locale from the <html lang> attribute (or your own i18n context).
|
|
2064
|
+
const locale = typeof document !== 'undefined' ? document.documentElement.lang || undefined : undefined;
|
|
2065
|
+
|
|
2066
|
+
useEffect(() => {
|
|
2067
|
+
brainerce.contactForms.get('main', locale).then((form) => {
|
|
2068
|
+
setSchema(form);
|
|
2069
|
+
const initial: Record<string, FieldValue> = {};
|
|
2070
|
+
for (const f of form.fields) initial[f.key] = defaultValueFor(f);
|
|
2071
|
+
setValues(initial);
|
|
2072
|
+
});
|
|
2073
|
+
}, [locale]);
|
|
2074
|
+
|
|
2075
|
+
if (!schema) return null;
|
|
2076
|
+
|
|
2077
|
+
const onSubmit = async (e: React.FormEvent) => {
|
|
2078
|
+
e.preventDefault();
|
|
2079
|
+
if (loading) return;
|
|
2080
|
+
if (honeypot.trim().length > 0) { setSent(true); return; } // bot \u2192 silent success
|
|
2081
|
+
|
|
2082
|
+
setLoading(true);
|
|
2083
|
+
try {
|
|
2084
|
+
const payload: Record<string, unknown> = {};
|
|
2085
|
+
for (const f of schema.fields) {
|
|
2086
|
+
const raw = values[f.key];
|
|
2087
|
+
if (isEmpty(raw)) continue;
|
|
2088
|
+
payload[f.key] = typeof raw === 'string' ? raw.trim() : raw;
|
|
2089
|
+
}
|
|
2090
|
+
await brainerce.createInquiry({ formKey: schema.key, fields: payload, locale });
|
|
2091
|
+
setSent(true);
|
|
2092
|
+
} finally {
|
|
2093
|
+
setLoading(false);
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
|
|
2097
|
+
if (sent) {
|
|
2098
|
+
// RENDER THE MERCHANT'S success message \u2014 do not hardcode.
|
|
2099
|
+
return <div>{schema.successMessage}</div>;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
return (
|
|
2103
|
+
<form onSubmit={onSubmit} noValidate>
|
|
2104
|
+
<h1>{schema.name}</h1>
|
|
2105
|
+
{schema.description && <p>{schema.description}</p>}
|
|
2106
|
+
|
|
2107
|
+
{/* Honeypot \u2014 must be visually hidden from humans, not from bots */}
|
|
2108
|
+
<div aria-hidden style={{ position: 'absolute', left: '-10000px', width: 0, height: 0, overflow: 'hidden' }}>
|
|
2109
|
+
<label htmlFor="contact-honeypot">Leave this field empty</label>
|
|
2110
|
+
<input id="contact-honeypot" type="text" tabIndex={-1} autoComplete="off"
|
|
2111
|
+
value={honeypot} onChange={(e) => setHoneypot(e.target.value)} />
|
|
2112
|
+
</div>
|
|
2113
|
+
|
|
2114
|
+
{schema.fields.map((field) => (
|
|
2115
|
+
<DynamicField key={field.key} field={field}
|
|
2116
|
+
value={values[field.key] ?? defaultValueFor(field)}
|
|
2117
|
+
onChange={(v) => setValues((p) => ({ ...p, [field.key]: v }))} />
|
|
2118
|
+
))}
|
|
2119
|
+
|
|
2120
|
+
<button type="submit" disabled={loading}>
|
|
2121
|
+
{loading ? '\u2026' : schema.submitButton}
|
|
2122
|
+
</button>
|
|
2123
|
+
</form>
|
|
2124
|
+
);
|
|
2125
|
+
}
|
|
2126
|
+
\`\`\`
|
|
2127
|
+
|
|
2128
|
+
### Rules
|
|
2129
|
+
|
|
2130
|
+
- **Rate limit:** 3 submissions / 60s per IP \u2014 show a friendly "try again later" message on HTTP 429.
|
|
2131
|
+
- **Honeypot:** always render a hidden field named \`honeypot\` and **never send** it. Bots fill every input; the server rejects submissions carrying a non-empty \`honeypot\`.
|
|
2132
|
+
- **Built-in keys:** \`name\`, \`email\`, \`phone\`, \`subject\`, \`message\` always exist on the default form; the legacy \`createInquiry\` shape keeps working forever.
|
|
2133
|
+
- **Max values:** each field value is capped at 10 000 chars server-side. Validate client-side before submitting using \`field.validation.maxLength\`.
|
|
2134
|
+
- **Required fields:** respect \`field.isRequired\`. The server validates too, but show \`required\` on the input for browser-level UX.
|
|
2135
|
+
- **Validation:** when \`field.validation.pattern\` is present, pass it as the input's \`pattern\` attribute; the server also enforces it. Likewise \`minLength\`/\`maxLength\`/\`min\`/\`max\`.
|
|
2136
|
+
- **Enum values:** SELECT and MULTI_SELECT always return \`enumValues\` (non-empty array). Render from \`enumValues\`, never a hardcoded list.
|
|
2137
|
+
- **Visibility:** the server strips fields with \`isVisible=false\`, so \`schema.fields\` only contains things to render.
|
|
2138
|
+
- **Origin check:** the endpoint validates \`Origin\` against the store's allowed origins. Test from your real storefront URL, not \`file://\` or localhost unless the merchant added it to allowed origins.
|
|
2139
|
+
- **Locale handling:** always pass \`locale\` to \`contactForms.get()\` and to \`createInquiry()\`. The staff inbox filters inquiries by language. Omit to fall back to the store's default language.
|
|
2140
|
+
- **Success message:** render \`schema.successMessage\` as-is. (Variable interpolation like \`{{customerName}}\` is not yet wired; any such placeholders currently render literally. Safe to use plain text.)
|
|
2141
|
+
- **Caching:** the schema GET is safe to cache per \`{storeId, formKey, locale}\`. 60 s feels live without hammering the API.
|
|
2142
|
+
|
|
2143
|
+
### Multiple forms
|
|
2144
|
+
|
|
2145
|
+
If the merchant set up more than one form (e.g. a \`main\` form on \`/contact\`
|
|
2146
|
+
and a \`newsletter\` form embedded in the footer), render each form from its
|
|
2147
|
+
own \`contactForms.get(key, locale)\` call. The \`formKey\` you pass to
|
|
2148
|
+
\`createInquiry\` must match.`;
|
|
2149
|
+
}
|
|
1891
2150
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
1892
2151
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
1893
2152
|
const cur = currency || "USD";
|
|
@@ -1926,6 +2185,8 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
1926
2185
|
return getTypeQuickReference();
|
|
1927
2186
|
case "admin":
|
|
1928
2187
|
return getAdminApiSection();
|
|
2188
|
+
case "inquiries":
|
|
2189
|
+
return getContactInquiriesSection();
|
|
1929
2190
|
case "all":
|
|
1930
2191
|
return [
|
|
1931
2192
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -2002,10 +2263,14 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2002
2263
|
"",
|
|
2003
2264
|
"---",
|
|
2004
2265
|
"",
|
|
2005
|
-
getAdminApiSection()
|
|
2266
|
+
getAdminApiSection(),
|
|
2267
|
+
"",
|
|
2268
|
+
"---",
|
|
2269
|
+
"",
|
|
2270
|
+
getContactInquiriesSection()
|
|
2006
2271
|
].join("\n");
|
|
2007
2272
|
default:
|
|
2008
|
-
return `Unknown topic: "${topic}". Available topics: setup, products, cart, checkout, checkout-custom-fields, payment, auth, order-confirmation, inventory, discounts, recommendations, product-customization-fields, tax, i18n, critical-rules, type-reference, admin, all`;
|
|
2273
|
+
return `Unknown topic: "${topic}". Available topics: setup, products, cart, checkout, checkout-custom-fields, payment, auth, order-confirmation, inventory, discounts, recommendations, product-customization-fields, tax, i18n, critical-rules, type-reference, admin, inquiries, all`;
|
|
2009
2274
|
}
|
|
2010
2275
|
}
|
|
2011
2276
|
|
|
@@ -2031,6 +2296,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
2031
2296
|
"type-reference",
|
|
2032
2297
|
"i18n",
|
|
2033
2298
|
"admin",
|
|
2299
|
+
"inquiries",
|
|
2034
2300
|
"all"
|
|
2035
2301
|
]).describe("The SDK documentation topic to retrieve"),
|
|
2036
2302
|
connectionId: import_zod.z.string().optional().describe("Vibe-coded connection ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -2691,6 +2957,102 @@ interface CartBundleOffer {
|
|
|
2691
2957
|
requiresVariantSelection: boolean;
|
|
2692
2958
|
lockedVariant?: { id: string; name?: string };
|
|
2693
2959
|
}`;
|
|
2960
|
+
var INQUIRIES_TYPES = `// ---- Contact Inquiries & Forms ----
|
|
2961
|
+
|
|
2962
|
+
// Two shapes \u2014 legacy and flexible. The two may be mixed; \`fields\` wins on key collision.
|
|
2963
|
+
interface CreateInquiryInput {
|
|
2964
|
+
// Legacy shape (still supported forever, backed by default "main" form)
|
|
2965
|
+
name?: string; // max 120 chars (if provided)
|
|
2966
|
+
email?: string; // must be valid email if provided
|
|
2967
|
+
subject?: string; // max 200 chars
|
|
2968
|
+
message?: string; // max 10000 chars
|
|
2969
|
+
phone?: string;
|
|
2970
|
+
|
|
2971
|
+
// Flexible shape
|
|
2972
|
+
formKey?: string; // defaults to "main"; merchant-defined keys e.g. "newsletter"
|
|
2973
|
+
fields?: Record<string, unknown>; // bag of values keyed by field key (built-in or custom)
|
|
2974
|
+
locale?: string; // e.g. "en", "he" \u2014 stored on the inquiry
|
|
2975
|
+
sourceMetadata?: Record<string, unknown>; // arbitrary context (e.g. { page: '/contact', campaign: 'fall-2026' })
|
|
2976
|
+
|
|
2977
|
+
// Shared
|
|
2978
|
+
customerId?: string; // link to logged-in customer
|
|
2979
|
+
metadata?: Record<string, unknown>; // deprecated alias of sourceMetadata
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
interface CreateInquiryResponse {
|
|
2983
|
+
id: string;
|
|
2984
|
+
status: 'NEW';
|
|
2985
|
+
createdAt: string; // ISO datetime
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
// ---- Form schema (for dynamic rendering) ----
|
|
2989
|
+
|
|
2990
|
+
type ContactFormFieldType =
|
|
2991
|
+
| 'TEXT' | 'TEXTAREA' | 'EMAIL' | 'PHONE' | 'NUMBER'
|
|
2992
|
+
| 'SELECT' | 'MULTI_SELECT' | 'CHECKBOX' | 'URL' | 'DATE';
|
|
2993
|
+
|
|
2994
|
+
interface ContactFormFieldValidation {
|
|
2995
|
+
minLength?: number;
|
|
2996
|
+
maxLength?: number;
|
|
2997
|
+
min?: number;
|
|
2998
|
+
max?: number;
|
|
2999
|
+
pattern?: string; // regex string
|
|
3000
|
+
patternMessage?: string;
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
interface ContactFormPublicField {
|
|
3004
|
+
key: string; // stable identifier, e.g. "email", "company"
|
|
3005
|
+
type: ContactFormFieldType;
|
|
3006
|
+
label: string; // already localized for the requested locale
|
|
3007
|
+
placeholder?: string; // already localized
|
|
3008
|
+
helpText?: string; // already localized
|
|
3009
|
+
isRequired: boolean;
|
|
3010
|
+
enumValues?: { value: string; label: string }[]; // present (non-empty) for SELECT / MULTI_SELECT
|
|
3011
|
+
validation?: ContactFormFieldValidation;
|
|
3012
|
+
defaultValue?: string;
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
interface ContactFormPublic {
|
|
3016
|
+
id: string;
|
|
3017
|
+
key: string; // e.g. "main", "newsletter"
|
|
3018
|
+
name: string; // already localized \u2014 use as form heading
|
|
3019
|
+
description?: string; // already localized \u2014 use as subtitle
|
|
3020
|
+
submitButton: string; // already localized \u2014 use as submit label
|
|
3021
|
+
successMessage: string; // already localized \u2014 render after submit succeeds
|
|
3022
|
+
fields: ContactFormPublicField[]; // in display order; hidden fields already filtered out
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3025
|
+
interface ContactFormSummary {
|
|
3026
|
+
key: string;
|
|
3027
|
+
name: string;
|
|
3028
|
+
isDefault: boolean;
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
// Field-type \u2192 HTML mapping for dynamic rendering
|
|
3032
|
+
// ------------------------------------------------------------------
|
|
3033
|
+
// TEXT \u2192 <input type="text" ... pattern?={validation.pattern}>
|
|
3034
|
+
// TEXTAREA \u2192 <textarea rows={6} ...>
|
|
3035
|
+
// EMAIL \u2192 <input type="email" autoComplete="email" ...>
|
|
3036
|
+
// PHONE \u2192 <input type="tel" autoComplete="tel" ...>
|
|
3037
|
+
// NUMBER \u2192 <input type="number" min={validation.min} max={validation.max}>
|
|
3038
|
+
// URL \u2192 <input type="url" ...>
|
|
3039
|
+
// DATE \u2192 <input type="date" ...> (value is ISO yyyy-MM-dd)
|
|
3040
|
+
// SELECT \u2192 <select>{enumValues.map(...)}</select> \u2014 always rendered from enumValues
|
|
3041
|
+
// MULTI_SELECT \u2192 multiple <input type="checkbox">, value is string[]
|
|
3042
|
+
// CHECKBOX \u2192 single <input type="checkbox">, value is boolean
|
|
3043
|
+
// ------------------------------------------------------------------
|
|
3044
|
+
|
|
3045
|
+
// SDK methods
|
|
3046
|
+
// await brainerce.createInquiry(input) \u2192 POST /stores/{storeId}/inquiries
|
|
3047
|
+
// await brainerce.contactForms.list() \u2192 GET /stores/{storeId}/contact-forms
|
|
3048
|
+
// await brainerce.contactForms.get(key?, locale?) \u2192 GET /stores/{storeId}/contact-forms/{key}?locale={locale}
|
|
3049
|
+
//
|
|
3050
|
+
// Rules
|
|
3051
|
+
// - Rate limit: 3 submissions / 60s per IP \u2014 handle 429 responses gracefully
|
|
3052
|
+
// - Honeypot: always render an invisible field named \`honeypot\` and never send it
|
|
3053
|
+
// - Always pass \`locale\` \u2014 inbox filters inquiries by language, and schema labels come back translated
|
|
3054
|
+
// - Render \`schema.name\` / \`description\` / \`submitButton\` / \`successMessage\` directly \u2014 do NOT hardcode copy
|
|
3055
|
+
// - Unknown field keys are stripped server-side \u2014 safe to send extras during dev`;
|
|
2694
3056
|
var TYPES_BY_DOMAIN = {
|
|
2695
3057
|
products: PRODUCTS_TYPES,
|
|
2696
3058
|
cart: CART_TYPES,
|
|
@@ -2698,7 +3060,8 @@ var TYPES_BY_DOMAIN = {
|
|
|
2698
3060
|
orders: ORDERS_TYPES,
|
|
2699
3061
|
customers: CUSTOMERS_TYPES,
|
|
2700
3062
|
payments: PAYMENTS_TYPES,
|
|
2701
|
-
helpers: HELPERS_TYPES
|
|
3063
|
+
helpers: HELPERS_TYPES,
|
|
3064
|
+
inquiries: INQUIRIES_TYPES
|
|
2702
3065
|
};
|
|
2703
3066
|
function getTypesByDomain(domain) {
|
|
2704
3067
|
if (domain === "all") {
|
|
@@ -2719,7 +3082,17 @@ var AVAILABLE_DOMAINS = Object.keys(TYPES_BY_DOMAIN);
|
|
|
2719
3082
|
var GET_TYPE_DEFINITIONS_NAME = "get-type-definitions";
|
|
2720
3083
|
var GET_TYPE_DEFINITIONS_DESCRIPTION = "Get TypeScript type definitions from the Brainerce SDK, segmented by domain. Use this when you need to understand the exact shape of objects like Product, Cart, Checkout, Order, etc.";
|
|
2721
3084
|
var GET_TYPE_DEFINITIONS_SCHEMA = {
|
|
2722
|
-
domain: import_zod2.z.enum([
|
|
3085
|
+
domain: import_zod2.z.enum([
|
|
3086
|
+
"products",
|
|
3087
|
+
"cart",
|
|
3088
|
+
"checkout",
|
|
3089
|
+
"orders",
|
|
3090
|
+
"customers",
|
|
3091
|
+
"payments",
|
|
3092
|
+
"helpers",
|
|
3093
|
+
"inquiries",
|
|
3094
|
+
"all"
|
|
3095
|
+
]).describe(
|
|
2723
3096
|
'The domain of types to retrieve. Use "helpers" for helper function signatures and common types like StoreInfo, PaginatedResponse.'
|
|
2724
3097
|
)
|
|
2725
3098
|
};
|