@naylence/runtime 0.3.5-test.910 → 0.3.5-test.913

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.
Files changed (47) hide show
  1. package/dist/browser/index.cjs +1915 -1214
  2. package/dist/browser/index.mjs +1910 -1209
  3. package/dist/cjs/naylence/fame/config/extended-fame-config.js +52 -0
  4. package/dist/cjs/naylence/fame/factory-manifest.js +2 -0
  5. package/dist/cjs/naylence/fame/http/jwks-api-router.js +16 -18
  6. package/dist/cjs/naylence/fame/http/oauth2-server.js +28 -31
  7. package/dist/cjs/naylence/fame/http/oauth2-token-router.js +901 -93
  8. package/dist/cjs/naylence/fame/http/openid-configuration-router.js +30 -32
  9. package/dist/cjs/naylence/fame/node/admission/admission-profile-factory.js +79 -0
  10. package/dist/cjs/naylence/fame/security/auth/oauth2-pkce-token-provider-factory.js +171 -0
  11. package/dist/cjs/naylence/fame/security/auth/oauth2-pkce-token-provider.js +560 -0
  12. package/dist/cjs/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  13. package/dist/cjs/naylence/fame/telemetry/open-telemetry-trace-emitter-factory.js +19 -2
  14. package/dist/cjs/naylence/fame/telemetry/open-telemetry-trace-emitter.js +19 -9
  15. package/dist/cjs/naylence/fame/util/register-runtime-factories.js +6 -0
  16. package/dist/cjs/version.js +2 -2
  17. package/dist/esm/naylence/fame/config/extended-fame-config.js +52 -0
  18. package/dist/esm/naylence/fame/factory-manifest.js +2 -0
  19. package/dist/esm/naylence/fame/http/jwks-api-router.js +16 -17
  20. package/dist/esm/naylence/fame/http/oauth2-server.js +28 -31
  21. package/dist/esm/naylence/fame/http/oauth2-token-router.js +901 -93
  22. package/dist/esm/naylence/fame/http/openid-configuration-router.js +30 -31
  23. package/dist/esm/naylence/fame/node/admission/admission-profile-factory.js +79 -0
  24. package/dist/esm/naylence/fame/security/auth/oauth2-pkce-token-provider-factory.js +134 -0
  25. package/dist/esm/naylence/fame/security/auth/oauth2-pkce-token-provider.js +555 -0
  26. package/dist/esm/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  27. package/dist/esm/naylence/fame/telemetry/open-telemetry-trace-emitter-factory.js +19 -2
  28. package/dist/esm/naylence/fame/telemetry/open-telemetry-trace-emitter.js +19 -9
  29. package/dist/esm/naylence/fame/util/register-runtime-factories.js +6 -0
  30. package/dist/esm/version.js +2 -2
  31. package/dist/node/index.cjs +1911 -1210
  32. package/dist/node/index.mjs +1910 -1209
  33. package/dist/node/node.cjs +2945 -1439
  34. package/dist/node/node.mjs +2944 -1438
  35. package/dist/types/naylence/fame/factory-manifest.d.ts +1 -1
  36. package/dist/types/naylence/fame/http/jwks-api-router.d.ts +8 -8
  37. package/dist/types/naylence/fame/http/oauth2-server.d.ts +3 -3
  38. package/dist/types/naylence/fame/http/oauth2-token-router.d.ts +75 -19
  39. package/dist/types/naylence/fame/http/openid-configuration-router.d.ts +8 -8
  40. package/dist/types/naylence/fame/security/auth/oauth2-pkce-token-provider-factory.d.ts +27 -0
  41. package/dist/types/naylence/fame/security/auth/oauth2-pkce-token-provider.d.ts +42 -0
  42. package/dist/types/naylence/fame/security/crypto/providers/default-crypto-provider.d.ts +0 -1
  43. package/dist/types/naylence/fame/telemetry/open-telemetry-trace-emitter.d.ts +4 -0
  44. package/dist/types/version.d.ts +1 -1
  45. package/package.json +4 -4
  46. package/dist/esm/naylence/fame/fastapi/oauth2-server.js +0 -205
  47. package/dist/types/naylence/fame/fastapi/oauth2-server.d.ts +0 -22
