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

@vyhoang/gateway-registration-sdk

v0.1.2

Published

Shared contracts and service-side SDK for runtime gateway route registration.

Readme

@vyhoang/gateway-registration-sdk

Gateway Registration SDK

Package dùng chung để các service đăng ký route runtime với gateway.

Package này gồm 2 phần:

  • contracts: kiểu dữ liệu route metadata, policy, pipeline, validation schema
  • sdk: helper/service SDK để publish và re-publish routes lên gateway

Mục tiêu là để nhiều service như NestJS, Moleculer hoặc service dùng NATS thuần có thể dùng chung một chuẩn metadata, thay vì mỗi service tự định nghĩa type và subject riêng.


Package này giải quyết bài toán gì?

Khi gateway đi theo hướng runtime route registration:

  1. Service boot lên
  2. Service publish danh sách route metadata qua message bus
  3. Gateway nhận metadata và nạp vào runtime registry
  4. Gateway có thể yêu cầu các service re-sync route khi vừa khởi động hoặc khi cần đồng bộ lại

Package này chuẩn hóa đúng flow đó.


Phạm vi

Package này chỉ nên chứa:

  • contract dùng chung giữa gateway và service
  • constants cho subject/event
  • helper để định nghĩa route metadata
  • service-side SDK để publish route metadata

Package này không nên chứa:

  • RouteRegistry của gateway
  • GatewayPipeline
  • auth/security step
  • transport adapter runtime của gateway
  • business logic của từng service

Export chính

Contracts

  • RouteDefinition
  • RouteRegistrationPayload
  • ActionPolicy
  • ActionPipelineConfig
  • RouteValidationConfig
  • JsonSchemaLike

Constants

  • GATEWAY_REGISTER_SUBJECT
  • GATEWAY_ROUTE_SYNC_REQUEST_SUBJECT

Helpers

  • defineRoute(...)
  • defineRoutes(...)

SDK

  • GatewayRoutePublisher
  • createGatewayRoutePublisher(...)
  • isGatewayRouteSyncRequestSubject(...)

Cài đặt

npm install @vyhoang/gateway-registration-sdk

Ví dụ route metadata

import { defineRoutes } from '@vyhoang/gateway-registration-sdk';

export const PRODUCT_ROUTES = defineRoutes([
  {
    method: 'POST',
    path: '/product',
    action: 'product.create',
    service: 'product',
    transport: 'nats',
    pattern: 'product.create',
    policy: {
      clientPermissions: ['product-write'],
      requiredScopes: ['product.write'],
      rateLimit: 20,
      audit: true,
      requireUser: true,
      authCacheSeconds: 60,
    },
    validation: {
      body: {
        type: 'object',
        required: ['name'],
        properties: {
          name: { type: 'string', minLength: 1 },
        },
      },
    },
  },
]);

Ví dụ dùng SDK trong service

SDK này không phụ thuộc framework. Chỉ cần truyền vào một object có hàm emit(subject, payload).

import {
  createGatewayRoutePublisher,
  defineRoutes,
} from '@vyhoang/gateway-registration-sdk';

const routes = defineRoutes([
  {
    method: 'POST',
    path: '/product',
    action: 'product.create',
    service: 'product',
    transport: 'nats',
    pattern: 'product.create',
  },
]);

const publisher = createGatewayRoutePublisher({
  source: 'product-service',
  routes,
  client: {
    emit: (subject, payload) => natsClient.emit(subject, payload),
  },
  logger: console,
});

await publisher.publishRoutes();

Re-sync routes

Khi gateway gửi subject gateway.routes.sync.request, service có thể gọi lại publishRoutes() để đăng ký lại toàn bộ route hiện tại.

Ví dụ:

await publisher.handleSyncRequest();

Hoặc nếu bạn đang tự subscribe event:

if (isGatewayRouteSyncRequestSubject(subject)) {
  await publisher.publishRoutes();
}

Gợi ý tích hợp

