@naylence/runtime 0.3.5-test.911 → 0.3.5-test.914

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 +78 -166
  2. package/dist/browser/index.mjs +78 -166
  3. package/dist/cjs/naylence/fame/config/extended-fame-config.js +58 -2
  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 +58 -2
  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 +78 -166
  20. package/dist/node/index.mjs +78 -166
  21. package/dist/node/node.cjs +305 -251
  22. package/dist/node/node.mjs +305 -251
  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
@@ -7,21 +7,18 @@ import { x25519 } from '@noble/curves/ed25519.js';
7
7
  import { hkdf } from '@noble/hashes/hkdf.js';
8
8
  import { sha256, sha512 } from '@noble/hashes/sha2.js';
9
9
  import { utf8ToBytes, bytesToHex, randomBytes, concatBytes } from '@noble/hashes/utils.js';
10
- import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
11
- import { SubjectPublicKeyInfo, SubjectAlternativeName, GeneralName, Extensions, Extension, id_ce_subjectAltName, Attribute, AlgorithmIdentifier, AttributeTypeAndValue, AttributeValue, Name, RelativeDistinguishedName } from '@peculiar/asn1-x509';
12
- import { Attributes, CertificationRequestInfo, CertificationRequest } from '@peculiar/asn1-csr';
13
10
  import { parse } from 'yaml';
14
11
  import fastify from 'fastify';
15
12
  import websocketPlugin from '@fastify/websocket';
16
13
  import { sign, hashes, verify } from '@noble/ed25519';
17
14
 
18
15
  // This file is auto-generated during build - do not edit manually
19
- // Generated from package.json version: 0.3.5-test.911
16
+ // Generated from package.json version: 0.3.5-test.914
20
17
  /**
21
18
  * The package version, injected at build time.
22
19
  * @internal
23
20
  */
24
- const VERSION = '0.3.5-test.911';
21
+ const VERSION = '0.3.5-test.914';
25
22
 