@@ -57,6 +57,57 @@ const CONFIG_SEARCH_PATHS = [
57
57
  ];
58
58
  const fsModuleSpecifier = String.fromCharCode(102) + String.fromCharCode(115);
59
59
  let cachedFsModule = null;
60
+ // Capture this module's URL without triggering TypeScript's import.meta restriction on CJS builds
61
+ const currentModuleUrl = (() => {
62
+ try {
63
+ return (0, eval)('import.meta.url');
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ })();
69
+ // Shared flag that allows synchronous waiting for the Node-specific require shim
70
+ const requireReadyFlag = logging_types_js_1.isNode && typeof SharedArrayBuffer !== 'undefined'
71
+ ? new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT))
72
+ : null;
73
+ if (requireReadyFlag) {
74
+ // 0 means initializing, 1 means ready (success or failure)
75
+ Atomics.store(requireReadyFlag, 0, 0);
76
+ // Prepare a CommonJS-style require when running in pure ESM contexts
77
+ void (async () => {
78
+ try {
79
+ if (typeof require !== 'function') {
80
+ const moduleNamespace = (await Promise.resolve().then(() => __importStar(require('node:module'))));
81
+ const createRequire = moduleNamespace.createRequire;
82
+ if (typeof createRequire === 'function') {
83
+ const fallbackPath = `${process.cwd()}/.__naylence_require_shim__.mjs`;
84
+ const nodeRequire = createRequire(currentModuleUrl ?? fallbackPath);
85
+ globalThis.require = nodeRequire;
86
+ }
87
+ }
88
+ }
89
+ catch {
90
+ // Ignore failures – getFsModule will surface a helpful error when needed
91
+ }
92
+ })()
93
+ .catch(() => {
94
+ // Ignore async errors – the ready flag will still unblock consumers
95
+ })
96
+ .finally(() => {
97
+ Atomics.store(requireReadyFlag, 0, 1);
98
+ Atomics.notify(requireReadyFlag, 0);
99
+ });
100
+ }
101
+ function ensureRequireReady() {
102
+ if (!requireReadyFlag) {
103
+ return;
104
+ }
105
+ if (Atomics.load(requireReadyFlag, 0) === 1) {
106
+ return;
107
+ }
108
+ // Block until the asynchronous loader finishes initialising
109
+ Atomics.wait(requireReadyFlag, 0, 0);
110
+ }
60
111
  function getFsModule() {
61
112
  if (cachedFsModule) {
62
113
  return cachedFsModule;
@@ -64,6 +115,7 @@ function getFsModule() {
64
115
  if (!logging_types_js_1.isNode) {
65
116
  throw new Error('File system access is not available in this environment');
66
117
  }
118
+ ensureRequireReady();
67
119
  if (typeof require === 'function') {
68
120
  try {
69
121
  cachedFsModule = require(fsModuleSpecifier);
@@ -71,6 +71,7 @@ exports.MODULES = [
71
71
  "./security/auth/noop-token-verifier-factory.js",
72
72
  "./security/auth/oauth2-authorizer-factory.js",
73
73
  "./security/auth/oauth2-client-credentials-token-provider-factory.js",
74
+ "./security/auth/oauth2-pkce-token-provider-factory.js",
74
75
  "./security/auth/query-param-auth-injection-strategy-factory.js",
75
76
  "./security/auth/shared-secret-authorizer-factory.js",
76
77
  "./security/auth/shared-secret-token-provider-factory.js",
@@ -144,6 +145,7 @@ exports.MODULE_LOADERS = {
144
145
  "./security/auth/noop-token-verifier-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/noop-token-verifier-factory.js"))),
145
146
  "./security/auth/oauth2-authorizer-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/oauth2-authorizer-factory.js"))),
146
147
  "./security/auth/oauth2-client-credentials-token-provider-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/oauth2-client-credentials-token-provider-factory.js"))),
