Data Dictionary
Canonical reference for every data model and backend function endpoint.
Built-in fields (every entity)
All entities automatically include: id (string), created_date, updated_date, and created_by_id (the authenticated user who created the record). These are managed by the platform and never set by client code.
Listing
The core marketplace record. A listing represents livestock, equipment, feed, property, services, or other rural goods posted by a user. New listings start in Pending approval and require admin approval before going live.
| Field | Type | Description |
|---|---|---|
| titlerequired | string | Listing title (max 200 chars). |
| description | string | Full listing description (max 10,000 chars). |
| categoryrequired | enum | Livestock · Farm Equipment · Hay, Feed & Seed · Farm Supplies · Property & Agriculture · Services · Pets & Companion Animals · Miscellaneous. |
| subcategory | string | Subcategory (e.g. Cattle, Tractors, Round Bales). |
| price | number | Asking price in USD. Null = contact for price. |
| price_type | enum | Fixed · Negotiable · Auction · Contact for Price (default Fixed). |
| condition | enum | New · Like New · Good · Fair · Salvage · N/A (default N/A). |
| images | string[] | Image URLs (max 20). First image is the cover. |
| cityrequired | string | City. |
| staterequired | string | State. |
| zip_code | string | ZIP code. |
| contact_name | string | Display name for the poster. |
| contact_phone | string | Server-anchored to the poster's profile phone. |
| contact_email | string | Server-anchored to the poster's verified account email. |
| specs | object<string,string> | Key-value attributes (Breed, Year, Make, Model, Acres, etc.). |
| status | enum | Active · Sold · Pending · Expired (default Active). |
| approval_status | enum | Pending · Approved · Rejected. Server-set only. |
| rejection_reason | string | Reason given to the poster when rejected. |
| discounted_price | number | Admin-overridden discounted sale price. |
| promo_partner | string | Vendor/partner name for promotional listings. |
| views | number | View counter (incremented server-side). |
| inquiries | number | Inquiry counter (incremented server-side). |
| fb_posted | boolean | Whether posted to the Facebook page. |
| fb_posted_date | date | Date last posted to Facebook. |
| fb_post_id | string | Facebook post ID (pageId_postId). |
RLS — Row-Level Security
Read: public (empty rule). Create / Update: admin-only via direct SDK — normal users must go through the create-listing and update-listing backend functions, which run as service role and enforce field control. Delete: the record owner or an admin.
Inquiry
A message from a buyer to a listing owner. Buyers may be anonymous (no account required). The listing_owner_id field anchors RLS so only the listing owner and admins can read and manage inquiries on their listings.
| Field | Type | Description |
|---|---|---|
| listing_idrequired | string | ID of the listing inquired about. |
| listing_owner_id | string | User ID of the listing owner — anchors RLS. |
| sender_namerequired | string | Buyer's name. |
| sender_email | string | Buyer's email (optional). |
| sender_phone | string | Buyer's phone (optional). |
| messagerequired | string | The inquiry message. |
| description | string | Optional additional details (max 1,000 chars). |
| status | enum | New · Read · Replied (default New). |
RLS
Read / Update: the listing owner (matched on listing_owner_id == user.id) or an admin. Create: public (buyers need no account). Delete: admin-only.
Advertisement
A paid banner ad displayed on the homepage and browse pages. Ads are created via the create-checkout function (paid subscriptions) or the admin portal (vendor partnerships). Paid ads move through Pending → Pending Review → Active as the webhook confirms payment.
| Field | Type | Description |
|---|---|---|
| business_namerequired | string | Advertiser business name. |
| headlinerequired | string | Short ad headline shown in the banner. |
| description | string | Supporting ad copy. |
| image_url | string | Logo or banner image URL. |
| target_url | string | Link URL (http/https only). If blank, a call-to-inquire phone button is shown. |
| placement | enum | Homepage Banner · Browse Banner · All (default All). |
| plan | enum | Monthly · Quarterly · Annual · Vendor Partnership. |
| start_date | date | Campaign start date. |
| end_date | date | Campaign end date. |
| status | enum | Pending · Pending Review · Active · Expired · Rejected. |
| checkout_id | string | Wix checkout session ID — links the payment to this ad. |
| subscription_id | string | Wix subscription contract ID (set by webhook). |
| contact_name | string | Advertiser contact name. |
| contact_email | string | Advertiser contact email. |
| contact_phone | string | Public phone for phone-only ads. |
| rejection_reason | string | Reason given when an ad is rejected. |
RLS
Read: public. Create / Update / Delete: admin-only. The create-checkout function (admin-gated) and the payment webhook (service role) are the only write paths for paid ads.
BlogPost
An editorial blog post. Published posts are auto-shared to the Barnyard Listing Facebook page.
| Field | Type | Description |
|---|---|---|
| titlerequired | string | Post title. |
| body | string | Full post content (plain text / light markdown). |
| excerpt | string | Short summary shown in cards and the Facebook post. |
| image_url | string | Cover image URL. |
| category | enum | General · News · Tips & Guides · Announcement · Market Update · Featured (default General). |
| status | enum | Draft · Published (default Draft). |
| published_date | date | Date published. |
| author | string | Author name. |
| fb_posted | boolean | Whether pushed to Facebook. |
| fb_posted_date | date | Date last pushed to Facebook. |
| fb_post_id | string | Facebook post ID (pageId_postId). |
RLS
Read: public. Create / Update / Delete: admin-only.
FacebookPost
An audit log record of every listing or blog post pushed to the Barnyard Listing Facebook page.
| Field | Type | Description |
|---|---|---|
| listing_idrequired | string | ID of the listing or blog post promoted. |
| listing_title | string | Title at time of posting. |
| category | string | Listing category. |
| subcategory | string | Listing subcategory. |
| fb_post_idrequired | string | Facebook post ID (pageId_postId). |
| message | string | The policy-safe message that was posted. |
| page_id | string | Facebook page ID. |
| page_name | string | Facebook page name. |
| posted_daterequired | date | Date posted. |
| source | enum | listing · blog (default listing). |
| link | string | The public URL shared in the post. |
RLS
All operations (create / read / update / delete) restricted to admins. This is an internal audit table.
User
The built-in platform user. Users join via invite; records cannot be created directly through the SDK. The phone field is the user's profile phone, shown on their listings.
| Field | Type | Description |
|---|---|---|
| rolerequired | enum | admin · user. |
| phone | string | Profile phone — shown on the user's listings. Set from the Dashboard profile tab. |
| full_name | string | Display name (read-only, platform-managed). |
| string | Verified account email (read-only, platform-managed). |
Built-in security
Only admins can list, update, or delete other users. A user updates their own profile (e.g. phone) via base44.auth.updateMe().
Backend Function API Reference
Backend functions are HTTP handlers deployed at /functions/<name>. From the frontend, invoke them through the SDK: base44.functions.invoke('name', payload) — never a raw fetch. All functions return JSON.
create-listing
Auth: logged-in user Creates a listing. Validates and whitelists user fields; sets all system/moderation fields server-side. Contact email & phone are anchored to the authenticated account.
Request
POST /functions/create-listing
{
"title": "Angus Cow — Bred Heifer",
"category": "Livestock",
"subcategory": "Cattle",
"description": "...",
"price": 1200,
"price_type": "Fixed",
"condition": "Good",
"city": "Austin", "state": "TX", "zip_code": "78701",
"images": ["https://..."],
"specs": { "Breed": "Angus" },
"contact_name": "Jane"
}Response (200)
{ "ok": true, "id": "<listing_id>" }update-listing
Auth: owner or admin Partial update of a listing. Verifies ownership; strips all system fields. Contact email & phone are re-anchored to the account on every call.
Request
POST /functions/update-listing
{ "id": "<listing_id>", "title": "...", "price": 1100, ... }Response (200)
{ "ok": true, "listing": { ...updated } }admin-portal
Auth: admin A single multiplexed endpoint for moderation actions. The action field selects the operation.
| Field | Type | Description |
|---|---|---|
| approve_listing | action | Approve a listing → Active, emails creator, auto-posts to Facebook. |
| reject_listing | action | Reject a listing (requires reason), emails creator. |
| unpublish_listing | action | Pull a live listing back to Pending review, emails creator. |
| discount_listing | action | Set discounted_price / promo_partner. |
| delete_listing | action | Admin deletes a listing. |
| approve_ad | action | Approve an ad → Active, emails advertiser. |
| reject_ad | action | Reject an ad (requires reason), emails advertiser. |
| create_ad | action | Admin-authored vendor ad (no payment). |
| update_ad | action | Edit an existing ad. |
| publish_blog | action | Publish a blog post + auto-post to Facebook. |
| delete_blog | action | Delete a blog post. |
create-checkout
Auth: admin Creates a Wix (Base44 Payments) subscription checkout session for an ad and persists a pending Advertisement linked by checkout_id. Returns a redirect URL.
Request
POST /functions/create-checkout
{
"plan": "Monthly", // Monthly | Quarterly | Annual
"business_name": "Acme Feed",
"headline": "Quality feed, delivered",
"target_url": "https://acme.com",
"contact_phone": "555-123-4567",
...
}Response (200)
{ "redirectUrl": "https://...wix checkout URL..." }wix-payments-webhook
Auth: JWT (Wix) Receives Wix payment events. Verifies the RS256 JWT with WIX_PAYMENTS_WEBHOOK_PUBLIC_KEY. On order_approved, moves the matching ad to Pending Review and stores the subscription ID. On subscription cancel/expire, marks the ad Expired. Registered for ORDER_APPROVED, SUBSCRIPTION_CANCELED, SUBSCRIPTION_ENDED.
notify-admin
Auth: authenticated Emails all admin users. Action: new_listing (poster must be logged in & own the listing). All user-supplied text is sanitized against header/HTML injection. Inquiry notifications are handled internally by submit-inquiry.
increment-listing-stat
Auth: public Increments views or inquiries on a listing. Runs as service role (Listing RLS blocks anonymous writes). Rate-limited to one increment per IP + listing + field per minute.
Request
POST /functions/increment-listing-stat
{ "listing_id": "<id>", "field": "views" }post-to-facebook / post-blog-to-facebook
Auth: admin Manually trigger a Facebook cross-post for a listing or blog post. (Approval also auto-triggers listing posts.) Both delegate to the shared fb-post.ts module, which runs an AI safety check on photos before posting.