Với NestJS service

  • tạo file *.route.metadata.ts
  • tạo publisher trong onModuleInit()
  • khi nhận sync request thì gọi lại publishRoutes()

Với Moleculer service

  • giữ metadata ở tầng infrastructure
  • khởi tạo publisher trong started()
  • đóng publisher trong stopped() nếu cần
  • khi nhận sync request thì publish lại route

English

Shared package for runtime route registration between services and the gateway.

This package includes two main parts:

  • contracts: route metadata, policy, pipeline, and validation schema types
  • sdk: helper/service SDK to publish and re-publish routes to the gateway

The goal is to let multiple services such as NestJS, Moleculer, or plain NATS-based services share one metadata contract instead of redefining types and subjects in each service.

What problem does this package solve?

When the gateway follows a runtime route registration model:

  1. A service starts
  2. The service publishes its route metadata through a message bus
  3. The gateway receives that metadata and loads it into the runtime registry
  4. The gateway can request services to re-sync routes after startup or when reloading state

This package standardizes that flow.

Scope

This package should contain only:

  • shared contracts between gateway and services
  • constants for subjects/events
  • helpers to define route metadata
  • a service-side SDK to publish route metadata

This package should not contain:

  • gateway RouteRegistry
  • GatewayPipeline
  • auth/security steps
  • gateway runtime transport adapters
  • business logic from individual services

Main exports

Contracts

  • RouteDefinition
  • RouteRegistrationPayload
  • ActionPolicy
  • ActionPipelineConfig
  • RouteValidationConfig
  • JsonSchemaLike

Constants

  • GATEWAY_REGISTER_SUBJECT
  • GATEWAY_ROUTE_SYNC_REQUEST_SUBJECT

Helpers

  • defineRoute(...)
  • defineRoutes(...)

SDK

  • GatewayRoutePublisher
  • createGatewayRoutePublisher(...)
  • isGatewayRouteSyncRequestSubject(...)

Installation

npm install @vyhoang/gateway-registration-sdk

Example route metadata

import { defineRoutes } from '@vyhoang/gateway-registration-sdk';

export const PRODUCT_ROUTES = defineRoutes([
  {
    method: 'POST',
    path: '/product',
    action: 'product.create',
    service: 'product',
    transport: 'nats',
    pattern: 'product.create',
    policy: {
      clientPermissions: ['product-write'],
      requiredScopes: ['product.write'],
      rateLimit: 20,
      audit: true,
      requireUser: true,
      authCacheSeconds: 60,
    },
    validation: {
      body: {
        type: 'object',
        required: ['name'],
        properties: {
          name: { type: 'string', minLength: 1 },
        },
      },
    },
  },
]);

Example SDK usage in a service

The SDK is framework agnostic. You only need to provide an object with an emit(subject, payload) function.

import {
  createGatewayRoutePublisher,
  defineRoutes,
} from '@vyhoang/gateway-registration-sdk';

const routes = defineRoutes([
  {
    method: 'POST',
    path: '/product',
    action: 'product.create',
    service: 'product',
    transport: 'nats',
    pattern: 'product.create',
  },
]);

const publisher = createGatewayRoutePublisher({
  source: 'product-service',
  routes,
  client: {
    emit: (subject, payload) => natsClient.emit(subject, payload),
  },
  logger: console,
});

await publisher.publishRoutes();

Route re-sync

When the gateway emits the gateway.routes.sync.request subject, a service can call publishRoutes() again to re-register its full route set.

Example:

await publisher.handleSyncRequest();

Or when you already subscribe to events yourself:

if (isGatewayRouteSyncRequestSubject(subject)) {
  await publisher.publishRoutes();
}

Integration notes

For NestJS services

  • create a *.route.metadata.ts file
  • create the publisher in onModuleInit()
  • call publishRoutes() again when a sync request arrives

For Moleculer services

  • keep metadata in the infrastructure layer
  • initialize the publisher in started()
  • close publisher resources in stopped() if needed
  • re-publish routes when a sync request arrives