148
+ "./security/auth/oauth2-pkce-token-provider-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/oauth2-pkce-token-provider-factory.js"))),
147
149
  "./security/auth/query-param-auth-injection-strategy-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/query-param-auth-injection-strategy-factory.js"))),
148
150
  "./security/auth/shared-secret-authorizer-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/shared-secret-authorizer-factory.js"))),
149
151
  "./security/auth/shared-secret-token-provider-factory.js": () => Promise.resolve().then(() => __importStar(require("./security/auth/shared-secret-token-provider-factory.js"))),
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * JWKS (JSON Web Key Set) API router for Express
3
+ * JWKS (JSON Web Key Set) API plugin for Fastify
4
4
  *
5
5
  * Provides /.well-known/jwks.json endpoint for public key discovery
6
6
  * Used by OAuth2/JWT token verification
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createJwksRouter = createJwksRouter;
10
- const tslib_1 = require("tslib");
11
- const express_1 = tslib_1.__importDefault(require("express"));
12
10
  const logging_js_1 = require("../util/logging.js");
13
11
  const logger = (0, logging_js_1.getLogger)('naylence.fame.http.jwks_api_router');
14
12
  const DEFAULT_PREFIX = '';
@@ -88,23 +86,22 @@ function filterKeysByType(jwksData, allowedTypes) {
88
86
  return { ...jwksData, keys: filteredKeys };
89
87
  }
90
88
  /**
91
- * Create an Express router that exposes JWKS at /.well-known/jwks.json
89
+ * Create a Fastify plugin that exposes JWKS at /.well-known/jwks.json
92
90
  *
93
91
  * @param options - Router configuration options
94
- * @returns Express router with JWKS endpoint
92
+ * @returns Fastify plugin with JWKS endpoint
95
93
  *
96
94
  * @example
97
95
  * ```typescript
98
- * import express from 'express';
96
+ * import Fastify from 'fastify';
99
97
  * import { createJwksRouter } from '@naylence/runtime';
100
98
  *
101
- * const app = express();
99
+ * const app = Fastify();
102
100
  * const cryptoProvider = new MyCryptoProvider();
103
- * app.use(createJwksRouter({ cryptoProvider }));
101
+ * app.register(createJwksRouter({ cryptoProvider }));
104
102
  * ```
105
103
  */
106
104
  function createJwksRouter(options = {}) {
107
- const router = express_1.default.Router();
108
105
  const { getJwksJson, cryptoProvider, prefix = DEFAULT_PREFIX, keyTypes, } = normalizeCreateJwksRouterOptions(options);
109
106
  // Get JWKS data
110
107
  let jwks;
@@ -127,14 +124,15 @@ function createJwksRouter(options = {}) {
127
124
  key_types: allowedKeyTypes,
128
125
  total_keys: jwks.keys.length,
129
126
  });
