@ops-ai/toggly-hono 0.1.3 → 0.3.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 +31 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -54,13 +54,42 @@ async function extractIdentity(c, config) {
|
|
|
54
54
|
}
|
|
55
55
|
return void 0;
|
|
56
56
|
}
|
|
57
|
+
function segmentHeaders(c) {
|
|
58
|
+
const headerBag = {};
|
|
59
|
+
for (const name of [
|
|
60
|
+
"user-agent",
|
|
61
|
+
"accept-language",
|
|
62
|
+
"cf-ipcountry",
|
|
63
|
+
"x-vercel-ip-country",
|
|
64
|
+
"cloudfront-viewer-country"
|
|
65
|
+
]) {
|
|
66
|
+
headerBag[name] = c.req.header(name);
|
|
67
|
+
}
|
|
68
|
+
return headerBag;
|
|
69
|
+
}
|
|
57
70
|
async function extractContext(c, config) {
|
|
71
|
+
const headerBag = segmentHeaders(c);
|
|
72
|
+
const headerRequest = (0, import_toggly_node_core.fromHttpRequest)(headerBag).request;
|
|
58
73
|
if (config.getContext) {
|
|
59
|
-
|
|
74
|
+
const custom = await config.getContext(c);
|
|
75
|
+
return {
|
|
76
|
+
...custom,
|
|
77
|
+
// Field-level merge: custom wins; missing keys filled from headers
|
|
78
|
+
request: {
|
|
79
|
+
...headerRequest,
|
|
80
|
+
...custom.request
|
|
81
|
+
}
|
|
82
|
+
};
|
|
60
83
|
}
|
|
61
84
|
const identity = await extractIdentity(c, config);
|
|
85
|
+
const groups = config.getGroups ? await config.getGroups(c) : void 0;
|
|
86
|
+
const claims = config.getClaims ? await config.getClaims(c) : void 0;
|
|
87
|
+
const fromReq = (0, import_toggly_node_core.fromHttpRequest)(headerBag, { identity, groups, claims });
|
|
62
88
|
return {
|
|
63
|
-
identity,
|
|
89
|
+
identity: fromReq.identity,
|
|
90
|
+
groups: fromReq.groups,
|
|
91
|
+
claims: fromReq.claims,
|
|
92
|
+
request: fromReq.request,
|
|
64
93
|
traits: {
|
|
65
94
|
ip: c.req.header("cf-connecting-ip") || c.req.header("x-forwarded-for"),
|
|
66
95
|
userAgent: c.req.header("user-agent"),
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 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 * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n // Use custom extractor if provided\n if (config.getContext) {\n return config.getContext(c)\n }\n\n // Default: extract basic context\n const identity = await extractIdentity(c, config)\n\n return {\n identity,\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,8BAKO;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,eAAe,eACb,GACA,QAC4B;AAE5B,MAAI,OAAO,YAAY;AACrB,WAAO,OAAO,WAAW,CAAC;AAAA,EAC5B;AAGA,QAAM,WAAW,MAAM,gBAAgB,GAAG,MAAM;AAEhD,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,MACN,IAAI,EAAE,IAAI,OAAO,kBAAkB,KAAK,EAAE,IAAI,OAAO,iBAAiB;AAAA,MACtE,WAAW,EAAE,IAAI,OAAO,YAAY;AAAA,MACpC,MAAM,EAAE,IAAI;AAAA,MACZ,QAAQ,EAAE,IAAI;AAAA,IAChB;AAAA,EACF;AACF;AAUO,SAAS,iBAAiB,QAA6C;AAE5E,MAAI,cAAoC;AAExC,QAAM,aAAa,YAAY;A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A;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;;;AD3PA,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} 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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AAA,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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -12,7 +12,17 @@ interface TogglyHonoConfig extends TogglyServerConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
getIdentity?: (c: Context) => string | undefined | Promise<string | undefined>;
|
|
14
14
|
/**
|
|
15
|
-
* Function to extract
|
|
15
|
+
* Function to extract group memberships from Hono context
|
|
16
|
+
*/
|
|
17
|
+
getGroups?: (c: Context) => string[] | undefined | Promise<string[] | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Function to extract principal / JWT-style claims from Hono context
|
|
20
|
+
*/
|
|
21
|
+
getClaims?: (c: Context) => Record<string, string> | undefined | Promise<Record<string, string> | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Function to extract evaluation context from Hono context.
|
|
24
|
+
* When provided, returned fields are used; missing `request` is still
|
|
25
|
+
* filled from HTTP headers via `fromHttpRequest`.
|
|
16
26
|
*/
|
|
17
27
|
getContext?: (c: Context) => EvaluationContext | Promise<EvaluationContext>;
|
|
18
28
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,17 @@ interface TogglyHonoConfig extends TogglyServerConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
getIdentity?: (c: Context) => string | undefined | Promise<string | undefined>;
|
|
14
14
|
/**
|
|
15
|
-
* Function to extract
|
|
15
|
+
* Function to extract group memberships from Hono context
|
|
16
|
+
*/
|
|
17
|
+
getGroups?: (c: Context) => string[] | undefined | Promise<string[] | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Function to extract principal / JWT-style claims from Hono context
|
|
20
|
+
*/
|
|
21
|
+
getClaims?: (c: Context) => Record<string, string> | undefined | Promise<Record<string, string> | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Function to extract evaluation context from Hono context.
|
|
24
|
+
* When provided, returned fields are used; missing `request` is still
|
|
25
|
+
* filled from HTTP headers via `fromHttpRequest`.
|
|
16
26
|
*/
|
|
17
27
|
getContext?: (c: Context) => EvaluationContext | Promise<EvaluationContext>;
|
|
18
28
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/middleware.ts
|
|
2
2
|
import {
|
|
3
3
|
createTogglyClient,
|
|
4
|
-
normalizeFeatureKeys
|
|
4
|
+
normalizeFeatureKeys,
|
|
5
|
+
fromHttpRequest
|
|
5
6
|
} from "@ops-ai/toggly-node-core";
|
|
6
7
|
var honoClient = null;
|
|
7
8
|
function getHonoToggly() {
|
|
@@ -17,13 +18,42 @@ async function extractIdentity(c, config) {
|
|
|
17
18
|
}
|
|
18
19
|
return void 0;
|
|
19
20
|
}
|
|
21
|
+
function segmentHeaders(c) {
|
|
22
|
+
const headerBag = {};
|
|
23
|
+
for (const name of [
|
|
24
|
+
"user-agent",
|
|
25
|
+
"accept-language",
|
|
26
|
+
"cf-ipcountry",
|
|
27
|
+
"x-vercel-ip-country",
|
|
28
|
+
"cloudfront-viewer-country"
|
|
29
|
+
]) {
|
|
30
|
+
headerBag[name] = c.req.header(name);
|
|
31
|
+
}
|
|
32
|
+
return headerBag;
|
|
33
|
+
}
|
|
20
34
|
async function extractContext(c, config) {
|
|
35
|
+
const headerBag = segmentHeaders(c);
|
|
36
|
+
const headerRequest = fromHttpRequest(headerBag).request;
|
|
21
37
|
if (config.getContext) {
|
|
22
|
-
|
|
38
|
+
const custom = await config.getContext(c);
|
|
39
|
+
return {
|
|
40
|
+
...custom,
|
|
41
|
+
// Field-level merge: custom wins; missing keys filled from headers
|
|
42
|
+
request: {
|
|
43
|
+
...headerRequest,
|
|
44
|
+
...custom.request
|
|
45
|
+
}
|
|
46
|
+
};
|
|
23
47
|
}
|
|
24
48
|
const identity = await extractIdentity(c, config);
|
|
49
|
+
const groups = config.getGroups ? await config.getGroups(c) : void 0;
|
|
50
|
+
const claims = config.getClaims ? await config.getClaims(c) : void 0;
|
|
51
|
+
const fromReq = fromHttpRequest(headerBag, { identity, groups, claims });
|
|
25
52
|
return {
|
|
26
|
-
identity,
|
|
53
|
+
identity: fromReq.identity,
|
|
54
|
+
groups: fromReq.groups,
|
|
55
|
+
claims: fromReq.claims,
|
|
56
|
+
request: fromReq.request,
|
|
27
57
|
traits: {
|
|
28
58
|
ip: c.req.header("cf-connecting-ip") || c.req.header("x-forwarded-for"),
|
|
29
59
|
userAgent: c.req.header("user-agent"),
|
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 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 * Get evaluation context from Hono context\n */\nasync function extractContext(\n c: Context,\n config: TogglyHonoConfig\n): Promise<EvaluationContext> {\n // Use custom extractor if provided\n if (config.getContext) {\n return config.getContext(c)\n }\n\n // Default: extract basic context\n const identity = await extractIdentity(c, config)\n\n return {\n identity,\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,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;AAC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,iBAAiB;AAAA,EACnB,IAAI;AAEJ,QAAM,cAAc,qBAAqB,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;;;AC3PA;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 })\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;A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AAA,OACK;","names":["createTogglyClient"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ops-ai/toggly-hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.
|
|
56
|
+
"@ops-ai/toggly-node-core": "^0.7.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^22.15.30",
|