@naylence/runtime 0.3.5-test.911 → 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 (31) hide show
  1. package/dist/browser/index.cjs +72 -164
  2. package/dist/browser/index.mjs +72 -164
  3. package/dist/cjs/naylence/fame/config/extended-fame-config.js +52 -0
  4. package/dist/cjs/naylence/fame/http/jwks-api-router.js +16 -18
  5. package/dist/cjs/naylence/fame/http/oauth2-server.js +28 -31
  6. package/dist/cjs/naylence/fame/http/oauth2-token-router.js +153 -8
  7. package/dist/cjs/naylence/fame/http/openid-configuration-router.js +30 -32
  8. package/dist/cjs/naylence/fame/node/admission/admission-profile-factory.js +18 -0
  9. package/dist/cjs/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  10. package/dist/cjs/version.js +2 -2
  11. package/dist/esm/naylence/fame/config/extended-fame-config.js +52 -0
  12. package/dist/esm/naylence/fame/http/jwks-api-router.js +16 -17
  13. package/dist/esm/naylence/fame/http/oauth2-server.js +28 -31
  14. package/dist/esm/naylence/fame/http/oauth2-token-router.js +153 -8
  15. package/dist/esm/naylence/fame/http/openid-configuration-router.js +30 -31
  16. package/dist/esm/naylence/fame/node/admission/admission-profile-factory.js +18 -0
  17. package/dist/esm/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  18. package/dist/esm/version.js +2 -2
  19. package/dist/node/index.cjs +72 -164
  20. package/dist/node/index.mjs +72 -164
  21. package/dist/node/node.cjs +299 -249
  22. package/dist/node/node.mjs +299 -249
  23. package/dist/types/naylence/fame/http/jwks-api-router.d.ts +8 -8
  24. package/dist/types/naylence/fame/http/oauth2-server.d.ts +3 -3
  25. package/dist/types/naylence/fame/http/oauth2-token-router.d.ts +5 -5
  26. package/dist/types/naylence/fame/http/openid-configuration-router.d.ts +8 -8
  27. package/dist/types/naylence/fame/security/crypto/providers/default-crypto-provider.d.ts +0 -1
  28. package/dist/types/version.d.ts +1 -1
  29. package/package.json +4 -6
  30. package/dist/esm/naylence/fame/fastapi/oauth2-server.js +0 -205
  31. package/dist/types/naylence/fame/fastapi/oauth2-server.d.ts +0 -22
@@ -1,10 +1,10 @@
1
1
  /**
2
- * JWKS (JSON Web Key Set) API router for Express
2
+ * JWKS (JSON Web Key Set) API plugin for Fastify
3
3
  *
4
4
  * Provides /.well-known/jwks.json endpoint for public key discovery
5
5
  * Used by OAuth2/JWT token verification
6
6
  */
7
- import { type Router } from 'express';
7
+ import type { FastifyPluginAsync } from 'fastify';
8
8
  import type { CryptoProvider } from '../security/crypto/providers/crypto-provider.js';
