@hyperse-hub/hps-plugin-hub
Vendure plugin for private npm-style license packages: persist licenses per customer and product, expose admin CRUD, a shop-facing list without license keys, and a REST license check that accepts an encrypted payload.
Requirements
- Node.js ≥ 20
- Vendure ^3.5 (plugin declares compatibility
>=3.0.0)
- Peer deps align with
@vendure/core, NestJS GraphQL, TypeORM (see package.json)
Install
yarn add @hyperse-hub/hps-plugin-hub
Register in VendureConfig
cipherKey must be exactly 64 hexadecimal characters (32 random bytes). Use the same key anywhere you encrypt payloads for POST /license/check (see @hyperse-hub/hps-common).
import type { VendureConfig } from '@vendure/core';
import { HpsPluginHub } from '@hyperse-hub/hps-plugin-hub';
import { randomBytes } from 'node:crypto';
export const config: VendureConfig = {
plugins: [
HpsPluginHub.init({
cipherKey: randomBytes(32).toString('hex'),
}),
],
};
Configuration
| Option | Required | Description |
|---|
cipherKey | Yes | 64-char hex string (randomBytes(32).toString('hex')). Invalid values throw at init(). |
Local dev server
This package includes yarn serve, which loads config/.env when present. You can set:
HUB_LICENSE_CIPHER_KEY — 64 hex chars; otherwise config/dev-server.ts uses a fixed fallback key (development only).
Data model: HubLicensePackage
Stored as table hub_license_package with a unique (customerId, packageName) pair.
| Field | Notes |
|---|
packageName | Package name as in the registry (e.g. Verdaccio scope). |
licenseKey | Secret; not exposed on Shop API types. |
accessibleEndsAt | Optional end of access; null treated as no end date. |
customer / product | Vendure relations. |
Permissions (Admin API)
The plugin registers hubPermission (CrudPermissionDefinition('HpsPluginHub')). Assign on administrator roles:
CreateHpsPluginHub, ReadHpsPluginHub, UpdateHpsPluginHub, DeleteHpsPluginHub
Admin queries and mutations are gated by these permissions.
Admin GraphQL (summary)
- Queries:
hubLicensePackages, hubLicensePackage(id)
- Mutations:
createHubLicensePackage, updateHubLicensePackage, deleteHubLicensePackage
CreateHubLicensePackageInput / UpdateHubLicensePackageInput include packageName, optional licenseKey, optional accessibleEndsAt, customerId, productId (see schema in src/api/).
Shop API
All shop responses use HubLicensePackageShop, which omits licenseKey. Distribute keys only via Admin API or other secure channels.
hubLicenses — Paginated licenses for the authenticated customer.
Customer.activeLicenses — Count of licenses that pass the same validity rules as server-side checks (including accessibleEndsAt when set).
Customer.nextRenewals — Licenses that are already expired (accessibleEndsAt before now) and are candidates for renewal.
Example shape:
query ShopHubLicenses {
hubLicenses {
items {
id
packageName
accessibleEndsAt
product {
id
name
}
}
totalItems
}
}
REST: POST /license/check
Body:
{
"data": "<encrypted string>"
}
After decryption, the payload must be JSON with licenseKey and packageName (both strings). Encryption must use the plugin’s cipherKey via @hyperse-hub/hps-common (encrypt / decrypt).
Responses (JSON):
- Success path:
{ "valid": true, "message": "License key is valid" }
- Invalid / missing / expired:
{ "valid": false, "message": "<reason>" }
- Malformed body or crypto: 400 with a generic bad-request message.
Typical reasons for valid: false: unknown key, or license expired per accessibleEndsAt.
Events
HubLicensePackageEvent is emitted when a HubLicensePackage is created, updated, or deleted (see src/events/).
Package exports
The public entry re-exports the plugin, hubPermission, services, types, and events (src/index.ts). Use these for custom integrations or tests.
Scripts (monorepo / package)
| Script | Purpose |
|---|
yarn build | Compile to dist/ |
yarn serve | Dev Vendure with this plugin |
yarn test | Unit + e2e (Vitest) |
yarn codegen | GraphQL codegen (admin/shop) |
In this monorepo, hub tooling may also use @hyperse-hub/hps-plugin-hub-client and @hyperse-hub/hps-plugin-hub-verdaccio for registry-side flows; see their READMEs for wiring details.