@ops-ai/toggly-hono 0.3.1 → 0.5.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
@@ -107,9 +107,7 @@ function togglyMiddleware(config) {
107
107
  }
108
108
  };
109
109
  return async (c, next) => {
110
- if (!initPromise) {
111
- initPromise = initialize();
112
- }
110
+ initPromise ??= initialize();
113
111
  await initPromise;
114
112
  if (!honoClient) {
115
113
  throw new Error("Toggly client failed to initialize");
@@ -123,7 +121,13 @@ function togglyMiddleware(config) {
123
121
  context: evalContext,
124
122
  isFeatureOn: (featureKey) => honoClient.isFeatureOn(featureKey, evalContext),
125
123
  isFeatureOff: (featureKey) => honoClient.isFeatureOff(featureKey, evalContext),
126
- evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext)
124
+ evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),
125
+ getVariant(featureKey) {
126
+ return honoClient.getVariant(featureKey, evalContext);
127
+ },
128
+ getVariantValue(featureKey) {
129
+ return honoClient.getVariantValue(featureKey, evalContext);
130
+ }
127
131
  });
128
132
  await next();
129
133
  };
@@ -212,7 +216,7 @@ function withFeature(featureKey, handler, options = {}) {
212
216
  );
213
217
  };
214
218
  }
215
- var featuresHandler = async (c) => {
219
+ var featuresHandler = (c) => {
216
220
  const toggly = c.get("toggly");
217
221
  if (!toggly) {
218
222
  return c.json(
@@ -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\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;AAA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,aAAO,KAAK,GAAG,IAAI;AAAA,IACrB;AAGA,UAAM,KAAK;AAAA,EACb;AACF;AAKO,SAAS,YACd,YACA,SACA,UAAkD,CAAC,GAChC;AACnB,QAAM;AAAA,IACJ,cAAc;AAAA,IACd,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,EACnB,IAAI;AAEJ,QAAM,kBAAc,8CAAqB,UAAU;AAEnD,SAAO,OAAO,GAAY,SAAS;AACjC,UAAM,SAAS,EAAE,IAAI,QAAQ;AAE7B,QAAI,CAAC,QAAQ;AACX,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 initPromise ??= initialize()\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 = (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,G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AAQ;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;;;ADjSA,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
@@ -71,9 +71,7 @@ function togglyMiddleware(config) {
71
71
  }
72
72
  };
73
73
  return async (c, next) => {
74
- if (!initPromise) {
75
- initPromise = initialize();
76
- }
74
+ initPromise ??= initialize();
77
75
  await initPromise;
78
76
  if (!honoClient) {
79
77
  throw new Error("Toggly client failed to initialize");
@@ -87,7 +85,13 @@ function togglyMiddleware(config) {
87
85
  context: evalContext,
88
86
  isFeatureOn: (featureKey) => honoClient.isFeatureOn(featureKey, evalContext),
89
87
  isFeatureOff: (featureKey) => honoClient.isFeatureOff(featureKey, evalContext),
90
- evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext)
88
+ evaluateFeatureGate: (featureKeys, requirement, negate) => honoClient.evaluateFeatureGate(featureKeys, requirement, negate, evalContext),
89
+ getVariant(featureKey) {
90
+ return honoClient.getVariant(featureKey, evalContext);
91
+ },
92
+ getVariantValue(featureKey) {
93
+ return honoClient.getVariantValue(featureKey, evalContext);
94
+ }
91
95
  });
92
96
  await next();
93
97
  };
@@ -176,7 +180,7 @@ function withFeature(featureKey, handler, options = {}) {
176
180
  );
177
181
  };
178
182
  }
179
- var featuresHandler = async (c) => {
183
+ var featuresHandler = (c) => {
180
184
  const toggly = c.get("toggly");
181
185
  if (!toggly) {
182
186
  return c.json(
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;AACT;AAKA,eAAe,eACb,GACA,QAC4B;AAC5B,QAAM,YAAY,eAAe,CAAC;AAClC,QAAM,gBAAgB,gBAAgB,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;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAGA,QAAM,WAAW,MAAM,gBAAgB,GAAG,MAAM;AAChD,QAAM,SAAS,OAAO,YAAY,MAAM,OAAO,UAAU,CAAC,IAAI;AAC9D,QAAM,SAAS,OAAO,YAAY,MAAM,OAAO,UAAU,CAAC,IAAI;AAC9D,QAAM,UAAU,gBAAgB,WAAW,EAAE,UAAU,QAAQ,OAAO,CAAC;AAEvE,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,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AAQ;AACX,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;;;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 initPromise ??= initialize()\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 = (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,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,gBAAgB,gBAAgB,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;AAAA,MACZ;AAAA,I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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.1",
3
+ "version": "0.5.0",
4
4
  "description": "Toggly feature flags Hono middleware",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -47,22 +47,22 @@
47
47
  "url": "https://github.com/ops-ai/Toggly.FeatureManagement/issues"
48
48
  },
49
49
  "engines": {
50
- "node": ">=18.0.0"
50
+ "node": ">=22.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "hono": "^4.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@ops-ai/toggly-node-core": "^0.9.1"
56
+ "@ops-ai/toggly-node-core": "^0.14.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@types/node": "^22.15.30",
60
- "@vitest/coverage-v8": "^3.2.4",
61
- "eslint": "^9.28.0",
62
- "hono": "^4.7.11",
63
- "tsup": "^8.5.0",
64
- "typescript": "^5.8.3",
65
- "vitest": "^3.2.4"
59
+ "@types/node": "^22.20.5",
60
+ "@vitest/coverage-v8": "^3.2.7",
61
+ "eslint": "^9.39.5",
62
+ "hono": "^4.13.16",
63
+ "tsup": "^8.5.1",
64
+ "typescript": "^5.9.3",
65
+ "vitest": "^3.2.7"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"