9
9
  export interface CreateJwksRouterOptions {
10
10
  /**
@@ -30,19 +30,19 @@ export interface CreateJwksRouterOptions {
30
30
  keyTypes?: string[];
31
31
  }
32
32
  /**
33
- * Create an Express router that exposes JWKS at /.well-known/jwks.json
33
+ * Create a Fastify plugin that exposes JWKS at /.well-known/jwks.json
34
34
  *
35
35
  * @param options - Router configuration options
36
- * @returns Express router with JWKS endpoint
36
+ * @returns Fastify plugin with JWKS endpoint
37
37
  *
38
38
  * @example
39
39
  * ```typescript
40
- * import express from 'express';
40
+ * import Fastify from 'fastify';
41
41
  * import { createJwksRouter } from '@naylence/runtime';
42
42
  *
43
- * const app = express();
43
+ * const app = Fastify();
44
44
  * const cryptoProvider = new MyCryptoProvider();
45
- * app.use(createJwksRouter({ cryptoProvider }));
45
+ * app.register(createJwksRouter({ cryptoProvider }));
46
46
  * ```
47
47
  */
48
- export declare function createJwksRouter(options?: CreateJwksRouterOptions): Router;
48
+ export declare function createJwksRouter(options?: CreateJwksRouterOptions): FastifyPluginAsync;
@@ -21,11 +21,11 @@
21
21
  * FAME_JWT_ISSUER: JWT issuer (default: https://auth.fame.fabric)
22
22
  * FAME_JWT_ALGORITHM: JWT algorithm (default: EdDSA)
23
23
  */
24
- import express from 'express';
24
+ import type { FastifyInstance } from 'fastify';
25
25
  /**
26
- * Create and configure the OAuth2 Express application
26
+ * Create and configure the OAuth2 Fastify application
27
27
  */
28
- export declare function createApp(): Promise<express.Application>;
28
+ export declare function createApp(): Promise<FastifyInstance>;
29
29
  /**
30
30
  * Main entry point when run as CLI
31
31
  */
@@ -1,11 +1,11 @@
1
1
  /**
2
- * OAuth2 client credentials and authorization code (PKCE) grant router for Express
2
+ * OAuth2 client credentials and authorization code (PKCE) grant router for Fastify
3
3
  *
4
4
  * Provides /oauth/token and /oauth/authorize endpoints for local development and testing.
5
5
  * Implements OAuth2 client credentials grant with JWT token issuance and
6
6
  * OAuth2 authorization code grant with PKCE verification.
7
7
  */
8
- import { type Router } from 'express';
8
+ import type { FastifyPluginAsync } from 'fastify';
9
9
  import type { CryptoProvider } from '../security/crypto/providers/crypto-provider.js';
10
10
  export interface CreateOAuth2TokenRouterOptions {
11
11
  /**
@@ -110,11 +110,11 @@ export interface CreateOAuth2TokenRouterOptions {
110
110
  devLoginTitle?: string;
111
111
  }
112
112
  /**
113
- * Create an Express router that implements OAuth2 token and authorization endpoints
113
+ * Create a Fastify plugin that implements OAuth2 token and authorization endpoints
114
114
  * with support for client credentials and authorization code (PKCE) grants.
115
115
  *
116
116
  * @param options - Router configuration options
117
- * @returns Express router with OAuth2 token and authorization endpoints
117
+ * @returns Fastify plugin with OAuth2 token and authorization endpoints
118
118
  *
119
119
  * Environment Variables:
120
120
  * FAME_JWT_CLIENT_ID: OAuth2 client identifier
@@ -127,4 +127,4 @@ export interface CreateOAuth2TokenRouterOptions {
127
127
  * FAME_OAUTH_ALLOW_PUBLIC_CLIENTS: Allow PKCE exchanges without client_secret (optional, default: true)
128
128
  * FAME_OAUTH_CODE_TTL_SEC: Authorization code TTL in seconds (optional, default: 300)
129
129
  */
130
- export declare function createOAuth2TokenRouter(options: CreateOAuth2TokenRouterOptions): Router;
130
+ export declare function createOAuth2TokenRouter(options: CreateOAuth2TokenRouterOptions): FastifyPluginAsync;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * OpenID Connect Discovery configuration router for Express
2
+ * OpenID Connect Discovery configuration plugin for Fastify
3
3
  *
4
4
  * Provides /.well-known/openid-configuration endpoint for OAuth2/OIDC client auto-discovery
5
5
  */
6
- import { type Router } from 'express';
6
+ import type { FastifyPluginAsync } from 'fastify';
7
7
  export interface CreateOpenIDConfigurationRouterOptions {
8
8
  /**
9
9
  * Router prefix (default: empty string)
@@ -41,10 +41,10 @@ export interface CreateOpenIDConfigurationRouterOptions {
41
41
  algorithm?: string;
42
42
  }
43
43
  /**
44
- * Create an Express router that implements OpenID Connect Discovery
44
+ * Create a Fastify plugin that implements OpenID Connect Discovery
45
45
  *
46
46
  * @param options - Router configuration options
47
- * @returns Express router with OpenID configuration endpoint
47
+ * @returns Fastify plugin with OpenID configuration endpoint
48
48
  *
49
49
  * Environment Variables:
50
50
  * FAME_JWT_ISSUER: JWT issuer claim (optional)
@@ -53,13 +53,13 @@ export interface CreateOpenIDConfigurationRouterOptions {
53
53
  *
54
54
  * @example
55
55
  * ```typescript
56
- * import express from 'express';
56
+ * import Fastify from 'fastify';
57
57
  * import { createOpenIDConfigurationRouter } from '@naylence/runtime';
58
58
  *
59
- * const app = express();
60
- * app.use(createOpenIDConfigurationRouter({
59
+ * const app = Fastify();
60
+ * app.register(createOpenIDConfigurationRouter({
61
61
  * issuer: 'https://auth.example.com',
62
62
  * }));
63
63
  * ```
64
64
  */
65
- export declare function createOpenIDConfigurationRouter(options?: CreateOpenIDConfigurationRouterOptions): Router;
65
+ export declare function createOpenIDConfigurationRouter(options?: CreateOpenIDConfigurationRouterOptions): FastifyPluginAsync;
@@ -57,6 +57,5 @@ export declare class DefaultCryptoProvider implements CryptoProvider {
57
57
  prepareForAttach(nodeId: string, physicalPath: string, logicals: string[]): void;
58
58
  setLogicals(logicals: string[]): void;
59
59
  storeSignedCertificate(certificatePem: string, certificateChainPem?: string | null): void;
60
- createCsr(nodeId: string, physicalPath: string, logicals: string[], subjectName?: string): Promise<string>;
61
60
  }
62
61
  export {};
@@ -2,4 +2,4 @@
2
2
  * The package version, injected at build time.
3
3
  * @internal
4
4
  */
5
- export declare const VERSION = "0.3.5-test.911";
5
+ export declare const VERSION = "0.3.5-test.913";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.3.5-test.911",
3
+ "version": "0.3.5-test.913",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",
@@ -183,8 +183,6 @@
183
183
  "@peculiar/asn1-csr": "^2.5.0",
184
184
  "@peculiar/asn1-schema": "^2.5.0",
185
185
  "@peculiar/asn1-x509": "^2.5.0",
186
- "@types/express": "^5.0.3",
187
- "express": "^5.1.0",
188
186
  "fastify": "^5.6.1",
189
187
  "jose": "^6.1.0",
190
188
  "yaml": "^2.6.0",
@@ -217,7 +215,7 @@
217
215
  "@types/better-sqlite3": "^7.6.13",
218
216
  "@types/jest": "^29.5.14",
219
217
  "@types/node": "^24.6.0",
220
- "@types/supertest": "^2.0.16",
218
+ "@types/supertest": "^2.0.16",
221
219
  "@types/ws": "^8.5.10",
222
220
  "@typescript-eslint/eslint-plugin": "^8.45.0",
223
221
  "@typescript-eslint/parser": "^8.45.0",
@@ -234,7 +232,7 @@
234
232
  "rimraf": "^6.0.1",
235
233
  "rollup": "^4.52.3",
236
234
  "size-limit": "^11.1.5",
237
- "supertest": "^7.1.3",
235
+ "supertest": "^7.1.3",
238
236
  "ts-jest": "^29.4.5",
239
237
  "tslib": "^2.6.2",
240
238
  "typescript": "^5.3.2",
@@ -254,4 +252,4 @@
254
252
  "engines": {
255
253
  "node": ">=18.0.0"
256
254
  }
257
- }
255
+ }
@@ -1,205 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * OAuth2 Development Server - Simple token server for local testing
4
- *
5
- * WARNING: This is a DEVELOPMENT ONLY server. Do NOT use in production!
6
- *
7
- * Provides a minimal OAuth2 client credentials flow implementation
8
- * for local testing and development of Fame applications.
9
- *
10
- * Environment Variables:
11
- * - FAME_LOG_LEVEL: Log level (default: trace)
12
- * - APP_HOST: Server host (default: 0.0.0.0)
13
- * - APP_PORT: Server port (default: 8099)
14
- * - FAME_JWT_CLIENT_ID: Expected OAuth2 client ID
15
- * - FAME_JWT_CLIENT_SECRET: Expected OAuth2 client secret
16
- * - FAME_JWT_ISSUER: JWT issuer (default: https://oauth2-server)
17
- * - FAME_JWT_AUDIENCE: JWT audience (default: fame.fabric)
18
- * - FAME_JWT_ALGORITHM: JWT algorithm (default: EdDSA)
19
- */
20
- import Fastify from 'fastify';
21
- import formbody from '@fastify/formbody';
22
- import * as jose from 'jose';
23
- import { generateKeyPair } from 'crypto';
24
- import { promisify } from 'util';
25
- import { enableLogging, getLogger } from '../util/logging.js';
26
- const generateKeyPairAsync = promisify(generateKeyPair);
27
- const ENV_VAR_LOG_LEVEL = 'FAME_LOG_LEVEL';
28
- const ENV_VAR_CLIENT_ID = 'FAME_JWT_CLIENT_ID';
29
- const ENV_VAR_CLIENT_SECRET = 'FAME_JWT_CLIENT_SECRET';
30
- const ENV_VAR_JWT_ISSUER = 'FAME_JWT_ISSUER';
31
- const ENV_VAR_JWT_AUDIENCE = 'FAME_JWT_AUDIENCE';
32
- const ENV_VAR_JWT_ALGORITHM = 'FAME_JWT_ALGORITHM';
33
- const logger = getLogger('naylence.fame.fastapi.oauth2_server');
34
- // Global keypair for signing tokens
35
- let signingKey; // jose.KeyLike type not exported
36
- let publicKey; // jose.KeyLike type not exported
37
- let publicJWK;
38
- async function initializeKeys() {
39
- const algorithm = process.env[ENV_VAR_JWT_ALGORITHM] || 'EdDSA';
40
- if (algorithm === 'EdDSA') {
41
- const { privateKey, publicKey: pubKey } = await generateKeyPairAsync('ed25519', {
42
- privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
43
- publicKeyEncoding: { type: 'spki', format: 'pem' },
44
- });
45
- signingKey = await jose.importPKCS8(privateKey, 'EdDSA');
46
- publicKey = await jose.importSPKI(pubKey, 'EdDSA');
47
- publicJWK = await jose.exportJWK(publicKey);
48
- publicJWK.kid = 'dev-key-1';
49
- publicJWK.alg = 'EdDSA';
50
- publicJWK.use = 'sig';
51
- }
52
- else {
53
- // RS256 fallback
54
- const { privateKey, publicKey: pubKey } = await generateKeyPairAsync('rsa', {
55
- modulusLength: 2048,
56
- privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
57
- publicKeyEncoding: { type: 'spki', format: 'pem' },
58
- });
59
- signingKey = await jose.importPKCS8(privateKey, 'RS256');
60
- publicKey = await jose.importSPKI(pubKey, 'RS256');
61
- publicJWK = await jose.exportJWK(publicKey);
62
- publicJWK.kid = 'dev-key-1';
63
- publicJWK.alg = 'RS256';
64
- publicJWK.use = 'sig';
65
- }
66
- logger.info('oauth2_server_keys_initialized', { algorithm });
67
- }
68
- async function createApp() {
69
- await initializeKeys();
70
- const logLevel = (process.env[ENV_VAR_LOG_LEVEL] || 'info').toLowerCase();
71
- const fastify = Fastify({
72
- logger: {
73
- level: logLevel === 'trace' ? 'debug' : logLevel,
74
- },
75
- });
76
- // Register formbody plugin to parse application/x-www-form-urlencoded
77
- await fastify.register(formbody);
78
- const issuer = process.env[ENV_VAR_JWT_ISSUER] || 'https://oauth2-server';
79
- const audience = process.env[ENV_VAR_JWT_AUDIENCE] || 'fame.fabric';
80
- const algorithm = process.env[ENV_VAR_JWT_ALGORITHM] || 'EdDSA';
81
- const expectedClientId = process.env[ENV_VAR_CLIENT_ID];
82
- const expectedClientSecret = process.env[ENV_VAR_CLIENT_SECRET];
83
- // OAuth2 token endpoint
84
- fastify.post('/oauth/token', async (request, reply) => {
85
- const { grant_type, client_id, client_secret, scope } = request.body;
86
- // Validate grant type
87
- if (grant_type !== 'client_credentials') {
88
- return reply.status(400).send({
89
- error: 'unsupported_grant_type',
90
- error_description: 'Only client_credentials grant type is supported',
91
- });
92
- }
93
- // Validate client credentials
94
- if (!expectedClientId || !expectedClientSecret) {
95
- logger.error('oauth2_server_missing_credentials', {
96
- message: 'FAME_JWT_CLIENT_ID and FAME_JWT_CLIENT_SECRET must be set',
97
- });
98
- return reply.status(500).send({
99
- error: 'server_error',
100
- error_description: 'Server not configured properly',
101
- });
102
- }
103
- if (client_id !== expectedClientId ||
104
- client_secret !== expectedClientSecret) {
105
- return reply.status(401).send({
106
- error: 'invalid_client',
107
- error_description: 'Invalid client credentials',
108
- });
109
- }
110
- // Generate JWT
111
- const now = Math.floor(Date.now() / 1000);
112
- const expiresIn = 3600; // 1 hour
113
- const payload = {
114
- iss: issuer,
115
- sub: client_id,
116
- aud: audience,
117
- iat: now,
118
- exp: now + expiresIn,
119
- scope: scope || 'node.connect',
120
- };
121
- const token = await new jose.SignJWT(payload)
122
- .setProtectedHeader({ alg: algorithm, kid: 'dev-key-1' })
123
- .sign(signingKey);
124
- logger.debug('oauth2_token_issued', {
125
- client_id,
126
- scope: payload.scope,
127
- expires_in: expiresIn,
128
- });
129
- return {
130
- access_token: token,
131
- token_type: 'Bearer',
132
- expires_in: expiresIn,
133
- scope: payload.scope,
134
- };
135
- });
136
- // JWKS endpoint for public key distribution
137
- fastify.get('/.well-known/jwks.json', async () => {
138
- return {
139
- keys: [publicJWK],
140
- };
141
- });
142
- // OpenID configuration endpoint
143
- fastify.get('/.well-known/openid-configuration', async () => {
144
- const baseUrl = issuer;
145
- return {
146
- issuer: baseUrl,
147
- token_endpoint: `${baseUrl}/oauth/token`,
148
- jwks_uri: `${baseUrl}/.well-known/jwks.json`,
149
- grant_types_supported: ['client_credentials'],
150
- response_types_supported: ['token'],
151
- token_endpoint_auth_methods_supported: [
152
- 'client_secret_post',
153
- 'client_secret_basic',
154
- ],
155
- };
156
- });
157
- // Health check
158
- fastify.get('/health', async () => {
159
- return { status: 'healthy', service: 'oauth2-dev-server' };
160
- });
161
- return fastify;
162
- }
163
- async function main() {
164
- try {
165
- const logLevel = process.env[ENV_VAR_LOG_LEVEL] || 'trace';
166
- enableLogging(logLevel);
167
- const app = await createApp();
168
- const host = process.env.APP_HOST || '0.0.0.0';
169
- const port = parseInt(process.env.APP_PORT || '8099', 10);
170
- await app.listen({ host, port });
171
- logger.info('oauth2_dev_server_started', {
172
- host,
173
- port,
174
- logLevel,
175
- });
176
- console.log(`\n⚠️ OAuth2 Development Server (DO NOT USE IN PRODUCTION)`);
177
- console.log(`📍 Listening on http://${host}:${port}`);
178
- console.log(`🔑 Token endpoint: http://${host}:${port}/oauth/token`);
179
- console.log(`📜 JWKS endpoint: http://${host}:${port}/.well-known/jwks.json\n`);
180
- }
181
- catch (error) {
182
- logger.error('oauth2_dev_server_failed_to_start', {
183
- error: error instanceof Error ? error.message : String(error),
184
- });
185
- console.error('Failed to start OAuth2 Development Server:', error);
186
- process.exit(1);
187
- }
188
- }
189
- // Handle graceful shutdown
190
- process.on('SIGTERM', () => {
191
- logger.info('oauth2_dev_server_shutting_down', { signal: 'SIGTERM' });
192
- process.exit(0);
193
- });
194
- process.on('SIGINT', () => {
195
- logger.info('oauth2_dev_server_shutting_down', { signal: 'SIGINT' });
196
- process.exit(0);
197
- });
198
- // Start server if run directly
199
- if (import.meta.url === `file://${process.argv[1]}`) {
200
- main().catch((error) => {
201
- console.error('Fatal error:', error);
202
- process.exit(1);
203
- });
204
- }
205
- export { createApp };
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * OAuth2 Development Server - Simple token server for local testing
4
- *
5
- * WARNING: This is a DEVELOPMENT ONLY server. Do NOT use in production!
6
- *
7
- * Provides a minimal OAuth2 client credentials flow implementation
8
- * for local testing and development of Fame applications.
9
- *
10
- * Environment Variables:
11
- * - FAME_LOG_LEVEL: Log level (default: trace)
12
- * - APP_HOST: Server host (default: 0.0.0.0)
13
- * - APP_PORT: Server port (default: 8099)
14
- * - FAME_JWT_CLIENT_ID: Expected OAuth2 client ID
15
- * - FAME_JWT_CLIENT_SECRET: Expected OAuth2 client secret
16
- * - FAME_JWT_ISSUER: JWT issuer (default: https://oauth2-server)
17
- * - FAME_JWT_AUDIENCE: JWT audience (default: fame.fabric)
18
- * - FAME_JWT_ALGORITHM: JWT algorithm (default: EdDSA)
19
- */
20
- import type { FastifyInstance } from 'fastify';
21
- declare function createApp(): Promise<FastifyInstance>;
22
- export { createApp };