@ops-ai/toggly-hono 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -123,7 +123,13 @@ function togglyMiddleware(config) {
123
123
  context: evalContext,
124
124
  isFeatureOn: (featureKey) => honoClient.isFeatureOn(featureKey, evalContext),
125
125
  isFeatureOff: (featureKey) => honoClient.isFeatureOff(featureKey, evalContext),
126
- evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext)
126
+ evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),
127
+ getVariant(featureKey) {
128
+ return honoClient.getVariant(featureKey, evalContext);
129
+ },
130
+ getVariantValue(featureKey) {
131
+ return honoClient.getVariantValue(featureKey, evalContext);
132
+ }
127
133
  });
128
134
  await next();
129
135
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/middleware.ts"],"sourcesContent":["// Middleware\nexport {\n togglyMiddleware,\n featureGate,\n featureRoutes,\n withFeature,\n featuresHandler,\n getHonoToggly,\n closeHonoToggly,\n} from './middleware.js'\n\n// Types\nexport type {\n TogglyHonoConfig,\n TogglyContextData,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Re-export core types for convenience\nexport type {\n TogglyClient,\n TogglyConfig,\n TogglyServerConfig,\n TogglyState,\n FeatureDefinitions,\n FeatureRequirement,\n EvaluationContext,\n Hook,\n HookMetadata,\n} from '@ops-ai/toggly-node-core'\n\n// Re-export core utilities\nexport {\n createTogglyClient,\n initToggly,\n getToggly,\n useToggly,\n closeToggly,\n createLoggingHook,\n createMemoryCache,\n createFileCache,\n} from '@ops-ai/toggly-node-core'\n","import type { Context, MiddlewareHandler, Handler } from 'hono'\nimport {\n createTogglyClient,\n normalizeFeatureKeys,\n fromHttpRequest,\n type TogglyClient,\n type EvaluationContext,\n} from '@ops-ai/toggly-node-core'\nimport type {\n TogglyHonoConfig,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Module-level client singleton\nlet honoClient: TogglyClient | null = null\n\n/**\n * Get the Hono Toggly client\n */\nexport function getHonoToggly(): TogglyClient | null {\n return honoClient\n}\n\n/**\n * Get identity from Hono context\n */\nasync function extractIdentity(\n c: Context,\n config: TogglyHonoConfig\n): Promise<string | undefined> {\n // Use custom extractor if provided\n if (config.getIdentity) {\n return config.getIdentity(c)\n }\n\n // Default: check header\n const headerIdentity = c.req.header('x-toggly-identity')\n if (headerIdentity) {\n return headerIdentity\n }\n\n return undefined\n}\n\n/**\n * Collect segment-relevant headers from a Hono request\n */\nfunction segmentHeaders(c: Context): Record<string, string | undefined> {\n const headerBag: Record<string, string | undefined> = {}\n for (const name of [\n 'user-agent',\n 'accept-language',\n 'cf-ipcountry',\n 'x-vercel-ip-country',\n 'cloudfront-viewer-country',\n ]) {\n headerBag[name] = c.req.header(name)\n }\n return headerBag\n}\n\n/**\n * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n const headerBag = segmentHeaders(c)\n const headerRequest = fromHttpRequest(headerBag).request\n\n // Custom full context: use returned fields, fill missing request from headers\n if (config.getContext) {\n const custom = await config.getContext(c)\n return {\n ...custom,\n // Field-level merge: custom wins; missing keys filled from headers\n request: {\n ...headerRequest,\n ...custom.request,\n },\n }\n }\n\n // Default: identity / groups / claims providers + segment request headers\n const identity = await extractIdentity(c, config)\n const groups = config.getGroups ? await config.getGroups(c) : undefined\n const claims = config.getClaims ? await config.getClaims(c) : undefined\n const fromReq = fromHttpRequest(headerBag, { identity, groups, claims })\n\n return {\n identity: fromReq.identity,\n groups: fromReq.groups,\n claims: fromReq.claims,\n request: fromReq.request,\n traits: {\n ip: c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n userAgent: c.req.header('user-agent'),\n path: c.req.path,\n method: c.req.method,\n },\n }\n}\n\n/**\n * Create Toggly middleware for Hono\n *\n * This middleware:\n * 1. Initializes the Toggly client (if not already initialized)\n * 2. Attaches feature flag helpers to the context\n * 3. Extracts identity and context from the request\n */\nexport function togglyMiddleware(config: TogglyHonoConfig): MiddlewareHandler {\n // Initialize client lazily\n let initPromise: Promise<void> | null = null\n\n const initialize = async () => {\n if (!honoClient) {\n honoClient = createTogglyClient(config)\n await honoClient.init()\n }\n }\n\n return async (c: Context, next) => {\n // Ensure client is initialized\n if (!initPromise) {\n initPromise = initialize()\n }\n await initPromise\n\n if (!honoClient) {\n throw new Error('Toggly client failed to initialize')\n }\n\n // Extract context from request\n const evalContext = await extractContext(c, config)\n const identity = evalContext.identity\n\n // Attach Toggly helpers to Hono context\n c.set('toggly', {\n client: honoClient,\n features: honoClient.state.features,\n identity,\n context: evalContext,\n isFeatureOn: (featureKey: string) => honoClient!.isFeatureOn(featureKey, evalContext),\n isFeatureOff: (featureKey: string) => honoClient!.isFeatureOff(featureKey, evalContext),\n evaluateFeatureGate: (featureKeys, requirement, negate) =>\n honoClient!.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),\n })\n\n await next()\n }\n}\n\n/**\n * Create a feature gate middleware\n *\n * Protects routes by checking if specified features are enabled\n */\nexport function featureGate(options: FeatureGateOptions): MiddlewareHandler {\n const {\n featureKey,\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before featureGate')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n await next()\n return\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Create middleware that applies feature gates based on route patterns\n */\nexport function featureRoutes(routes: FeatureRouteOptions[]): MiddlewareHandler {\n return async (c: Context, next) => {\n for (const route of routes) {\n // Check if route matches\n const pathMatches =\n typeof route.path === 'string'\n ? c.req.path === route.path || c.req.path.startsWith(route.path)\n : route.path.test(c.req.path)\n\n if (!pathMatches) {\n continue\n }\n\n // Check if method matches\n if (route.methods && !route.methods.includes(c.req.method.toUpperCase())) {\n continue\n }\n\n // Apply feature gate\n const gate = featureGate(route)\n return gate(c, next)\n }\n\n // No matching route, continue\n await next()\n }\n}\n\n/**\n * Create a route handler that only executes if feature is enabled\n */\nexport function withFeature(\n featureKey: string | string[],\n handler: Handler,\n options: Omit<FeatureGateOptions, 'featureKey'> = {}\n): MiddlewareHandler {\n const {\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before withFeature')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n // Execute the handler\n return handler(c, next)\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Get features handler for Hono\n */\nexport const featuresHandler: Handler = async (c: Context) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n return c.json(\n {\n error: 'Internal Server Error',\n message: 'Toggly middleware not configured',\n },\n 500\n )\n }\n\n return c.json({\n features: toggly.features,\n identity: toggly.identity,\n })\n}\n\n/**\n * Close the Hono Toggly client\n */\nexport function closeHonoToggly(): void {\n if (honoClient) {\n honoClient.close()\n honoClient = null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X,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,UAAM,YAAY,MAAM,OAAO,oBAAoB,aAAa,aAAa,MAAM;AAEnF,QAAI,WAAW;AAEb,aAAO,QAAQ,GAAG,IAAI;AAAA,IACxB;AAGA,QAAI,YAAY;AACd,aAAO,EAAE,SAAS,YAAY,cAAc;AAAA,IAC9C;AAEA,QAAI,YAAY;AACd,aAAO,WAAW,CAAC;AAAA,IACrB;AAGA,WAAO,EAAE;AAAA,MACP;AAAA,QACE,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAKO,IAAM,kBAA2B,OAAO,MAAe;AAC5D,QAAM,SAAS,EAAE,IAAI,QAAQ;AAE7B,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE;AAAA,MACP;AAAA,QACE,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,KAAK;AAAA,IACZ,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB,CAAC;AACH;AAKO,SAAS,kBAAwB;AACtC,MAAI,YAAY;AACd,eAAW,MAAM;AACjB,iBAAa;AAAA,EACf;AACF;;;AD9RA,IAAAA,2BASO;","names":["import_toggly_node_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/middleware.ts"],"sourcesContent":["// Middleware\nexport {\n togglyMiddleware,\n featureGate,\n featureRoutes,\n withFeature,\n featuresHandler,\n getHonoToggly,\n closeHonoToggly,\n} from './middleware.js'\n\n// Types\nexport type {\n TogglyHonoConfig,\n TogglyContextData,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Re-export core types for convenience\nexport type {\n TogglyClient,\n TogglyConfig,\n TogglyServerConfig,\n TogglyState,\n FeatureDefinitions,\n FeatureRequirement,\n EvaluationContext,\n Hook,\n HookMetadata,\n VariantResult,\n} from '@ops-ai/toggly-node-core'\n\n// Re-export core utilities\nexport {\n createTogglyClient,\n initToggly,\n getToggly,\n useToggly,\n closeToggly,\n createLoggingHook,\n createMemoryCache,\n createFileCache,\n} from '@ops-ai/toggly-node-core'\n","import type { Context, MiddlewareHandler, Handler } from 'hono'\nimport {\n createTogglyClient,\n normalizeFeatureKeys,\n fromHttpRequest,\n type TogglyClient,\n type EvaluationContext,\n} from '@ops-ai/toggly-node-core'\nimport type {\n TogglyHonoConfig,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Module-level client singleton\nlet honoClient: TogglyClient | null = null\n\n/**\n * Get the Hono Toggly client\n */\nexport function getHonoToggly(): TogglyClient | null {\n return honoClient\n}\n\n/**\n * Get identity from Hono context\n */\nasync function extractIdentity(\n c: Context,\n config: TogglyHonoConfig\n): Promise<string | undefined> {\n // Use custom extractor if provided\n if (config.getIdentity) {\n return config.getIdentity(c)\n }\n\n // Default: check header\n const headerIdentity = c.req.header('x-toggly-identity')\n if (headerIdentity) {\n return headerIdentity\n }\n\n return undefined\n}\n\n/**\n * Collect segment-relevant headers from a Hono request\n */\nfunction segmentHeaders(c: Context): Record<string, string | undefined> {\n const headerBag: Record<string, string | undefined> = {}\n for (const name of [\n 'user-agent',\n 'accept-language',\n 'cf-ipcountry',\n 'x-vercel-ip-country',\n 'cloudfront-viewer-country',\n ]) {\n headerBag[name] = c.req.header(name)\n }\n return headerBag\n}\n\n/**\n * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n const headerBag = segmentHeaders(c)\n const headerRequest = fromHttpRequest(headerBag).request\n\n // Custom full context: use returned fields, fill missing request from headers\n if (config.getContext) {\n const custom = await config.getContext(c)\n return {\n ...custom,\n // Field-level merge: custom wins; missing keys filled from headers\n request: {\n ...headerRequest,\n ...custom.request,\n },\n }\n }\n\n // Default: identity / groups / claims providers + segment request headers\n const identity = await extractIdentity(c, config)\n const groups = config.getGroups ? await config.getGroups(c) : undefined\n const claims = config.getClaims ? await config.getClaims(c) : undefined\n const fromReq = fromHttpRequest(headerBag, { identity, groups, claims })\n\n return {\n identity: fromReq.identity,\n groups: fromReq.groups,\n claims: fromReq.claims,\n request: fromReq.request,\n traits: {\n ip: c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n userAgent: c.req.header('user-agent'),\n path: c.req.path,\n method: c.req.method,\n },\n }\n}\n\n/**\n * Create Toggly middleware for Hono\n *\n * This middleware:\n * 1. Initializes the Toggly client (if not already initialized)\n * 2. Attaches feature flag helpers to the context\n * 3. Extracts identity and context from the request\n */\nexport function togglyMiddleware(config: TogglyHonoConfig): MiddlewareHandler {\n // Initialize client lazily\n let initPromise: Promise<void> | null = null\n\n const initialize = async () => {\n if (!honoClient) {\n honoClient = createTogglyClient(config)\n await honoClient.init()\n }\n }\n\n return async (c: Context, next) => {\n // Ensure client is initialized\n if (!initPromise) {\n initPromise = initialize()\n }\n await initPromise\n\n if (!honoClient) {\n throw new Error('Toggly client failed to initialize')\n }\n\n // Extract context from request\n const evalContext = await extractContext(c, config)\n const identity = evalContext.identity\n\n // Attach Toggly helpers to Hono context\n c.set('toggly', {\n client: honoClient,\n features: honoClient.state.features,\n identity,\n context: evalContext,\n isFeatureOn: (featureKey: string) => honoClient!.isFeatureOn(featureKey, evalContext),\n isFeatureOff: (featureKey: string) => honoClient!.isFeatureOff(featureKey, evalContext),\n evaluateFeatureGate: (featureKeys, requirement, negate) =>\n honoClient!.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),\n getVariant(featureKey: string) {\n return honoClient!.getVariant(featureKey, evalContext)\n },\n getVariantValue(featureKey: string) {\n return honoClient!.getVariantValue(featureKey, evalContext)\n },\n })\n\n await next()\n }\n}\n\n/**\n * Create a feature gate middleware\n *\n * Protects routes by checking if specified features are enabled\n */\nexport function featureGate(options: FeatureGateOptions): MiddlewareHandler {\n const {\n featureKey,\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before featureGate')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n await next()\n return\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Create middleware that applies feature gates based on route patterns\n */\nexport function featureRoutes(routes: FeatureRouteOptions[]): MiddlewareHandler {\n return async (c: Context, next) => {\n for (const route of routes) {\n // Check if route matches\n const pathMatches =\n typeof route.path === 'string'\n ? c.req.path === route.path || c.req.path.startsWith(route.path)\n : route.path.test(c.req.path)\n\n if (!pathMatches) {\n continue\n }\n\n // Check if method matches\n if (route.methods && !route.methods.includes(c.req.method.toUpperCase())) {\n continue\n }\n\n // Apply feature gate\n const gate = featureGate(route)\n return gate(c, next)\n }\n\n // No matching route, continue\n await next()\n }\n}\n\n/**\n * Create a route handler that only executes if feature is enabled\n */\nexport function withFeature(\n featureKey: string | string[],\n handler: Handler,\n options: Omit<FeatureGateOptions, 'featureKey'> = {}\n): MiddlewareHandler {\n const {\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before withFeature')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n // Execute the handler\n return handler(c, next)\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Get features handler for Hono\n */\nexport const featuresHandler: Handler = async (c: Context) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n return c.json(\n {\n error: 'Internal Server Error',\n message: 'Toggly middleware not configured',\n },\n 500\n )\n }\n\n return c.json({\n features: toggly.features,\n identity: toggly.identity,\n })\n}\n\n/**\n * Close the Hono Toggly client\n */\nexport function closeHonoToggly(): void {\n if (honoClient) {\n honoClient.close()\n honoClient = null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,8BAMO;AAQP,IAAI,aAAkC;AAK/B,SAAS,gBAAqC;AACnD,SAAO;AACT;AAKA,eAAe,gBACb,GACA,QAC6B;AAE7B,MAAI,OAAO,aAAa;AACtB,WAAO,OAAO,YAAY,CAAC;AAAA,EAC7B;AAGA,QAAM,iBAAiB,EAAE,IAAI,OAAO,mBAAmB;AACvD,MAAI,gBAAgB;AAClB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKA,SAAS,eAAe,GAAgD;AACtE,QAAM,YAAgD,CAAC;AACvD,aAAW,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAG;AACD,cAAU,IAAI,IAAI,EAAE,IAAI,OAAO,IAAI;AAAA,EACrC;AACA,SAAO;AACT;AAKA,eAAe,eACb,GACA,QAC4B;AAC5B,QAAM,YAAY,eAAe,CAAC;AAClC,QAAM,oBAAgB,yCAAgB,SAAS,EAAE;AAGjD,MAAI,OAAO,YAAY;AACrB,UAAM,SAAS,MAAM,OAAO,WAAW,CAAC;AACxC,WAAO;AAAA,MACL,GAAG;AAAA;AAAA,MAEH,SAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,OAAO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A,EACf;AACF;;;ADnSA,IAAAA,2BASO;","names":["import_toggly_node_core"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, MiddlewareHandler, Handler } from 'hono';
2
- import { TogglyClient, FeatureDefinitions, EvaluationContext, FeatureRequirement, TogglyServerConfig } from '@ops-ai/toggly-node-core';
3
- export { EvaluationContext, FeatureDefinitions, FeatureRequirement, Hook, HookMetadata, TogglyClient, TogglyConfig, TogglyServerConfig, TogglyState, closeToggly, createFileCache, createLoggingHook, createMemoryCache, createTogglyClient, getToggly, initToggly, useToggly } from '@ops-ai/toggly-node-core';
2
+ import { TogglyClient, FeatureDefinitions, EvaluationContext, FeatureRequirement, VariantResult, TogglyServerConfig } from '@ops-ai/toggly-node-core';
3
+ export { EvaluationContext, FeatureDefinitions, FeatureRequirement, Hook, HookMetadata, TogglyClient, TogglyConfig, TogglyServerConfig, TogglyState, VariantResult, closeToggly, createFileCache, createLoggingHook, createMemoryCache, createTogglyClient, getToggly, initToggly, useToggly } from '@ops-ai/toggly-node-core';
4
4
 
