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

@primocaredentgroup/convex-campaigns-component

v0.4.1

Published

Convex Campaigns backend component for PrimoCore

Downloads

544

Readme

PrimoCore Convex Campaigns Component

Pacchetto npm per distribuire il componente Convex campaigns di PrimoCore.

Contenuto

  • convex.config.ts: definizione componente Convex.
  • convex/components/campaigns/*: funzioni, schema, ports, domain.
  • convex/campaigns.ts: API pubblica stabile (campaigns.*).

Build del pacchetto

Dal root del monorepo:

cd packages/convex-campaigns-component
npm run sync:from-repo
npm pack

npm pack esegue anche prepack, quindi sincronizza automaticamente i file dal repo.

Pubblicazione su npmjs

cd packages/convex-campaigns-component
npm login
npm publish

Installazione su host PrimoCore

Nel repo host:

npm install @primocaredentgroup/convex-campaigns-component

Poi nel convex.config.ts dell'host installa il componente:

import { defineApp } from "convex/server";
import { campaignsComponent } from "@primocaredentgroup/convex-campaigns-component/convex.config";

const app = defineApp();
app.use(campaignsComponent, { name: "campaigns" });

export default app;

Infine esegui:

npx convex dev

Sviluppo standalone (npx convex dev)

Il componente ha il suo backend e può essere sviluppato in isolamento:

cd /path/to/campagne   # root del package (dove c'è package.json)
npx convex dev

La convex.config.ts esporta un'app che monta il componente, così convex dev funziona dalla root del package.

Note

  • Il componente espone logica backend Campaigns (no UI).
  • L'autorizzazione è server-side (assertAuthorized) e va collegata al provider auth del deployment host in produzione.
  • La port Consent resta stub fino a disponibilità del componente consensi ufficiale.

Compatibilità host e prerequisiti schema

  • Il componente definisce e usa indici Convex per le proprie tabelle (campaign_steps.by_campaign, campaign_steps.by_campaign_order, ecc.).
  • In caso di mismatch temporaneo tra codice e indici dopo deploy, le query principali usano fallback safe per evitare crash UI.
  • Per le tabelle host (users) il componente prova prima lookup indicizzato (by_auth0, by_email) e, se l'indice non è disponibile, applica fallback collect + find.

Compatibilità clinic IDs

  • scopeClinicIds accetta sia:
    • Convex IDs (v.id("clinics"))
    • stringhe clinicId
  • Strategia adottata: accettazione stringhe + normalizzazione interna (String(id)), per compatibilità cross-host senza patch nel node_modules host.

Comportamento auth fallback

  • Mapping identity robusto:
    • prova subject -> users.by_auth0
    • fallback email -> users.by_email
    • fallback finale collect + find se indici host non disponibili
  • Role matching case-insensitive (admin, Admin, ADMIN equivalenti).
  • Se identity esiste ma utente/ruoli non mappati:
    • default: errore controllato (CAMPAIGNS_AUTH_*)
    • opzionale dev-safe: impostare CAMPAIGNS_AUTH_MISSING_USER_MODE=allow

Embedding in PrimoUpCore

API pubbliche host-facing (production-ready)

Usare campaignsPublic o le funzioni esportate direttamente:

  • listActiveCampaignsForOrg – campagne ready per org, opzionale filter per clinicId
  • getLatestPublishedVersion – versione più recente pubblicata di una campagna
  • getPatientCampaignMemberships – memberships di un paziente, ordinate per priority
  • getAudiencePage – audience paginata (ordine deterministico)
  • recordContactAttempt – registra esito contatto
  • getFieldRegistry – registry campi per UI builder

Variabili d'ambiente

| Variabile | Valore | Default | Descrizione | |-----------|--------|---------|-------------| | CAMPAIGNS_USE_DEMO_DATASOURCE | "true" | "false" | true in dev, false in prod | Se false, usa solo core datasource (tabella patients). In prod impostare false per evitare uso di dati demo. |

Normalizzazione clinicId

Tutte le API pubbliche normalizzano clinicId al boundary: String(id) per compatibilità con Convex IDs e stringhe.

Checklist installazione in PrimoUpCore

  1. npm pack / publishnpm pack dal repo o npm publish su registry
  2. install su PrimoUpCorenpm install @primocaredentgroup/convex-campaigns-component
  3. set env varsCAMPAIGNS_USE_DEMO_DATASOURCE=false in produzione
  4. chiamare listActiveCampaignsForOrg – verifica integrazione da host
  5. verificare demo datasource disabilitato – in prod non deve usare tabelle demo

API v2 (rule engine + snapshot versionati)

API playground/dev (test, examples):

  • campaigns:seedDemoData
  • campaigns:upsertCampaign
  • campaigns:setCampaignLifecycleStatus
  • campaigns:listCampaignsV2
  • campaigns:getCampaignV2
  • campaigns:listCampaignVersions
  • campaigns:previewCampaignAudience
  • campaigns:publishCampaignVersion
  • campaigns:updateCampaignCallPolicy
  • campaigns:getCampaignCallPolicy

API pubbliche (vedi sopra): listActiveCampaignsForOrg, getLatestPublishedVersion, getPatientCampaignMemberships, getAudiencePage, recordContactAttempt, getFieldRegistry.

Il motore regole usa DSL JSON (AND/OR + condizioni atomiche) validata con zod.

Playground React

Esempio frontend standalone disponibile in:

  • examples/campaigns-playground

Vedi guida completa:

  • examples/campaigns-playground/README.md

Smoke test

Script per verificare le API in sequenza. Esegui dalla root del componente (dove si trova package.json):

cd /path/to/campagne   # repo del componente campaigns
npm run smoke

L'URL Convex viene letto da .env.local (creato da npx convex dev) o da variabili d'ambiente:

CONVEX_URL=https://tuo-deployment.convex.cloud npm run smoke

Variabili: SMOKE_ORG_ID, SMOKE_CLINIC_IDS, SMOKE_SKIP_SEED=1 per saltare seed.