130
- // JWKS endpoint
131
- router.get(`${prefix}/.well-known/jwks.json`, (_req, res) => {
132
- const filteredJwks = filterKeysByType(jwks, allowedKeyTypes);
133
- logger.debug('jwks_served', {
134
- total_keys: jwks.keys.length,
135
- filtered_keys: filteredJwks.keys.length,
127
+ const plugin = async (instance) => {
128
+ instance.get(`${prefix}/.well-known/jwks.json`, async (_request, reply) => {
129
+ const filteredJwks = filterKeysByType(jwks, allowedKeyTypes);
130
+ logger.debug('jwks_served', {
131
+ total_keys: jwks.keys.length,
132
+ filtered_keys: filteredJwks.keys.length,
133
+ });
134
+ reply.send(filteredJwks);
136
135
  });
137
- res.json(filteredJwks);
138
- });
139
- return router;
136
+ };
137
+ return plugin;
140
138
  }
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.createApp = createApp;
27
27
  exports.main = main;
28
28
  const tslib_1 = require("tslib");
29
- const express_1 = tslib_1.__importDefault(require("express"));
29
+ const fastify_1 = tslib_1.__importDefault(require("fastify"));
30
30
  const oauth2_token_router_js_1 = require("./oauth2-token-router.js");
31
31
  const jwks_api_router_js_1 = require("./jwks-api-router.js");
32
32
  const openid_configuration_router_js_1 = require("./openid-configuration-router.js");
@@ -58,23 +58,18 @@ async function getCryptoProvider() {
58
58
  return DefaultCryptoProvider.create();
59
59
  }
60
60
  /**
61
- * Create and configure the OAuth2 Express application
61
+ * Create and configure the OAuth2 Fastify application
62
62
  */
63
63
  async function createApp() {
64
- const app = (0, express_1.default)();
65
- // Middleware
66
- app.use(express_1.default.json());
67
- app.use(express_1.default.urlencoded({ extended: true }));
64
+ const app = (0, fastify_1.default)({ logger: false });
68
65
  // Get crypto provider
69
66
  const cryptoProvider = await getCryptoProvider();
70
67
  // Add routers
71
- app.use((0, oauth2_token_router_js_1.createOAuth2TokenRouter)({ cryptoProvider }));
72
- app.use((0, jwks_api_router_js_1.createJwksRouter)({ cryptoProvider }));
73
- app.use((0, openid_configuration_router_js_1.createOpenIDConfigurationRouter)());
68
+ app.register((0, oauth2_token_router_js_1.createOAuth2TokenRouter)({ cryptoProvider }));
69
+ app.register((0, jwks_api_router_js_1.createJwksRouter)({ cryptoProvider }));
70
+ app.register((0, openid_configuration_router_js_1.createOpenIDConfigurationRouter)());
74
71
  // Health check endpoint
75
- app.get('/health', (_req, res) => {
76
- res.json({ status: 'ok' });
77
- });
72
+ app.get('/health', async () => ({ status: 'ok' }));
78
73
  return app;
79
74
  }
80
75
  /**
@@ -102,25 +97,27 @@ async function main() {
102
97
  });
103
98
  const app = await createApp();
104
99
  // Start server
105
- app.listen(port, host, () => {
106
- logger.info('oauth2_server_started', {
107
- host,
108
- port,
109
- endpoints: {
110
- token: '/oauth/token',
111
- jwks: '/.well-known/jwks.json',
112
- openid_config: '/.well-known/openid-configuration',
113
- health: '/health',
114
- },
115
- });
100
+ await app.listen({ port, host });
101
+ logger.info('oauth2_server_started', {
102
+ host,
103
+ port,
104
+ endpoints: {
105
+ token: '/oauth/token',
106
+ jwks: '/.well-known/jwks.json',
107
+ openid_config: '/.well-known/openid-configuration',
108
+ health: '/health',
109
+ },
116
110
  });
111
+ const shutdown = (signal) => {
112
+ logger.info('oauth2_server_shutting_down', { signal });
113
+ app
114
+ .close()
115
+ .catch((error) => logger.error('oauth2_server_shutdown_error', {
116
+ error: error instanceof Error ? error.message : String(error),
117
+ }))
118
+ .finally(() => process.exit(0));
119
+ };
117
120
  // Graceful shutdown
118
- process.on('SIGINT', () => {
119
- logger.info('oauth2_server_shutting_down', { signal: 'SIGINT' });
120
- process.exit(0);
121
- });
122
- process.on('SIGTERM', () => {
123
- logger.info('oauth2_server_shutting_down', { signal: 'SIGTERM' });
124
- process.exit(0);
125
- });
121
+ process.on('SIGINT', () => shutdown('SIGINT'));
122
+ process.on('SIGTERM', () => shutdown('SIGTERM'));
126
123
  }