5
5
  /**
6
6
  * Hono-specific configuration
@@ -37,6 +37,10 @@ interface TogglyContextData {
37
37
  isFeatureOn: (featureKey: string) => Promise<boolean>;
38
38
  isFeatureOff: (featureKey: string) => Promise<boolean>;
39
39
  evaluateFeatureGate: (featureKeys: string[], requirement?: FeatureRequirement, negate?: boolean) => Promise<boolean>;
40
+ /** Hono: catalog-local variant from context variables. */
41
+ getVariant(feature: string): Promise<VariantResult | null>;
42
+ /** Hono: assigned variant configurationValue, or null. */
43
+ getVariantValue(feature: string): Promise<unknown>;
40
44
  }
41
45
  /**
42
46
  * Feature gate options for protecting routes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, MiddlewareHandler, Handler } from 'hono';
2
- import { TogglyClient, FeatureDefinitions, EvaluationContext, FeatureRequirement, TogglyServerConfig } from '@ops-ai/toggly-node-core';
3
- export { EvaluationContext, FeatureDefinitions, FeatureRequirement, Hook, HookMetadata, TogglyClient, TogglyConfig, TogglyServerConfig, TogglyState, closeToggly, createFileCache, createLoggingHook, createMemoryCache, createTogglyClient, getToggly, initToggly, useToggly } from '@ops-ai/toggly-node-core';
2
+ import { TogglyClient, FeatureDefinitions, EvaluationContext, FeatureRequirement, VariantResult, TogglyServerConfig } from '@ops-ai/toggly-node-core';
3
+ export { EvaluationContext, FeatureDefinitions, FeatureRequirement, Hook, HookMetadata, TogglyClient, TogglyConfig, TogglyServerConfig, TogglyState, VariantResult, closeToggly, createFileCache, createLoggingHook, createMemoryCache, createTogglyClient, getToggly, initToggly, useToggly } from '@ops-ai/toggly-node-core';
4
4
 
5
5
  /**
6
6
  * Hono-specific configuration
@@ -37,6 +37,10 @@ interface TogglyContextData {
37
37
  isFeatureOn: (featureKey: string) => Promise<boolean>;
38
38
  isFeatureOff: (featureKey: string) => Promise<boolean>;
39
39
  evaluateFeatureGate: (featureKeys: string[], requirement?: FeatureRequirement, negate?: boolean) => Promise<boolean>;
40
+ /** Hono: catalog-local variant from context variables. */
41
+ getVariant(feature: string): Promise<VariantResult | null>;
42
+ /** Hono: assigned variant configurationValue, or null. */
43
+ getVariantValue(feature: string): Promise<unknown>;
40
44
  }
