npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alex-serban/domus-typesense

v0.2.17

Published

Typesense integration package for Domus CRM property search

Readme

@alex-serban/domus-typesense

Typesense integration package for Domus CRM property search with agency-scoped collections.

Installation

npm install @alex-serban/domus-typesense

Features

  • Agency-scoped collections - One collection per agency (properties-agency-{agencyId})
  • Type-safe property search - Full TypeScript support
  • React hooks - usePropertySearch and useFacets with nuqs URL sync
  • Property operations - Export, upsert, delete properties
  • Collection management - Create/delete collections per agency
  • Dynamic facets - Real-time filter counts and range calculations
  • Next.js integration - API route helpers included

Quick Start

1. Initialize Typesense Client

import { createTypesenseClient } from '@alex-serban/domus-typesense';

const client = createTypesenseClient({
  nodes: [
    {
      host: 'your-typesense-host.com',
      port: 443,
      protocol: 'https',
    },
  ],
  apiKey: 'your-api-key',
  connectionTimeoutSeconds: 2,
});

2. Create Property Search Service

import { PropertySearchService } from '@alex-serban/domus-typesense';

const searchService = new PropertySearchService(client);

3. Search Properties

const results = await searchService.search(agencyId, {
  query: 'apartment',
  types: ['apartment', 'house'],
  scopes: ['SALE', 'RENT'],
  cityIds: ['Iasi'],
  minPrice: 50000,
  maxPrice: 500000,
  page: 1,
  perPage: 20,
  sortBy: 'price',
  sortOrder: 'asc',
});

console.log(`Found ${results.found} properties`);
results.hits.forEach(property => {
  console.log(property.name, property.price);
});

4. Get Facets

const facets = await searchService.getFacets(agencyId, {
  types: ['apartment'],
});

// Get available cities, types, scopes with counts
console.log(facets.cities); // [{ value: 'Iasi', count: 6 }, ...]
console.log(facets.types);  // [{ value: 'apartment', count: 10 }, ...]

// Get price and sqm ranges
const priceRange = await searchService.getPriceRange(agencyId, filters);
const sqmRange = await searchService.getSqmRange(agencyId, filters);

React Hooks

usePropertySearch

Search properties with automatic URL sync via nuqs:

import { usePropertySearch } from '@alex-serban/domus-typesense';

function SearchPage({ agencyId }: { agencyId: string }) {
  const { results, loading, error, filters, updateFilters, refetch } = 
    usePropertySearch(agencyId, '/api/search-properties');

  return (
    <div>
      {loading && <p>Loading...</p>}
      {error && <p>Error: {error.message}</p>}
      {results && (
        <div>
          <p>Found {results.found} properties</p>
          {results.hits.map(property => (
            <div key={property.id}>{property.name}</div>
          ))}
        </div>
      )}
      <button onClick={() => updateFilters({ types: ['apartment'] })}>
        Filter Apartments
      </button>
    </div>
  );
}

useFacets

Fetch dynamic facets with URL sync:

import { useFacets } from '@alex-serban/domus-typesense';

function Filters({ agencyId }: { agencyId: string }) {
  const { facets, loading } = useFacets(agencyId);

  if (!facets) return <div>Loading filters...</div>;

  return (
    <div>
      <h3>Property Types</h3>
      {facets.types.map(type => (
        <label key={type.value}>
          <input type="checkbox" />
          {type.value} ({type.count})
        </label>
      ))}
      
      <h3>Price Range</h3>
      <p>
        {facets.priceRange.min} - {facets.priceRange.max} EUR
      </p>
    </div>
  );
}

Property Operations

Create Collection for Agency

import { createCollection } from '@alex-serban/domus-typesense';

await createCollection(client, agencyId);

Export Properties

import { exportProperties } from '@alex-serban/domus-typesense';

const properties = [
  { property: apartmentData, type: 'apartment' },
  { property: houseData, type: 'house' },
];

const result = await exportProperties(client, agencyId, properties);
console.log(`Exported ${result.exported} properties, ${result.errors} errors`);

Upsert Single Property

import { upsertProperty } from '@alex-serban/domus-typesense';

await upsertProperty(
  client,
  agencyId,
  propertyWithRelations,
  'apartment' // or 'house', 'commercial', 'industrial', 'land'
);

Delete Property

import { deleteProperty } from '@alex-serban/domus-typesense';

await deleteProperty(client, agencyId, propertyId);

Next.js API Routes

Use the provided helpers for API routes:

// app/api/search-properties/route.ts
import { handleSearchRequest } from '@alex-serban/domus-typesense';
import { propertySearchService } from '~/lib/typesense';

export async function POST(request: NextRequest) {
  return handleSearchRequest(propertySearchService, request);
}

// app/api/search-properties/facets/route.ts
import { handleFacetsRequest } from '@alex-serban/domus-typesense';
import { propertySearchService } from '~/lib/typesense';

export async function GET(request: NextRequest) {
  return handleFacetsRequest(propertySearchService, request);
}

Property Types

The package supports 5 property types:

  • apartment - Apartments
  • house - Houses
  • commercial - Commercial properties
  • industrial - Industrial properties
  • land - Land plots

Each property type has:

  • Common fields - Stored directly in Typesense (price, sqm, location, etc.)
  • ExtraData - Type-specific fields stored as JSON string (rooms, bathrooms, balcony, etc.)

Parse ExtraData

import { parseExtraData } from '@alex-serban/domus-typesense';

const property = results.hits[0];
const extraData = parseExtraData(
  property.extraData,
  property.type as 'apartment' | 'house' | 'commercial' | 'industrial' | 'land'
);

console.log(extraData.rooms); // For apartments/houses
console.log(extraData.balcony); // For apartments
console.log(extraData.garage); // For houses

Collection Names

Collections are automatically named per agency:

  • Format: properties-agency-{agencyId}
  • Example: properties-agency-abc123

API Reference

PropertySearchService

search(agencyId: string, filters: PropertySearchFilters): Promise<PropertySearchResponse>

Search properties for an agency.

getFacets(agencyId: string, filters?: PropertySearchFilters): Promise<Facets>

Get available facets (types, scopes, cities, etc.) with counts.

getPriceRange(agencyId: string, filters?: PropertySearchFilters): Promise<{min: number, max: number}>

Get min/max price range for current filters.

getSqmRange(agencyId: string, filters?: PropertySearchFilters): Promise<{min: number, max: number}>

Get min/max sqm range for current filters.

License

MIT

Links