HairCRM Integration Layer
HairCRM is an independent SaaS product. It integrates with Hair Industry Network exclusively through the Public API v1 — never through direct database access. This page is the canonical contract.
1. Install the SDK
Issue an API key from your account (scopes: read, write).
// HairCRM uses the SDK checked in at src/lib/haircrm/sdk.ts
import { createHinClient } from "@hin/haircrm-sdk";
const hin = createHinClient({
apiKey: process.env.HIN_API_KEY!,
partner: "haircrm",
});2. Single Sign-On
One identity. Users authenticate on Hair Industry Network. HairCRM consumes a short-lived hand-off token (TTL 30–600s, single-use, SHA-256 hashed at rest).
// 1. In Hair Industry Network — user clicks "Open HairCRM"
const { token } = await mintHairCrmSsoToken({ data: { redirect: "/dashboard" } });
window.location.href = `https://app.haircrm.in/sso?token=${token}`;
// 2. In HairCRM — exchange the token
const { data } = await hin.sso.consume(token);
// -> { userId: "...", metadata: { redirect: "/dashboard" } }3. Business Sync
Read-only, owner-scoped. HairCRM never writes to Hair Industry Network business records; it mirrors them.
await hin.sync.businessProfile();
await hin.sync.verification();
await hin.sync.products({ limit: 100 });
await hin.sync.services();
await hin.sync.media({ limit: 200 });
await hin.sync.reviews({ limit: 100 });4. AI Integration
HairCRM calls the AI Platform through the API. All calls are subscription-checked and rate-limited.
await hin.ai.search("premium wigs supplier Delhi");
await hin.ai.businessAssistant("Improve my studio profile");
await hin.ai.productAssistant("Suggest description for lace patch 8x10");
await hin.ai.analytics("lead.created", "30d");5. Notifications
Publishes to the Platform Notification Service. In-app writes directly; email/whatsapp/sms/push enqueue a background job.
await hin.notifications.publish({
channel: "in_app",
category: "business",
subject: "New lead assigned",
body: "Rahul Sharma — Delhi — hair patch enquiry",
});6. Analytics
HairCRM sends events to Enterprise BI via hin.analytics.event(). Events land in crm_event_ingest and are available to the owner analytics dashboard.
await hin.analytics.event({
event_type: "lead.created",
payload: { source: "walk-in", city: "Mumbai" },
});
await hin.analytics.summary();7. Search
Cross-module full-text search index shared with Hair Industry Network.
await hin.search.index({ entityType: "crm_customer", entityId: "c_1", title: "Rahul Sharma", body: "Delhi walk-in" });
await hin.search.query({ q: "delhi walk-in", limit: 10 });8. Media
Register media with the shared Media Platform; optimization runs in the background.
await hin.media.register({ kind: "image", url: "https://cdn.haircrm.in/x.jpg", mimeType: "image/jpeg" });9. Subscription Feature Gate
Never hardcode entitlements in HairCRM. Ask the platform:
const { data } = await hin.subscription.hasFeature("advanced_analytics");
if (!data.allowed) showUpgradePrompt(data.plan);10. Shared RBAC
Roles and permissions come from Hair Industry Network:
const { data } = await hin.permissions.me();
// { userId, roles: ["admin","studio_owner"], permissions: [...] }11. Shared Audit
Every consequential CRM action writes to the central audit trail.
await hin.audit.log({
category: "user",
action: "customer.updated",
entityType: "customer",
entityId: "cust_123",
meta: { field: "phone" },
});Rules of the road
- Never query the Hair Industry Network database directly.
- Send
X-Hin-Partner: haircrmon every request (SDK does this automatically). - Respect rate limits:
429withRetry-After: 60. - Feature-flag every new integration behind a subscription check.
- Audit-log every write.