41
45
  /**
42
46
  * Feature gate options for protecting routes
package/dist/index.js CHANGED
@@ -87,7 +87,13 @@ function togglyMiddleware(config) {
87
87
  context: evalContext,
88
88
  isFeatureOn: (featureKey) => honoClient.isFeatureOn(featureKey, evalContext),
89
89
  isFeatureOff: (featureKey) => honoClient.isFeatureOff(featureKey, evalContext),
90
- evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext)
90
+ evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),
91
+ getVariant(featureKey) {
92
+ return honoClient.getVariant(featureKey, evalContext);
93
+ },
94
+ getVariantValue(featureKey) {
95
+ return honoClient.getVariantValue(featureKey, evalContext);
96
+ }
91
97
  });
92
98
  await next();
93
99
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/middleware.ts","../src/index.ts"],"sourcesContent":["import type { Context, MiddlewareHandler, Handler } from 'hono'\nimport {\n createTogglyClient,\n normalizeFeatureKeys,\n fromHttpRequest,\n type TogglyClient,\n type EvaluationContext,\n} from '@ops-ai/toggly-node-core'\nimport type {\n TogglyHonoConfig,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Module-level client singleton\nlet honoClient: TogglyClient | null = null\n\n/**\n * Get the Hono Toggly client\n */\nexport function getHonoToggly(): TogglyClient | null {\n return honoClient\n}\n\n/**\n * Get identity from Hono context\n */\nasync function extractIdentity(\n c: Context,\n config: TogglyHonoConfig\n): Promise<string | undefined> {\n // Use custom extractor if provided\n if (config.getIdentity) {\n return config.getIdentity(c)\n }\n\n // Default: check header\n const headerIdentity = c.req.header('x-toggly-identity')\n if (headerIdentity) {\n return headerIdentity\n }\n\n return undefined\n}\n\n/**\n * Collect segment-relevant headers from a Hono request\n */\nfunction segmentHeaders(c: Context): Record<string, string | undefined> {\n const headerBag: Record<string, string | undefined> = {}\n for (const name of [\n 'user-agent',\n 'accept-language',\n 'cf-ipcountry',\n 'x-vercel-ip-country',\n 'cloudfront-viewer-country',\n ]) {\n headerBag[name] = c.req.header(name)\n }\n return headerBag\n}\n\n/**\n * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n const headerBag = segmentHeaders(c)\n const headerRequest = fromHttpRequest(headerBag).request\n\n // Custom full context: use returned fields, fill missing request from headers\n if (config.getContext) {\n const custom = await config.getContext(c)\n return {\n ...custom,\n // Field-level merge: custom wins; missing keys filled from headers\n request: {\n ...headerRequest,\n ...custom.request,\n },\n }\n }\n\n // Default: identity / groups / claims providers + segment request headers\n const identity = await extractIdentity(c, config)\n const groups = config.getGroups ? await config.getGroups(c) : undefined\n const claims = config.getClaims ? await config.getClaims(c) : undefined\n const fromReq = fromHttpRequest(headerBag, { identity, groups, claims })\n\n return {\n identity: fromReq.identity,\n groups: fromReq.groups,\n claims: fromReq.claims,\n request: fromReq.request,\n traits: {\n ip: c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n userAgent: c.req.header('user-agent'),\n path: c.req.path,\n method: c.req.method,\n },\n }\n}\n\n/**\n * Create Toggly middleware for Hono\n *\n * This middleware:\n * 1. Initializes the Toggly client (if not already initialized)\n * 2. Attaches feature flag helpers to the context\n * 3. Extracts identity and context from the request\n */\nexport function togglyMiddleware(config: TogglyHonoConfig): MiddlewareHandler {\n // Initialize client lazily\n let initPromise: Promise<void> | null = null\n\n const initialize = async () => {\n if (!honoClient) {\n honoClient = createTogglyClient(config)\n await honoClient.init()\n }\n }\n\n return async (c: Context, next) => {\n // Ensure client is initialized\n if (!initPromise) {\n initPromise = initialize()\n }\n await initPromise\n\n if (!honoClient) {\n throw new Error('Toggly client failed to initialize')\n }\n\n // Extract context from request\n const evalContext = await extractContext(c, config)\n const identity = evalContext.identity\n\n // Attach Toggly helpers to Hono context\n c.set('toggly', {\n client: honoClient,\n features: honoClient.state.features,\n identity,\n context: evalContext,\n isFeatureOn: (featureKey: string) => honoClient!.isFeatureOn(featureKey, evalContext),\n isFeatureOff: (featureKey: string) => honoClient!.isFeatureOff(featureKey, evalContext),\n evaluateFeatureGate: (featureKeys, requirement, negate) =>\n honoClient!.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),\n })\n\n await next()\n }\n}\n\n/**\n * Create a feature gate middleware\n *\n * Protects routes by checking if specified features are enabled\n */\nexport function featureGate(options: FeatureGateOptions): MiddlewareHandler {\n const {\n featureKey,\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before featureGate')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n await next()\n return\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Create middleware that applies feature gates based on route patterns\n */\nexport function featureRoutes(routes: FeatureRouteOptions[]): MiddlewareHandler {\n return async (c: Context, next) => {\n for (const route of routes) {\n // Check if route matches\n const pathMatches =\n typeof route.path === 'string'\n ? c.req.path === route.path || c.req.path.startsWith(route.path)\n : route.path.test(c.req.path)\n\n if (!pathMatches) {\n continue\n }\n\n // Check if method matches\n if (route.methods && !route.methods.includes(c.req.method.toUpperCase())) {\n continue\n }\n\n // Apply feature gate\n const gate = featureGate(route)\n return gate(c, next)\n }\n\n // No matching route, continue\n await next()\n }\n}\n\n/**\n * Create a route handler that only executes if feature is enabled\n */\nexport function withFeature(\n featureKey: string | string[],\n handler: Handler,\n options: Omit<FeatureGateOptions, 'featureKey'> = {}\n): MiddlewareHandler {\n const {\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before withFeature')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n // Execute the handler\n return handler(c, next)\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Get features handler for Hono\n */\nexport const featuresHandler: Handler = async (c: Context) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n return c.json(\n {\n error: 'Internal Server Error',\n message: 'Toggly middleware not configured',\n },\n 500\n )\n }\n\n return c.json({\n features: toggly.features,\n identity: toggly.identity,\n })\n}\n\n/**\n * Close the Hono Toggly client\n */\nexport function closeHonoToggly(): void {\n if (honoClient) {\n honoClient.close()\n honoClient = null\n }\n}\n","// Middleware\nexport {\n togglyMiddleware,\n featureGate,\n featureRoutes,\n withFeature,\n featuresHandler,\n getHonoToggly,\n closeHonoToggly,\n} from './middleware.js'\n\n// Types\nexport type {\n TogglyHonoConfig,\n TogglyContextData,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Re-export core types for convenience\nexport type {\n TogglyClient,\n TogglyConfig,\n TogglyServerConfig,\n TogglyState,\n FeatureDefinitions,\n FeatureRequirement,\n EvaluationContext,\n Hook,\n HookMetadata,\n} from '@ops-ai/toggly-node-core'\n\n// Re-export core utilities\nexport {\n createTogglyClient,\n initToggly,\n getToggly,\n useToggly,\n closeToggly,\n createLoggingHook,\n createMemoryCache,\n createFileCache,\n} from '@ops-ai/toggly-node-core'\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAQP,IAAI,aAAkC;AAK/B,SAAS,gBAAqC;AACnD,SAAO;AACT;AAKA,eAAe,gBACb,GACA,QAC6B;AAE7B,MAAI,OAAO,aAAa;AACtB,WAAO,OAAO,YAAY,CAAC;AAAA,EAC7B;AAGA,QAAM,iBAAiB,EAAE,IAAI,OAAO,mBAAmB;AACvD,MAAI,gBAAgB;AAClB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKA,SAAS,eAAe,GAAgD;AACtE,QAAM,YAAgD,CAAC;AACvD,aAAW,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAG;AACD,cAAU,IAAI,IAAI,EAAE,IAAI,OAAO,IAAI;AAAA,EACrC;AACA,SAAO;A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,UAAU,OAAO;AAAA,EACnB,CAAC;AACH;AAKO,SAAS,kBAAwB;AACtC,MAAI,YAAY;AACd,eAAW,MAAM;AACjB,iBAAa;AAAA,EACf;AACF;;;AC9RA;AAAA,EACE,sBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["createTogglyClient"]}
1
+ {"version":3,"sources":["../src/middleware.ts","../src/index.ts"],"sourcesContent":["import type { Context, MiddlewareHandler, Handler } from 'hono'\nimport {\n createTogglyClient,\n normalizeFeatureKeys,\n fromHttpRequest,\n type TogglyClient,\n type EvaluationContext,\n} from '@ops-ai/toggly-node-core'\nimport type {\n TogglyHonoConfig,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Module-level client singleton\nlet honoClient: TogglyClient | null = null\n\n/**\n * Get the Hono Toggly client\n */\nexport function getHonoToggly(): TogglyClient | null {\n return honoClient\n}\n\n/**\n * Get identity from Hono context\n */\nasync function extractIdentity(\n c: Context,\n config: TogglyHonoConfig\n): Promise<string | undefined> {\n // Use custom extractor if provided\n if (config.getIdentity) {\n return config.getIdentity(c)\n }\n\n // Default: check header\n const headerIdentity = c.req.header('x-toggly-identity')\n if (headerIdentity) {\n return headerIdentity\n }\n\n return undefined\n}\n\n/**\n * Collect segment-relevant headers from a Hono request\n */\nfunction segmentHeaders(c: Context): Record<string, string | undefined> {\n const headerBag: Record<string, string | undefined> = {}\n for (const name of [\n 'user-agent',\n 'accept-language',\n 'cf-ipcountry',\n 'x-vercel-ip-country',\n 'cloudfront-viewer-country',\n ]) {\n headerBag[name] = c.req.header(name)\n }\n return headerBag\n}\n\n/**\n * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n const headerBag = segmentHeaders(c)\n const headerRequest = fromHttpRequest(headerBag).request\n\n // Custom full context: use returned fields, fill missing request from headers\n if (config.getContext) {\n const custom = await config.getContext(c)\n return {\n ...custom,\n // Field-level merge: custom wins; missing keys filled from headers\n request: {\n ...headerRequest,\n ...custom.request,\n },\n }\n }\n\n // Default: identity / groups / claims providers + segment request headers\n const identity = await extractIdentity(c, config)\n const groups = config.getGroups ? await config.getGroups(c) : undefined\n const claims = config.getClaims ? await config.getClaims(c) : undefined\n const fromReq = fromHttpRequest(headerBag, { identity, groups, claims })\n\n return {\n identity: fromReq.identity,\n groups: fromReq.groups,\n claims: fromReq.claims,\n request: fromReq.request,\n traits: {\n ip: c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n userAgent: c.req.header('user-agent'),\n path: c.req.path,\n method: c.req.method,\n },\n }\n}\n\n/**\n * Create Toggly middleware for Hono\n *\n * This middleware:\n * 1. Initializes the Toggly client (if not already initialized)\n * 2. Attaches feature flag helpers to the context\n * 3. Extracts identity and context from the request\n */\nexport function togglyMiddleware(config: TogglyHonoConfig): MiddlewareHandler {\n // Initialize client lazily\n let initPromise: Promise<void> | null = null\n\n const initialize = async () => {\n if (!honoClient) {\n honoClient = createTogglyClient(config)\n await honoClient.init()\n }\n }\n\n return async (c: Context, next) => {\n // Ensure client is initialized\n if (!initPromise) {\n initPromise = initialize()\n }\n await initPromise\n\n if (!honoClient) {\n throw new Error('Toggly client failed to initialize')\n }\n\n // Extract context from request\n const evalContext = await extractContext(c, config)\n const identity = evalContext.identity\n\n // Attach Toggly helpers to Hono context\n c.set('toggly', {\n client: honoClient,\n features: honoClient.state.features,\n identity,\n context: evalContext,\n isFeatureOn: (featureKey: string) => honoClient!.isFeatureOn(featureKey, evalContext),\n isFeatureOff: (featureKey: string) => honoClient!.isFeatureOff(featureKey, evalContext),\n evaluateFeatureGate: (featureKeys, requirement, negate) =>\n honoClient!.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),\n getVariant(featureKey: string) {\n return honoClient!.getVariant(featureKey, evalContext)\n },\n getVariantValue(featureKey: string) {\n return honoClient!.getVariantValue(featureKey, evalContext)\n },\n })\n\n await next()\n }\n}\n\n/**\n * Create a feature gate middleware\n *\n * Protects routes by checking if specified features are enabled\n */\nexport function featureGate(options: FeatureGateOptions): MiddlewareHandler {\n const {\n featureKey,\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before featureGate')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n await next()\n return\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Create middleware that applies feature gates based on route patterns\n */\nexport function featureRoutes(routes: FeatureRouteOptions[]): MiddlewareHandler {\n return async (c: Context, next) => {\n for (const route of routes) {\n // Check if route matches\n const pathMatches =\n typeof route.path === 'string'\n ? c.req.path === route.path || c.req.path.startsWith(route.path)\n : route.path.test(c.req.path)\n\n if (!pathMatches) {\n continue\n }\n\n // Check if method matches\n if (route.methods && !route.methods.includes(c.req.method.toUpperCase())) {\n continue\n }\n\n // Apply feature gate\n const gate = featureGate(route)\n return gate(c, next)\n }\n\n // No matching route, continue\n await next()\n }\n}\n\n/**\n * Create a route handler that only executes if feature is enabled\n */\nexport function withFeature(\n featureKey: string | string[],\n handler: Handler,\n options: Omit<FeatureGateOptions, 'featureKey'> = {}\n): MiddlewareHandler {\n const {\n requirement = 'all',\n negate = false,\n onDisabled,\n redirectTo,\n redirectStatus = 302,\n } = options\n\n const featureKeys = normalizeFeatureKeys(featureKey)\n\n return async (c: Context, next) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n throw new Error('Toggly middleware must be applied before withFeature')\n }\n\n const isEnabled = await toggly.evaluateFeatureGate(featureKeys, requirement, negate)\n\n if (isEnabled) {\n // Execute the handler\n return handler(c, next)\n }\n\n // Feature is disabled\n if (redirectTo) {\n return c.redirect(redirectTo, redirectStatus)\n }\n\n if (onDisabled) {\n return onDisabled(c)\n }\n\n // Default: 404\n return c.json(\n {\n error: 'Not Found',\n message: 'The requested resource is not available',\n },\n 404\n )\n }\n}\n\n/**\n * Get features handler for Hono\n */\nexport const featuresHandler: Handler = async (c: Context) => {\n const toggly = c.get('toggly')\n\n if (!toggly) {\n return c.json(\n {\n error: 'Internal Server Error',\n message: 'Toggly middleware not configured',\n },\n 500\n )\n }\n\n return c.json({\n features: toggly.features,\n identity: toggly.identity,\n })\n}\n\n/**\n * Close the Hono Toggly client\n */\nexport function closeHonoToggly(): void {\n if (honoClient) {\n honoClient.close()\n honoClient = null\n }\n}\n","// Middleware\nexport {\n togglyMiddleware,\n featureGate,\n featureRoutes,\n withFeature,\n featuresHandler,\n getHonoToggly,\n closeHonoToggly,\n} from './middleware.js'\n\n// Types\nexport type {\n TogglyHonoConfig,\n TogglyContextData,\n FeatureGateOptions,\n FeatureRouteOptions,\n} from './types.js'\n\n// Re-export core types for convenience\nexport type {\n TogglyClient,\n TogglyConfig,\n TogglyServerConfig,\n TogglyState,\n FeatureDefinitions,\n FeatureRequirement,\n EvaluationContext,\n Hook,\n HookMetadata,\n VariantResult,\n} from '@ops-ai/toggly-node-core'\n\n// Re-export core utilities\nexport {\n createTogglyClient,\n initToggly,\n getToggly,\n useToggly,\n closeToggly,\n createLoggingHook,\n createMemoryCache,\n createFileCache,\n} from '@ops-ai/toggly-node-core'\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAQP,IAAI,aAAkC;AAK/B,SAAS,gBAAqC;AACnD,SAAO;AACT;AAKA,eAAe,gBACb,GACA,QAC6B;AAE7B,MAAI,OAAO,aAAa;AACtB,WAAO,OAAO,YAAY,CAAC;AAAA,EAC7B;AAGA,QAAM,iBA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,SAAS,YAAY,cAAc;AAAA,IAC9C;AAEA,QAAI,YAAY;AACd,aAAO,WAAW,CAAC;AAAA,IACrB;AAGA,WAAO,EAAE;AAAA,MACP;AAAA,QACE,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAKO,IAAM,kBAA2B,OAAO,MAAe;AAC5D,QAAM,SAAS,EAAE,IAAI,QAAQ;AAE7B,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE;AAAA,MACP;AAAA,QACE,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,KAAK;AAAA,IACZ,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB,CAAC;AACH;AAKO,SAAS,kBAAwB;AACtC,MAAI,YAAY;AACd,eAAW,MAAM;AACjB,iBAAa;AAAA,EACf;AACF;;;ACnSA;AAAA,EACE,sBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["createTogglyClient"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ops-ai/toggly-hono",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Toggly feature flags Hono middleware",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "hono": "^4.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@ops-ai/toggly-node-core": "^0.7.0"
56
+ "@ops-ai/toggly-node-core": "^0.11.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^22.15.30",
@@ -71,6 +71,7 @@
71
71
  "build": "tsup",
72
72
  "dev": "tsup --watch",
73
73
  "test": "vitest run",
74
+ "test:hosts": "node tests/packed-hosts.mjs",
74
75
  "test:watch": "vitest",
75
76
  "test:coverage": "vitest run --coverage",
76
77
  "lint": "eslint src tests",