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

@mv-service/cbm-addon-sdk

v1.0.1

Published

Client SDK für CBM-Addon-Entwickler — Bridge-Protokoll zwischen iframe-App und CBM-Shell

Readme

@mv-service/cbm-addon-sdk

Client SDK fuer CBM-Addon-Entwickler. Kapselt das Bridge-Protokoll (postMessage) zwischen einer iframe-basierten Addon-App und der CBM-Shell.

Installation

Das Paket wird öffentlich über die npm-Registry (npmjs.com) verteilt — keine Auth, kein Scope-Redirect nötig.

npm install @mv-service/cbm-addon-sdk
# oder
yarn add @mv-service/cbm-addon-sdk
# oder
pnpm add @mv-service/cbm-addon-sdk

Quickstart — Vanilla JS

<!DOCTYPE html>
<html>
<body>
  <div id="app">Verbinde mit CBM...</div>
  <script type="module">
    import { createCbmAddonClient } from '@mv-service/cbm-addon-sdk'

    const client = createCbmAddonClient()

    client.onInit((ctx) => {
      client.setTitle('Mein Addon')
      document.getElementById('app').textContent =
        `Hallo ${ctx.userDisplayName} (Tenant: ${ctx.tenantSlug})`

      // API-Call mit dem bereitgestellten JWT
      fetch(`${ctx.apiBaseUrl}/api/contracts`, {
        headers: { Authorization: `Bearer ${ctx.jwt}` },
      })
        .then((r) => r.json())
        .then((data) => console.log('Vertraege:', data))
    })

    client.onThemeChange(({ theme }) => {
      document.documentElement.dataset.theme = theme // 'light' | 'dark'
    })
  </script>
</body>
</html>

Quickstart — TypeScript

import { CbmAddonClient } from '@mv-service/cbm-addon-sdk'

const client = new CbmAddonClient({
  autoRefreshBufferSeconds: 120, // Token 2 min vor Ablauf erneuern
})

client
  .onInit(({ tenantId, userId, jwt, apiBaseUrl }) => {
    client.setTitle('Mein Addon')
    client.showToast('Addon geladen', 'success')

    // Im Framework-Lifecycle: client.destroy() aufrufen beim Unmount
  })
  .onThemeChange(({ theme, primaryColor }) => {
    document.documentElement.classList.toggle('dark', theme === 'dark')
  })
  .onTokenRefresh(({ jwt }) => {
    console.log('Neuer JWT:', jwt)
  })

// Spaeter:
// client.navigate('/customers/123')
// client.destroy()

API-Referenz

new CbmAddonClient(options?)

Erstellt die SDK-Instanz und sendet sofort CBM_READY an die CBM-Shell (Handshake-Start).

| Option | Typ | Default | Beschreibung | |--------|-----|---------|--------------| | version | string | "1.0" | Bridge-Protokollversion | | autoRefreshBufferSeconds | number | 120 | Sekunden vor JWT-Ablauf, bei denen automatisch ein Refresh angefordert wird. 0 deaktiviert Auto-Refresh. |

createCbmAddonClient(options?) — Factory-Funktion

Identisch zu new CbmAddonClient(options). Bequemer fuer Vanilla-JS-Addons ohne Klassen-Syntax.


Callbacks (chainable)

client.onInit(callback): this

Wird aufgerufen, sobald CBM_INIT von der Shell empfangen wird. Enthaelt den vollen Kontext-Payload.

Falls der Handshake bereits abgeschlossen ist (Late-Registration), wird der Callback sofort synchron aufgerufen.

interface CbmInitPayload {
  tenantId: string        // UUID des aktiven Tenants
  tenantSlug: string      // URL-Slug, z.B. "mv-service"
  userId: string          // UUID des eingeloggten Users
  userEmail: string
  userDisplayName: string
  jwt: string             // Kurzlebiger API-Token (15 min, addon-scoped)
  jwtExpiresAt: string    // ISO-8601-Ablaufzeit
  apiBaseUrl: string      // z.B. "https://cbm.example.com/api"
  addonId: string         // UUID der Addon-App
  locale: string          // Aktives Locale, z.B. "de"
}

client.onTokenRefresh(callback): this

Wird aufgerufen, wenn die Shell CBM_TOKEN_REFRESHED sendet (nach einem Refresh-Request).

client.onTokenRefresh(({ jwt, expiresAt }) => {
  myHttpClient.setAuthToken(jwt)
})

client.onThemeChange(callback): this

Wird aufgerufen, wenn der User das Theme in der CBM-Shell wechselt.

client.onThemeChange(({ theme, primaryColor }) => {
  // theme: 'light' | 'dark'
  // primaryColor?: string (CSS-Farbwert, optional)
})

Getter

| Getter | Typ | Beschreibung | |--------|-----|--------------| | client.isReady | boolean | true nach erstem CBM_INIT | | client.jwt | string \| null | Aktueller JWT (null vor CBM_INIT) | | client.apiBaseUrl | string \| null | API-Basis-URL (null vor CBM_INIT) | | client.getInitPayload() | CbmInitPayload \| null | Vollstaendiger Init-Payload |


Shell-Interaktion

client.requestTokenRefresh(): void

Fordert die Shell auf, den JWT zu erneuern. Wird normalerweise automatisch durch den Auto-Refresh-Timer aufgerufen.

client.navigate(path: string): void

Fordert die CBM-Shell auf, zu einem anderen Pfad zu navigieren.

client.navigate('/customers/123')

client.showToast(message, variant?): void

Zeigt eine Toast-Benachrichtigung in der CBM-Shell an.

client.showToast('Gespeichert!', 'success')  // 'success' | 'error' | 'info'

client.setTitle(title: string): void

Setzt den Seitentitel in der CBM-Shell-Kopfzeile.

client.setTitle('Asset-Verwaltung')

client.setLoading(loading: boolean): void

Zeigt oder versteckt einen Loading-Overlay in der CBM-Shell.

client.setLoading(true)
await doHeavyWork()
client.setLoading(false)

client.destroy(): void

Rauemt Event-Listener und Auto-Refresh-Timer auf. Muss im SPA-Teardown/onUnmount aufgerufen werden.

// React-Beispiel
useEffect(() => {
  const client = new CbmAddonClient()
  client.onInit(setup)
  return () => client.destroy()
}, [])

Sicherheitshinweise

  • Addons laufen in einem gesandboxten <iframe> (Sandboxattribute: allow-scripts allow-same-origin allow-forms allow-popups)
  • Der JWT ist auf die deklarierten RequiredScopes des Addons eingeschraenkt (15 min Laufzeit)
  • Nur registrierte IframeAllowedOrigins empfangen postMessages von der Shell
  • Das SDK sendet postMessage mit targetOrigin: '*' — die Herkunftspruefung liegt bei der Shell

Build (fuer Paket-Veroeffentlichung)

npm run build   # Erzeugt dist/index.js (ESM), dist/index.cjs (CJS), dist/index.d.ts
npm run dev     # Watch-Modus
npm run typecheck