26
23
  /**
27
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -13008,6 +13005,61 @@ const CONFIG_SEARCH_PATHS = [
13008
13005
  ];
13009
13006
  const fsModuleSpecifier = String.fromCharCode(102) + String.fromCharCode(115);
13010
13007
  let cachedFsModule = null;
13008
+ // Capture this module's URL without triggering TypeScript's import.meta restriction on CJS builds
13009
+ const currentModuleUrl = (() => {
13010
+ try {
13011
+ return (0, eval)('import.meta.url');
13012
+ }
13013
+ catch {
13014
+ return undefined;
13015
+ }
13016
+ })();
13017
+ let cachedNodeRequire = typeof require === 'function' ? require : null;
13018
+ function fileUrlToPath(url) {
13019
+ try {
13020
+ const parsed = new URL(url);
13021
+ if (parsed.protocol !== 'file:') {
13022
+ return null;
13023
+ }
13024
+ let pathname = parsed.pathname;
13025
+ if (typeof process !== 'undefined' &&
13026
+ process.platform === 'win32' &&
13027
+ pathname.startsWith('/')) {
13028
+ pathname = pathname.slice(1);
13029
+ }
13030
+ return decodeURIComponent(pathname);
13031
+ }
13032
+ catch {
13033
+ return null;
13034
+ }
13035
+ }
13036
+ function getNodeRequire() {
13037
+ if (cachedNodeRequire) {
13038
+ return cachedNodeRequire;
13039
+ }
13040
+ if (!isNode) {
13041
+ return null;
13042
+ }
13043
+ const processBinding = process.binding;
13044
+ if (typeof processBinding !== 'function') {
13045
+ return null;
13046
+ }
13047
+ try {
13048
+ const moduleWrap = processBinding('module_wrap');
13049
+ if (typeof moduleWrap?.createRequire !== 'function') {
13050
+ return null;
13051
+ }
13052
+ const modulePathFromUrl = currentModuleUrl
13053
+ ? fileUrlToPath(currentModuleUrl)
13054
+ : null;
13055
+ const requireSource = modulePathFromUrl ?? `${process.cwd()}/.naylence-require-shim.js`;
13056
+ cachedNodeRequire = moduleWrap.createRequire(requireSource);
13057
+ return cachedNodeRequire;
13058
+ }
13059
+ catch {
13060
+ return null;
13061
+ }
13062
+ }
13011
13063
  function getFsModule() {
13012
13064
  if (cachedFsModule) {
13013
13065
  return cachedFsModule;
@@ -13015,9 +13067,10 @@ function getFsModule() {
13015
13067
  if (!isNode) {
13016
13068
  throw new Error('File system access is not available in this environment');
13017
13069
  }
13018
- if (typeof require === 'function') {
13070
+ const nodeRequire = typeof require === 'function' ? require : getNodeRequire();
13071
+ if (nodeRequire) {
13019
13072
  try {
13020
- cachedFsModule = require(fsModuleSpecifier);
13073
+ cachedFsModule = nodeRequire(fsModuleSpecifier);
13021
13074
  return cachedFsModule;
13022
13075
  }
13023
13076
  catch (error) {
@@ -25393,11 +25446,6 @@ const DEFAULT_AUDIENCE = 'router-dev';
25393
25446
  const DEFAULT_TTL_SEC$1 = 3600;
25394
25447
  const DEFAULT_HMAC_SECRET_BYTES = 32;
25395
25448
  const ENCRYPTION_ALG = 'ECDH-ES';
25396
- const EXTENSION_REQUEST_OID = '1.2.840.113549.1.9.14';
25397
- const COMMON_NAME_OID = '2.5.4.3';
25398
- const ED25519_OID = '1.3.101.112';
25399
- const CSR_PEM_TAG = 'CERTIFICATE REQUEST';
25400
- const LOGICAL_URI_PREFIX = 'naylence://';
25401
25449
  function normalizeDefaultCryptoProviderOptions(options) {
25402
25450
  if (!options) {
25403
25451
  return {};
@@ -25663,76 +25711,6 @@ class DefaultCryptoProvider {
25663
25711
  has_chain: Boolean(certificateChainPem),
25664
25712
  });
25665
25713
  }
25666
- async createCsr(nodeId, physicalPath, logicals, subjectName) {
25667
- const trimmedNodeId = assertNonEmptyString(nodeId, 'nodeId');
25668
- const trimmedPhysicalPath = assertNonEmptyString(physicalPath, 'physicalPath');
25669
- try {
25670
- if (this.artifacts.signing.algorithm !== 'EdDSA') {
25671
- throw new Error('CSR creation only supported for Ed25519 signing keys in the default crypto provider');
25672
- }
25673
- const cryptoImpl = await ensureWebCrypto();
25674
- const privateKey = await cryptoImpl.subtle.importKey('pkcs8', pemToArrayBuffer(this.signingPrivatePem), {
25675
- name: 'Ed25519',
25676
- }, false, ['sign']);
25677
- const publicKeyDer = pemToArrayBuffer(this.signingPublicPem);
25678
- const subjectPkInfo = AsnConvert.parse(publicKeyDer, SubjectPublicKeyInfo);
25679
- const sanitizedLogicals = Array.isArray(logicals)
25680
- ? logicals.filter((value) => typeof value === 'string' && value.trim().length > 0)
25681
- : [];
25682
- const commonName = typeof subjectName === 'string' && subjectName.trim().length > 0
25683
- ? subjectName.trim()
25684
- : trimmedNodeId;
25685
- const subject = buildSubjectName(commonName);
25686
- const attributes = new Attributes();
25687
- if (sanitizedLogicals.length > 0) {
25688
- const san = new SubjectAlternativeName(sanitizedLogicals.map((logical) => new GeneralName({
25689
- uniformResourceIdentifier: `${LOGICAL_URI_PREFIX}${logical}`,
25690
- })));
25691
- const extensions = new Extensions([
25692
- new Extension({
25693
- extnID: id_ce_subjectAltName,
25694
- critical: false,
25695
- extnValue: new OctetString(AsnConvert.serialize(san)),
25696
- }),
25697
- ]);
25698
- attributes.push(new Attribute({
25699
- type: EXTENSION_REQUEST_OID,
25700
- values: [AsnConvert.serialize(extensions)],
25701
- }));
25702
- }
25703
- const requestInfo = new CertificationRequestInfo({
25704
- subject,
25705
- subjectPKInfo: subjectPkInfo,
25706
- attributes,
25707
- });
25708
- const requestInfoDer = AsnConvert.serialize(requestInfo);
25709
- const signature = await cryptoImpl.subtle.sign('Ed25519', privateKey, requestInfoDer);
25710
- const certificationRequest = new CertificationRequest({
25711
- certificationRequestInfo: requestInfo,
25712
- signatureAlgorithm: new AlgorithmIdentifier({
25713
- algorithm: ED25519_OID,
25714
- }),
25715
- signature: encodeBitString(signature),
25716
- });
25717
- certificationRequest.certificationRequestInfoRaw = requestInfoDer;
25718
- const csrDer = AsnConvert.serialize(certificationRequest);
25719
- const csrPem = arrayBufferToPem(csrDer, CSR_PEM_TAG);
25720
- logger$v.debug('csr_created', {
25721
- node_id: trimmedNodeId,
25722
- physical_path: trimmedPhysicalPath,
25723
- logical_count: sanitizedLogicals.length,
25724
- });
25725
- return csrPem;
25726
- }
25727
- catch (error) {
25728
- logger$v.error('csr_creation_failed', {
25729
- node_id: trimmedNodeId,
25730
- physical_path: trimmedPhysicalPath,
25731
- error: error instanceof Error ? error.message : String(error),
25732
- });
25733
- throw error;
25734
- }
25735
- }
25736
25714
  }
25737
25715
  async function buildProviderArtifacts(options) {
25738
25716
  const algorithm = normalizeAlgorithm(options.algorithm ?? readEnvAlgorithm());
@@ -25968,90 +25946,6 @@ function pemToDerBase64(pem) {
25968
25946
  // Ensure the output is valid base64 without whitespace
25969
25947
  return base64.replace(/\s+/g, '');
25970
25948
  }
25971
- let cryptoPromise = null;
25972
- async function ensureWebCrypto() {
25973
- if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto?.subtle) {
25974
- return globalThis.crypto;
25975
- }
25976
- if (!cryptoPromise) {
25977
- if (typeof process !== 'undefined' &&
25978
- typeof process.versions?.node === 'string') {
25979
- cryptoPromise = import('node:crypto').then((module) => {
25980
- const webcrypto = module.webcrypto;
25981
- if (!webcrypto || !webcrypto.subtle) {
25982
- throw new Error('WebCrypto API is not available in this Node.js runtime');
25983
- }
25984
- globalThis.crypto = webcrypto;
25985
- return webcrypto;
25986
- });
25987
- }
25988
- else {
25989
- cryptoPromise = Promise.reject(new Error('WebCrypto API is not available in this environment'));
25990
- }
25991
- }
25992
- return cryptoPromise;
25993
- }
25994
- function pemToArrayBuffer(pem) {
25995
- const normalized = pem
25996
- .replace(/-----BEGIN[^-]+-----/g, '')
25997
- .replace(/-----END[^-]+-----/g, '')
25998
- .replace(/\s+/g, '');
25999
- const bytes = base64ToBytes$1(normalized);
26000
- return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
26001
- }
26002
- function base64ToBytes$1(base64) {
26003
- if (typeof Buffer !== 'undefined') {
26004
- const buffer = Buffer.from(base64, 'base64');
26005
- const bytes = new Uint8Array(buffer.length);
26006
- for (let i = 0; i < buffer.length; i += 1) {
26007
- bytes[i] = buffer[i];
26008
- }
26009
- return bytes;
26010
- }
26011
- if (typeof atob === 'function') {
26012
- const binary = atob(base64);
26013
- const bytes = new Uint8Array(binary.length);
26014
- for (let i = 0; i < binary.length; i += 1) {
26015
- bytes[i] = binary.charCodeAt(i);
26016
- }
26017
- return bytes;
26018
- }
26019
- throw new Error('No base64 decoder available in this environment');
26020
- }
26021
- function arrayBufferToPem(buffer, tag) {
26022
- const base64 = bytesToBase64(new Uint8Array(buffer));
26023
- return `-----BEGIN ${tag}-----\n${formatPem(base64)}\n-----END ${tag}-----\n`;
26024
- }
26025
- function formatPem(base64) {
26026
- const lines = [];
26027
- for (let i = 0; i < base64.length; i += 64) {
26028
- lines.push(base64.slice(i, i + 64));
26029
- }
26030
- return lines.join('\n');
26031
- }
26032
- function encodeBitString(signature) {
26033
- const bytes = new Uint8Array(signature);
26034
- const bitString = new Uint8Array(bytes.length + 1);
26035
- bitString.set(bytes, 1);
26036
- return bitString.buffer;
26037
- }
26038
- function buildSubjectName(commonName) {
26039
- const attribute = new AttributeTypeAndValue({
26040
- type: COMMON_NAME_OID,
26041
- value: new AttributeValue({ utf8String: commonName }),
26042
- });
26043
- return new Name([new RelativeDistinguishedName([attribute])]);
26044
- }
26045
- function assertNonEmptyString(value, name) {
26046
- if (typeof value !== 'string') {
26047
- throw new TypeError(`${name} must be a string`);
26048
- }
26049
- const trimmed = value.trim();
26050
- if (trimmed.length === 0) {
26051
- throw new TypeError(`${name} must be a non-empty string`);
26052
- }
26053
- return trimmed;
26054
- }
26055
25949
  function cloneJson(value) {
26056
25950
  return JSON.parse(JSON.stringify(value));
26057
25951
  }
@@ -30499,6 +30393,8 @@ const ENV_VAR_DIRECT_INPAGE_CHANNEL = 'FAME_DIRECT_INPAGE_CHANNEL';
30499
30393
  const ENV_VAR_ADMISSION_SERVICE_URL = 'FAME_ADMISSION_SERVICE_URL';
30500
30394
  const DEFAULT_INPAGE_CHANNEL = 'naylence-fabric';
30501
30395
  const PROFILE_NAME_WELCOME = 'welcome';
30396
+ const PROFILE_NAME_WELCOME_PKCE = 'welcome-pkce';
30397
+ const PROFILE_NAME_WELCOME_PKCE_ALIAS = 'welcome_pkce';
30502
30398
  const PROFILE_NAME_DIRECT = 'direct';
30503
30399
  const PROFILE_NAME_DIRECT_HTTP = 'direct-http';
30504
30400
  const PROFILE_NAME_DIRECT_INPAGE = 'direct-inpage';
@@ -30559,6 +30455,7 @@ function createOAuthPkceTokenProviderConfig() {
30559
30455
  }
30560
30456
  const welcomeIsRoot = Expressions.env(ENV_VAR_IS_ROOT, 'false');
30561
30457
  const welcomeTokenProvider = createOAuthTokenProviderConfig();
30458
+ const welcomePkceTokenProvider = createOAuthPkceTokenProviderConfig();
30562
30459
  const WELCOME_SERVICE_PROFILE = {
30563
30460
  type: 'WelcomeServiceClient',
30564
30461
  is_root: welcomeIsRoot,
@@ -30572,6 +30469,19 @@ const WELCOME_SERVICE_PROFILE = {
30572
30469
  tokenProvider: welcomeTokenProvider,
30573
30470
  },
30574
30471
  };
30472
+ const WELCOME_SERVICE_PKCE_PROFILE = {
30473
+ type: 'WelcomeServiceClient',
30474
+ is_root: welcomeIsRoot,
30475
+ isRoot: welcomeIsRoot,
30476
+ url: Expressions.env(ENV_VAR_ADMISSION_SERVICE_URL),
30477
+ supported_transports: ['websocket'],
30478
+ supportedTransports: ['websocket'],
30479
+ auth: {
30480
+ type: 'BearerTokenHeaderAuth',
30481
+ token_provider: welcomePkceTokenProvider,
30482
+ tokenProvider: welcomePkceTokenProvider,
30483
+ },
30484
+ };
30575
30485
  const directGrantTokenProvider = createOAuthTokenProviderConfig();
30576
30486
  const directGrant = {
30577
30487
  type: 'WebSocketConnectionGrant',
@@ -30677,6 +30587,8 @@ const NOOP_PROFILE = {
30677
30587
  };
30678
30588
  const PROFILE_MAP$1 = {
30679
30589
  [PROFILE_NAME_WELCOME]: WELCOME_SERVICE_PROFILE,
30590
+ [PROFILE_NAME_WELCOME_PKCE]: WELCOME_SERVICE_PKCE_PROFILE,
30591
+ [PROFILE_NAME_WELCOME_PKCE_ALIAS]: WELCOME_SERVICE_PKCE_PROFILE,
30680
30592
  [PROFILE_NAME_DIRECT]: DIRECT_PROFILE,
30681
30593
  [PROFILE_NAME_DIRECT_PKCE]: DIRECT_PKCE_PROFILE,
30682
30594
  [PROFILE_NAME_DIRECT_PKCE_ALIAS]: DIRECT_PKCE_PROFILE,