@interopio/gateway-server 0.6.0-beta → 0.6.1-beta
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/changelog.md +8 -0
- package/dist/gateway-ent.cjs +1 -0
- package/dist/gateway-ent.cjs.map +2 -2
- package/dist/gateway-ent.js +1 -0
- package/dist/gateway-ent.js.map +2 -2
- package/dist/index.cjs +18 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +18 -16
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
# Change Log
|
|
4
4
|
|
|
5
|
+
## 0.6.1-beta (2025-07-18)
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- `gateway-ent` should not require authenticated access to the `gw` route
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- `Server` header now includes the version of the package
|
|
12
|
+
|
|
5
13
|
## 0.6.0-beta (2025-07-18)
|
|
6
14
|
|
|
7
15
|
### Added
|
package/dist/gateway-ent.cjs
CHANGED
|
@@ -266,6 +266,7 @@ function toServerConfig(config) {
|
|
|
266
266
|
route: config.route,
|
|
267
267
|
limits: config.limits,
|
|
268
268
|
origins: config.security?.origin_filters,
|
|
269
|
+
authorize: config["authorize"] ?? { access: "permitted" },
|
|
269
270
|
clients: config["clients"] ?? { inactive_seconds: 0, buffer_size: 100 },
|
|
270
271
|
contexts: {
|
|
271
272
|
lifetime: "retained",
|
package/dist/gateway-ent.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/gateway/ent/index.ts", "../src/gateway/ent/logging.ts", "../src/gateway/ent/server.ts", "../src/gateway/ent/config.ts"],
|
|
4
|
-
"sourcesContent": ["import {toLogConfig} from './logging.js';\nimport {ServerDelegate} from './server.js';\nimport {toServerConfig} from './config.js';\nimport {\n Gateway,\n GatewayConfig,\n LogInfo,\n LogLevel\n} from '../../../types/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\n\nexport function create(config: GatewayConfig): Gateway {\n return new ServerDelegate(toServerConfig(config));\n}\n\nexport function configure_logging(config?: { level: LogLevel, appender?: (info: LogInfo) => void }) {\n IOGateway.Logging.configure(toLogConfig(config));\n}\n", "import {LogInfo, LogLevel} from '@interopio/gateway-server/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\nimport {format} from 'node:util';\n\nclass LogInfoAdapter implements LogInfo {\n private _parsed?: { err?: Error, msg: string };\n private _timestamp?: string;\n private _output?: string;\n\n constructor(private readonly event: IOGateway.Logging.LogEvent) {\n }\n\n private parsed(): { err?: Error, msg: string } {\n if (this._parsed === undefined) {\n let err: Error | undefined = undefined;\n let vargs = this.event.data;\n if (this.event.data[0] instanceof Error) {\n err = this.event.data[0];\n vargs = vargs.slice(1);\n }\n const msg = format(this.event.message, ...vargs);\n this._parsed = {err, msg};\n }\n return this._parsed;\n }\n\n get time(): Date {\n return this.event.time;\n }\n\n get level(): LogLevel {\n return this.event.level;\n }\n\n get namespace() {\n return this.event.name;\n }\n\n get file(): string {\n return undefined as unknown as string;\n }\n\n get line(): number {\n return undefined as unknown as number;\n }\n\n get message(): string {\n return this.parsed().msg;\n }\n\n get stacktrace(): Error | undefined {\n return this.parsed().err;\n }\n\n private get timestamp(): string {\n if (this._timestamp === undefined) {\n this._timestamp = this.time.toISOString();\n }\n return this._timestamp;\n }\n\n get output(): string {\n if (this._output === undefined) {\n const err = this.parsed().err;\n const stacktrace = err ? `\\n${err.stack ?? err}` : '';\n this._output = `${this.timestamp} ${this.level.toUpperCase()} [${this.namespace}] - ${this.message}${stacktrace}`;\n }\n return this._output;\n }\n}\n\nexport function toLogConfig(config?: { level?: LogLevel; appender?: (info: LogInfo) => void }): IOGateway.Logging.LogConfig {\n let level: Exclude<LogLevel, 'report' | 'fatal'> = 'info';\n if (config?.level) {\n if (config.level === 'fatal') {\n level = 'error';\n } else if (config.level !== 'report') {\n level = config.level;\n }\n }\n const result: IOGateway.Logging.LogConfig = {level};\n const appenderFn = config?.appender;\n if (appenderFn) {\n result.appender = (event: IOGateway.Logging.LogEvent) => {\n appenderFn(new LogInfoAdapter(event));\n };\n }\n return result;\n}\n", "import {Gateway, GatewayClient, GatewayMessage} from '@interopio/gateway-server/gateway-ent';\nimport {GatewayServer} from '@interopio/gateway-server';\n\nexport class ServerDelegate implements Gateway {\n private server?: GatewayServer.Server;\n\n constructor(private readonly config: GatewayServer.ServerConfig) {\n }\n\n async connect(cb: (client: GatewayClient, msg: GatewayMessage) => void): Promise<GatewayClient> {\n if (!this.server) {\n throw new Error(`not started`);\n }\n const client = await this.server.gateway.connect((c, m) => cb(c as unknown as GatewayClient, m as GatewayMessage));\n return client as unknown as GatewayClient;\n }\n\n info(): { endpoint: string } {\n return this.server?.gateway.info() as { endpoint: string };\n }\n\n async start(): Promise<Gateway> {\n if (!this.server) {\n this.server = await GatewayServer.Factory(this.config);\n }\n return this;\n }\n\n async stop(): Promise<Gateway> {\n await this.server?.close();\n delete this.server;\n return this;\n }\n}\n", "import {GatewayServer} from '../../../gateway-server';\nimport {IOGateway} from '@interopio/gateway';\nimport { GatewayConfig, MetricsPublisherConfig } from '../../../types/gateway-ent';\n\nfunction toMetricsFilters(legacy?: MetricsPublisherConfig['filters']): IOGateway.MetricFilters | undefined {\n if (legacy) {\n const publishers = legacy.publishers.map(publisher => {\n return {identity: publisher.publisher, metrics: publisher.metrics};\n });\n const non_matched = legacy['non-matched'];\n return {publishers, non_matched};\n }\n}\n\nfunction toMetricsPublisherConfig(legacy: MetricsPublisherConfig & {\n conflation?: { 'max-datapoints-repo'?: number } & MetricsPublisherConfig['conflation']\n}): IOGateway.BasicMetricsPublisherConfig {\n const filters = toMetricsFilters(legacy?.filters);\n const conflation = toConflation(legacy?.conflation);\n return {...legacy, filters, conflation};\n}\n\nfunction toConflation(legacy?: {\n 'max-datapoints-repo'?: number\n} & MetricsPublisherConfig['conflation']): IOGateway.BasicMetricsPublisherConfig['conflation'] | undefined {\n if (legacy) {\n return {interval: legacy.interval};\n }\n}\n\nfunction toMetricsConfig(legacy: GatewayConfig['metrics']): IOGateway.GatewayConfig['metrics'] {\n const metrics: IOGateway.GatewayConfig['metrics'] = {publishers: []};\n legacy?.publishers?.forEach((publisher) => {\n if (typeof publisher === 'string') {\n if (publisher === 'rest') {\n metrics.publishers.push('rest');\n if (legacy.rest) {\n const conf = {...legacy.rest};\n const userAgent = conf[\"user-agent\"];\n delete conf['user-agent'];\n const headers = {...conf.headers, ...(userAgent ? {'user-agent': userAgent} : {})};\n delete conf.headers;\n metrics.rest = {\n endpoint: conf.endpoint,\n headers: headers,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.rest['publishFn'] ??= '@interopio/gateway-server/metrics/publisher/rest';\n }\n } else if (publisher === 'file') {\n metrics.publishers.push('file');\n if (legacy.file) {\n const conf = {...legacy.file};\n const status = conf['skip-status'] === undefined ? true : !conf['skip-status'];\n delete conf['skip-status'];\n metrics.file = {\n location: conf.location,\n status: status,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.file['publishFn'] ??= '@interopio/gateway/metrics/publisher/file';\n }\n } else {\n // unsupported predefined type\n }\n } else {\n const configuration = {...publisher.configuration};\n const splitSize = configuration[\"split-size\"];\n delete configuration[\"split-size\"];\n const file = publisher['file'] as string;\n const custom: IOGateway.CustomMetricsPublisherConfig = {\n split_size: splitSize,\n publisher: {file, configuration},\n ...toMetricsPublisherConfig(configuration)\n }\n metrics.publishers.push(custom);\n }\n });\n if (legacy?.filters) {\n metrics.filters = toMetricsFilters(legacy?.filters);\n }\n return metrics;\n}\ntype GatewayCluster = Required<GatewayConfig>['cluster'];\ntype P2P = Required<GatewayCluster>['p2p'];\n\nfunction trimTrailingSlash(url?: string): string | undefined {\n return url?.endsWith('/') ? url.slice(0, -1) : url;\n}\n\nfunction toCluster(legacy?: P2P): IOGateway.MeshConfig['cluster'] | undefined {\n if (legacy?.directory) {\n const legacyDirectory = legacy.directory;\n const config: IOGateway.MeshConfig['cluster'] = {endpoint: legacy?.['endpoint']};\n if (legacyDirectory.type === 'rest') {\n let directory: IOGateway.RestMeshDirectoryConfig | undefined = undefined;\n if (config.endpoint === undefined) {\n config.endpoint = trimTrailingSlash(legacyDirectory.config?.directory_uri)!;\n }\n else {\n directory = {uri: trimTrailingSlash(legacyDirectory.config?.directory_uri)};\n }\n if (legacyDirectory.config?.announce_interval) {\n directory ??= {};\n directory.interval = Number(legacyDirectory.config.announce_interval);\n }\n if (directory !== undefined) {\n config.directory = directory;\n }\n return config;\n }\n else if (legacyDirectory.type === 'static') {\n config.directory = {members : legacyDirectory.members ?? []};\n return config;\n }\n }\n}\n\nfunction toMeshConfig(legacy: GatewayConfig['cluster']) {\n const mesh: IOGateway.MeshConfig = {};\n if (legacy?.configuration?.node_id) mesh.node = legacy.configuration.node_id;\n if (legacy?.type === 'broker') mesh.broker = {endpoint: legacy.broker!.endpoint!};\n if (legacy?.type === 'p2p') {\n const cluster = toCluster(legacy.p2p);\n if (cluster) {\n mesh.cluster = cluster;\n }\n }\n return mesh;\n}\n\nfunction toAuthenticationConfig(legacy: GatewayConfig['authentication']): IOGateway.AuthenticationConfig {\n const authentication: IOGateway.AuthenticationConfig & {available: string[]} = {available: []};\n if (legacy?.default) {\n authentication.default = legacy.default as string;\n }\n\n const as = legacy?.available as string[];\n as.forEach((a) => {\n if (a === 'basic' || a === 'oauth2' || legacy?.[a]?.['authenticator'] !== undefined) {\n authentication.available.push(a);\n if (legacy?.[a] !== undefined) {\n authentication[a] = legacy[a];\n }\n }\n });\n\n return authentication;\n}\nexport function toServerConfig(config: GatewayConfig): GatewayServer.ServerConfig {\n const gateway: GatewayServer.ServerConfig[\"gateway\"] = {\n route: config.route,\n limits: config.limits,\n origins: config.security?.origin_filters as GatewayServer.OriginFilters,\n clients: config['clients'] ?? {inactive_seconds: 0, buffer_size: 100},\n contexts: {\n lifetime: 'retained',\n visibility: [\n {context: /___channel___.+/, restrictions: 'cluster'},\n {context: /T42\\..+/, restrictions: 'local'}\n ]\n },\n methods: {\n visibility: [\n {method: /T42\\..+/, restrictions: 'local'}\n ]\n },\n peers: {\n visibility: [\n {domain: 'context', restrictions: 'cluster'},\n {domain: 'agm', restrictions: 'local'}\n ]\n },\n metrics: {publishers: []}\n };\n if (config.authentication !== undefined) {\n if (config.authentication.token_ttl) gateway.token = {ttl: config.authentication?.token_ttl as number};\n if (config.authentication.available || config.authentication.default) gateway.authentication = toAuthenticationConfig(config.authentication);\n }\n if (config['globals']) {\n gateway.globals = config['globals'];\n }\n if (config['contexts']) {\n gateway.contexts = config['contexts'];\n }\n if (config['methods']) {\n gateway.methods = config['methods'];\n }\n if (config['peers']) {\n gateway.peers = config['peers'];\n }\n if (config.cluster?.enabled) {\n gateway.mesh = toMeshConfig(config.cluster);\n\n }\n if (config.metrics?.publishers) gateway.metrics = toMetricsConfig(config.metrics);\n return {\n port: config.port ?? 3434,\n host: config.ip ?? config['host'] as string,\n memory: config['memory'],\n gateway: gateway\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,uBAAqB;AAErB,IAAM,iBAAN,MAAwC;AAAA,EAKpC,YAA6B,OAAmC;AAAnC;AAAA,EAC7B;AAAA,EALQ;AAAA,EACA;AAAA,EACA;AAAA,EAKA,SAAuC;AAC3C,QAAI,KAAK,YAAY,QAAW;AAC5B,UAAI,MAAyB;AAC7B,UAAI,QAAQ,KAAK,MAAM;AACvB,UAAI,KAAK,MAAM,KAAK,CAAC,aAAa,OAAO;AACrC,cAAM,KAAK,MAAM,KAAK,CAAC;AACvB,gBAAQ,MAAM,MAAM,CAAC;AAAA,MACzB;AACA,YAAM,UAAM,yBAAO,KAAK,MAAM,SAAS,GAAG,KAAK;AAC/C,WAAK,UAAU,EAAC,KAAK,IAAG;AAAA,IAC5B;AACA,WAAO,KAAK;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,MAAI,OAAO,SAAS,GAAG;AACnB,YAAQ,UAAU,OAAO,SAAS;AAAA,EACtC;AACA,MAAI,OAAO,UAAU,GAAG;AACpB,YAAQ,WAAW,OAAO,UAAU;AAAA,EACxC;AACA,MAAI,OAAO,SAAS,GAAG;AACnB,YAAQ,UAAU,OAAO,SAAS;AAAA,EACtC;AACA,MAAI,OAAO,OAAO,GAAG;AACjB,YAAQ,QAAQ,OAAO,OAAO;AAAA,EAClC;AACA,MAAI,OAAO,SAAS,SAAS;AACzB,YAAQ,OAAO,aAAa,OAAO,OAAO;AAAA,EAE9C;AACA,MAAI,OAAO,SAAS,WAAY,SAAQ,UAAU,gBAAgB,OAAO,OAAO;AAChF,SAAO;AAAA,IACH,MAAM,OAAO,QAAQ;AAAA,IACrB,MAAM,OAAO,MAAM,OAAO,MAAM;AAAA,IAChC,QAAQ,OAAO,QAAQ;AAAA,IACvB;AAAA,EACJ;AACJ;;;
|
|
4
|
+
"sourcesContent": ["import {toLogConfig} from './logging.js';\nimport {ServerDelegate} from './server.js';\nimport {toServerConfig} from './config.js';\nimport {\n Gateway,\n GatewayConfig,\n LogInfo,\n LogLevel\n} from '../../../types/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\n\nexport function create(config: GatewayConfig): Gateway {\n return new ServerDelegate(toServerConfig(config));\n}\n\nexport function configure_logging(config?: { level: LogLevel, appender?: (info: LogInfo) => void }) {\n IOGateway.Logging.configure(toLogConfig(config));\n}\n", "import {LogInfo, LogLevel} from '@interopio/gateway-server/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\nimport {format} from 'node:util';\n\nclass LogInfoAdapter implements LogInfo {\n private _parsed?: { err?: Error, msg: string };\n private _timestamp?: string;\n private _output?: string;\n\n constructor(private readonly event: IOGateway.Logging.LogEvent) {\n }\n\n private parsed(): { err?: Error, msg: string } {\n if (this._parsed === undefined) {\n let err: Error | undefined = undefined;\n let vargs = this.event.data;\n if (this.event.data[0] instanceof Error) {\n err = this.event.data[0];\n vargs = vargs.slice(1);\n }\n const msg = format(this.event.message, ...vargs);\n this._parsed = {err, msg};\n }\n return this._parsed;\n }\n\n get time(): Date {\n return this.event.time;\n }\n\n get level(): LogLevel {\n return this.event.level;\n }\n\n get namespace() {\n return this.event.name;\n }\n\n get file(): string {\n return undefined as unknown as string;\n }\n\n get line(): number {\n return undefined as unknown as number;\n }\n\n get message(): string {\n return this.parsed().msg;\n }\n\n get stacktrace(): Error | undefined {\n return this.parsed().err;\n }\n\n private get timestamp(): string {\n if (this._timestamp === undefined) {\n this._timestamp = this.time.toISOString();\n }\n return this._timestamp;\n }\n\n get output(): string {\n if (this._output === undefined) {\n const err = this.parsed().err;\n const stacktrace = err ? `\\n${err.stack ?? err}` : '';\n this._output = `${this.timestamp} ${this.level.toUpperCase()} [${this.namespace}] - ${this.message}${stacktrace}`;\n }\n return this._output;\n }\n}\n\nexport function toLogConfig(config?: { level?: LogLevel; appender?: (info: LogInfo) => void }): IOGateway.Logging.LogConfig {\n let level: Exclude<LogLevel, 'report' | 'fatal'> = 'info';\n if (config?.level) {\n if (config.level === 'fatal') {\n level = 'error';\n } else if (config.level !== 'report') {\n level = config.level;\n }\n }\n const result: IOGateway.Logging.LogConfig = {level};\n const appenderFn = config?.appender;\n if (appenderFn) {\n result.appender = (event: IOGateway.Logging.LogEvent) => {\n appenderFn(new LogInfoAdapter(event));\n };\n }\n return result;\n}\n", "import {Gateway, GatewayClient, GatewayMessage} from '@interopio/gateway-server/gateway-ent';\nimport {GatewayServer} from '@interopio/gateway-server';\n\nexport class ServerDelegate implements Gateway {\n private server?: GatewayServer.Server;\n\n constructor(private readonly config: GatewayServer.ServerConfig) {\n }\n\n async connect(cb: (client: GatewayClient, msg: GatewayMessage) => void): Promise<GatewayClient> {\n if (!this.server) {\n throw new Error(`not started`);\n }\n const client = await this.server.gateway.connect((c, m) => cb(c as unknown as GatewayClient, m as GatewayMessage));\n return client as unknown as GatewayClient;\n }\n\n info(): { endpoint: string } {\n return this.server?.gateway.info() as { endpoint: string };\n }\n\n async start(): Promise<Gateway> {\n if (!this.server) {\n this.server = await GatewayServer.Factory(this.config);\n }\n return this;\n }\n\n async stop(): Promise<Gateway> {\n await this.server?.close();\n delete this.server;\n return this;\n }\n}\n", "import {GatewayServer} from '../../../gateway-server';\nimport {IOGateway} from '@interopio/gateway';\nimport { GatewayConfig, MetricsPublisherConfig } from '../../../types/gateway-ent';\n\nfunction toMetricsFilters(legacy?: MetricsPublisherConfig['filters']): IOGateway.MetricFilters | undefined {\n if (legacy) {\n const publishers = legacy.publishers.map(publisher => {\n return {identity: publisher.publisher, metrics: publisher.metrics};\n });\n const non_matched = legacy['non-matched'];\n return {publishers, non_matched};\n }\n}\n\nfunction toMetricsPublisherConfig(legacy: MetricsPublisherConfig & {\n conflation?: { 'max-datapoints-repo'?: number } & MetricsPublisherConfig['conflation']\n}): IOGateway.BasicMetricsPublisherConfig {\n const filters = toMetricsFilters(legacy?.filters);\n const conflation = toConflation(legacy?.conflation);\n return {...legacy, filters, conflation};\n}\n\nfunction toConflation(legacy?: {\n 'max-datapoints-repo'?: number\n} & MetricsPublisherConfig['conflation']): IOGateway.BasicMetricsPublisherConfig['conflation'] | undefined {\n if (legacy) {\n return {interval: legacy.interval};\n }\n}\n\nfunction toMetricsConfig(legacy: GatewayConfig['metrics']): IOGateway.GatewayConfig['metrics'] {\n const metrics: IOGateway.GatewayConfig['metrics'] = {publishers: []};\n legacy?.publishers?.forEach((publisher) => {\n if (typeof publisher === 'string') {\n if (publisher === 'rest') {\n metrics.publishers.push('rest');\n if (legacy.rest) {\n const conf = {...legacy.rest};\n const userAgent = conf[\"user-agent\"];\n delete conf['user-agent'];\n const headers = {...conf.headers, ...(userAgent ? {'user-agent': userAgent} : {})};\n delete conf.headers;\n metrics.rest = {\n endpoint: conf.endpoint,\n headers: headers,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.rest['publishFn'] ??= '@interopio/gateway-server/metrics/publisher/rest';\n }\n } else if (publisher === 'file') {\n metrics.publishers.push('file');\n if (legacy.file) {\n const conf = {...legacy.file};\n const status = conf['skip-status'] === undefined ? true : !conf['skip-status'];\n delete conf['skip-status'];\n metrics.file = {\n location: conf.location,\n status: status,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.file['publishFn'] ??= '@interopio/gateway/metrics/publisher/file';\n }\n } else {\n // unsupported predefined type\n }\n } else {\n const configuration = {...publisher.configuration};\n const splitSize = configuration[\"split-size\"];\n delete configuration[\"split-size\"];\n const file = publisher['file'] as string;\n const custom: IOGateway.CustomMetricsPublisherConfig = {\n split_size: splitSize,\n publisher: {file, configuration},\n ...toMetricsPublisherConfig(configuration)\n }\n metrics.publishers.push(custom);\n }\n });\n if (legacy?.filters) {\n metrics.filters = toMetricsFilters(legacy?.filters);\n }\n return metrics;\n}\ntype GatewayCluster = Required<GatewayConfig>['cluster'];\ntype P2P = Required<GatewayCluster>['p2p'];\n\nfunction trimTrailingSlash(url?: string): string | undefined {\n return url?.endsWith('/') ? url.slice(0, -1) : url;\n}\n\nfunction toCluster(legacy?: P2P): IOGateway.MeshConfig['cluster'] | undefined {\n if (legacy?.directory) {\n const legacyDirectory = legacy.directory;\n const config: IOGateway.MeshConfig['cluster'] = {endpoint: legacy?.['endpoint']};\n if (legacyDirectory.type === 'rest') {\n let directory: IOGateway.RestMeshDirectoryConfig | undefined = undefined;\n if (config.endpoint === undefined) {\n config.endpoint = trimTrailingSlash(legacyDirectory.config?.directory_uri)!;\n }\n else {\n directory = {uri: trimTrailingSlash(legacyDirectory.config?.directory_uri)};\n }\n if (legacyDirectory.config?.announce_interval) {\n directory ??= {};\n directory.interval = Number(legacyDirectory.config.announce_interval);\n }\n if (directory !== undefined) {\n config.directory = directory;\n }\n return config;\n }\n else if (legacyDirectory.type === 'static') {\n config.directory = {members : legacyDirectory.members ?? []};\n return config;\n }\n }\n}\n\nfunction toMeshConfig(legacy: GatewayConfig['cluster']) {\n const mesh: IOGateway.MeshConfig = {};\n if (legacy?.configuration?.node_id) mesh.node = legacy.configuration.node_id;\n if (legacy?.type === 'broker') mesh.broker = {endpoint: legacy.broker!.endpoint!};\n if (legacy?.type === 'p2p') {\n const cluster = toCluster(legacy.p2p);\n if (cluster) {\n mesh.cluster = cluster;\n }\n }\n return mesh;\n}\n\nfunction toAuthenticationConfig(legacy: GatewayConfig['authentication']): IOGateway.AuthenticationConfig {\n const authentication: IOGateway.AuthenticationConfig & {available: string[]} = {available: []};\n if (legacy?.default) {\n authentication.default = legacy.default as string;\n }\n\n const as = legacy?.available as string[];\n as.forEach((a) => {\n if (a === 'basic' || a === 'oauth2' || legacy?.[a]?.['authenticator'] !== undefined) {\n authentication.available.push(a);\n if (legacy?.[a] !== undefined) {\n authentication[a] = legacy[a];\n }\n }\n });\n\n return authentication;\n}\nexport function toServerConfig(config: GatewayConfig): GatewayServer.ServerConfig {\n const gateway: GatewayServer.ServerConfig[\"gateway\"] = {\n route: config.route,\n limits: config.limits,\n origins: config.security?.origin_filters as GatewayServer.OriginFilters,\n authorize: config['authorize'] as GatewayServer.AuthorizationRule ?? {access: 'permitted'},\n clients: config['clients'] ?? {inactive_seconds: 0, buffer_size: 100},\n contexts: {\n lifetime: 'retained',\n visibility: [\n {context: /___channel___.+/, restrictions: 'cluster'},\n {context: /T42\\..+/, restrictions: 'local'}\n ]\n },\n methods: {\n visibility: [\n {method: /T42\\..+/, restrictions: 'local'}\n ]\n },\n peers: {\n visibility: [\n {domain: 'context', restrictions: 'cluster'},\n {domain: 'agm', restrictions: 'local'}\n ]\n },\n metrics: {publishers: []}\n };\n if (config.authentication !== undefined) {\n if (config.authentication.token_ttl) gateway.token = {ttl: config.authentication?.token_ttl as number};\n if (config.authentication.available || config.authentication.default) gateway.authentication = toAuthenticationConfig(config.authentication);\n }\n if (config['globals']) {\n gateway.globals = config['globals'];\n }\n if (config['contexts']) {\n gateway.contexts = config['contexts'];\n }\n if (config['methods']) {\n gateway.methods = config['methods'];\n }\n if (config['peers']) {\n gateway.peers = config['peers'];\n }\n if (config.cluster?.enabled) {\n gateway.mesh = toMeshConfig(config.cluster);\n\n }\n if (config.metrics?.publishers) gateway.metrics = toMetricsConfig(config.metrics);\n return {\n port: config.port ?? 3434,\n host: config.ip ?? config['host'] as string,\n memory: config['memory'],\n gateway: gateway\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,uBAAqB;AAErB,IAAM,iBAAN,MAAwC;AAAA,EAKpC,YAA6B,OAAmC;AAAnC;AAAA,EAC7B;AAAA,EALQ;AAAA,EACA;AAAA,EACA;AAAA,EAKA,SAAuC;AAC3C,QAAI,KAAK,YAAY,QAAW;AAC5B,UAAI,MAAyB;AAC7B,UAAI,QAAQ,KAAK,MAAM;AACvB,UAAI,KAAK,MAAM,KAAK,CAAC,aAAa,OAAO;AACrC,cAAM,KAAK,MAAM,KAAK,CAAC;AACvB,gBAAQ,MAAM,MAAM,CAAC;AAAA,MACzB;AACA,YAAM,UAAM,yBAAO,KAAK,MAAM,SAAS,GAAG,KAAK;AAC/C,WAAK,UAAU,EAAC,KAAK,IAAG;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,OAAa;AACb,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,QAAkB;AAClB,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,YAAY;AACZ,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,OAAe;AACf,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,OAAe;AACf,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,UAAkB;AAClB,WAAO,KAAK,OAAO,EAAE;AAAA,EACzB;AAAA,EAEA,IAAI,aAAgC;AAChC,WAAO,KAAK,OAAO,EAAE;AAAA,EACzB;AAAA,EAEA,IAAY,YAAoB;AAC5B,QAAI,KAAK,eAAe,QAAW;AAC/B,WAAK,aAAa,KAAK,KAAK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H,MAAM,OAAO,QAAQ;AAAA,IACrB,MAAM,OAAO,MAAM,OAAO,MAAM;AAAA,IAChC,QAAQ,OAAO,QAAQ;AAAA,IACvB;AAAA,EACJ;AACJ;;;AHlMA,qBAAwB;AAEjB,SAAS,OAAO,QAAgC;AACnD,SAAO,IAAI,eAAe,eAAe,MAAM,CAAC;AACpD;AAEO,SAAS,kBAAkB,QAAkE;AAChG,2BAAU,QAAQ,UAAU,YAAY,MAAM,CAAC;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/gateway-ent.js
CHANGED
|
@@ -239,6 +239,7 @@ function toServerConfig(config) {
|
|
|
239
239
|
route: config.route,
|
|
240
240
|
limits: config.limits,
|
|
241
241
|
origins: config.security?.origin_filters,
|
|
242
|
+
authorize: config["authorize"] ?? { access: "permitted" },
|
|
242
243
|
clients: config["clients"] ?? { inactive_seconds: 0, buffer_size: 100 },
|
|
243
244
|
contexts: {
|
|
244
245
|
lifetime: "retained",
|
package/dist/gateway-ent.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/gateway/ent/logging.ts", "../src/gateway/ent/server.ts", "../src/gateway/ent/config.ts", "../src/gateway/ent/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {LogInfo, LogLevel} from '@interopio/gateway-server/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\nimport {format} from 'node:util';\n\nclass LogInfoAdapter implements LogInfo {\n private _parsed?: { err?: Error, msg: string };\n private _timestamp?: string;\n private _output?: string;\n\n constructor(private readonly event: IOGateway.Logging.LogEvent) {\n }\n\n private parsed(): { err?: Error, msg: string } {\n if (this._parsed === undefined) {\n let err: Error | undefined = undefined;\n let vargs = this.event.data;\n if (this.event.data[0] instanceof Error) {\n err = this.event.data[0];\n vargs = vargs.slice(1);\n }\n const msg = format(this.event.message, ...vargs);\n this._parsed = {err, msg};\n }\n return this._parsed;\n }\n\n get time(): Date {\n return this.event.time;\n }\n\n get level(): LogLevel {\n return this.event.level;\n }\n\n get namespace() {\n return this.event.name;\n }\n\n get file(): string {\n return undefined as unknown as string;\n }\n\n get line(): number {\n return undefined as unknown as number;\n }\n\n get message(): string {\n return this.parsed().msg;\n }\n\n get stacktrace(): Error | undefined {\n return this.parsed().err;\n }\n\n private get timestamp(): string {\n if (this._timestamp === undefined) {\n this._timestamp = this.time.toISOString();\n }\n return this._timestamp;\n }\n\n get output(): string {\n if (this._output === undefined) {\n const err = this.parsed().err;\n const stacktrace = err ? `\\n${err.stack ?? err}` : '';\n this._output = `${this.timestamp} ${this.level.toUpperCase()} [${this.namespace}] - ${this.message}${stacktrace}`;\n }\n return this._output;\n }\n}\n\nexport function toLogConfig(config?: { level?: LogLevel; appender?: (info: LogInfo) => void }): IOGateway.Logging.LogConfig {\n let level: Exclude<LogLevel, 'report' | 'fatal'> = 'info';\n if (config?.level) {\n if (config.level === 'fatal') {\n level = 'error';\n } else if (config.level !== 'report') {\n level = config.level;\n }\n }\n const result: IOGateway.Logging.LogConfig = {level};\n const appenderFn = config?.appender;\n if (appenderFn) {\n result.appender = (event: IOGateway.Logging.LogEvent) => {\n appenderFn(new LogInfoAdapter(event));\n };\n }\n return result;\n}\n", "import {Gateway, GatewayClient, GatewayMessage} from '@interopio/gateway-server/gateway-ent';\nimport {GatewayServer} from '@interopio/gateway-server';\n\nexport class ServerDelegate implements Gateway {\n private server?: GatewayServer.Server;\n\n constructor(private readonly config: GatewayServer.ServerConfig) {\n }\n\n async connect(cb: (client: GatewayClient, msg: GatewayMessage) => void): Promise<GatewayClient> {\n if (!this.server) {\n throw new Error(`not started`);\n }\n const client = await this.server.gateway.connect((c, m) => cb(c as unknown as GatewayClient, m as GatewayMessage));\n return client as unknown as GatewayClient;\n }\n\n info(): { endpoint: string } {\n return this.server?.gateway.info() as { endpoint: string };\n }\n\n async start(): Promise<Gateway> {\n if (!this.server) {\n this.server = await GatewayServer.Factory(this.config);\n }\n return this;\n }\n\n async stop(): Promise<Gateway> {\n await this.server?.close();\n delete this.server;\n return this;\n }\n}\n", "import {GatewayServer} from '../../../gateway-server';\nimport {IOGateway} from '@interopio/gateway';\nimport { GatewayConfig, MetricsPublisherConfig } from '../../../types/gateway-ent';\n\nfunction toMetricsFilters(legacy?: MetricsPublisherConfig['filters']): IOGateway.MetricFilters | undefined {\n if (legacy) {\n const publishers = legacy.publishers.map(publisher => {\n return {identity: publisher.publisher, metrics: publisher.metrics};\n });\n const non_matched = legacy['non-matched'];\n return {publishers, non_matched};\n }\n}\n\nfunction toMetricsPublisherConfig(legacy: MetricsPublisherConfig & {\n conflation?: { 'max-datapoints-repo'?: number } & MetricsPublisherConfig['conflation']\n}): IOGateway.BasicMetricsPublisherConfig {\n const filters = toMetricsFilters(legacy?.filters);\n const conflation = toConflation(legacy?.conflation);\n return {...legacy, filters, conflation};\n}\n\nfunction toConflation(legacy?: {\n 'max-datapoints-repo'?: number\n} & MetricsPublisherConfig['conflation']): IOGateway.BasicMetricsPublisherConfig['conflation'] | undefined {\n if (legacy) {\n return {interval: legacy.interval};\n }\n}\n\nfunction toMetricsConfig(legacy: GatewayConfig['metrics']): IOGateway.GatewayConfig['metrics'] {\n const metrics: IOGateway.GatewayConfig['metrics'] = {publishers: []};\n legacy?.publishers?.forEach((publisher) => {\n if (typeof publisher === 'string') {\n if (publisher === 'rest') {\n metrics.publishers.push('rest');\n if (legacy.rest) {\n const conf = {...legacy.rest};\n const userAgent = conf[\"user-agent\"];\n delete conf['user-agent'];\n const headers = {...conf.headers, ...(userAgent ? {'user-agent': userAgent} : {})};\n delete conf.headers;\n metrics.rest = {\n endpoint: conf.endpoint,\n headers: headers,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.rest['publishFn'] ??= '@interopio/gateway-server/metrics/publisher/rest';\n }\n } else if (publisher === 'file') {\n metrics.publishers.push('file');\n if (legacy.file) {\n const conf = {...legacy.file};\n const status = conf['skip-status'] === undefined ? true : !conf['skip-status'];\n delete conf['skip-status'];\n metrics.file = {\n location: conf.location,\n status: status,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.file['publishFn'] ??= '@interopio/gateway/metrics/publisher/file';\n }\n } else {\n // unsupported predefined type\n }\n } else {\n const configuration = {...publisher.configuration};\n const splitSize = configuration[\"split-size\"];\n delete configuration[\"split-size\"];\n const file = publisher['file'] as string;\n const custom: IOGateway.CustomMetricsPublisherConfig = {\n split_size: splitSize,\n publisher: {file, configuration},\n ...toMetricsPublisherConfig(configuration)\n }\n metrics.publishers.push(custom);\n }\n });\n if (legacy?.filters) {\n metrics.filters = toMetricsFilters(legacy?.filters);\n }\n return metrics;\n}\ntype GatewayCluster = Required<GatewayConfig>['cluster'];\ntype P2P = Required<GatewayCluster>['p2p'];\n\nfunction trimTrailingSlash(url?: string): string | undefined {\n return url?.endsWith('/') ? url.slice(0, -1) : url;\n}\n\nfunction toCluster(legacy?: P2P): IOGateway.MeshConfig['cluster'] | undefined {\n if (legacy?.directory) {\n const legacyDirectory = legacy.directory;\n const config: IOGateway.MeshConfig['cluster'] = {endpoint: legacy?.['endpoint']};\n if (legacyDirectory.type === 'rest') {\n let directory: IOGateway.RestMeshDirectoryConfig | undefined = undefined;\n if (config.endpoint === undefined) {\n config.endpoint = trimTrailingSlash(legacyDirectory.config?.directory_uri)!;\n }\n else {\n directory = {uri: trimTrailingSlash(legacyDirectory.config?.directory_uri)};\n }\n if (legacyDirectory.config?.announce_interval) {\n directory ??= {};\n directory.interval = Number(legacyDirectory.config.announce_interval);\n }\n if (directory !== undefined) {\n config.directory = directory;\n }\n return config;\n }\n else if (legacyDirectory.type === 'static') {\n config.directory = {members : legacyDirectory.members ?? []};\n return config;\n }\n }\n}\n\nfunction toMeshConfig(legacy: GatewayConfig['cluster']) {\n const mesh: IOGateway.MeshConfig = {};\n if (legacy?.configuration?.node_id) mesh.node = legacy.configuration.node_id;\n if (legacy?.type === 'broker') mesh.broker = {endpoint: legacy.broker!.endpoint!};\n if (legacy?.type === 'p2p') {\n const cluster = toCluster(legacy.p2p);\n if (cluster) {\n mesh.cluster = cluster;\n }\n }\n return mesh;\n}\n\nfunction toAuthenticationConfig(legacy: GatewayConfig['authentication']): IOGateway.AuthenticationConfig {\n const authentication: IOGateway.AuthenticationConfig & {available: string[]} = {available: []};\n if (legacy?.default) {\n authentication.default = legacy.default as string;\n }\n\n const as = legacy?.available as string[];\n as.forEach((a) => {\n if (a === 'basic' || a === 'oauth2' || legacy?.[a]?.['authenticator'] !== undefined) {\n authentication.available.push(a);\n if (legacy?.[a] !== undefined) {\n authentication[a] = legacy[a];\n }\n }\n });\n\n return authentication;\n}\nexport function toServerConfig(config: GatewayConfig): GatewayServer.ServerConfig {\n const gateway: GatewayServer.ServerConfig[\"gateway\"] = {\n route: config.route,\n limits: config.limits,\n origins: config.security?.origin_filters as GatewayServer.OriginFilters,\n clients: config['clients'] ?? {inactive_seconds: 0, buffer_size: 100},\n contexts: {\n lifetime: 'retained',\n visibility: [\n {context: /___channel___.+/, restrictions: 'cluster'},\n {context: /T42\\..+/, restrictions: 'local'}\n ]\n },\n methods: {\n visibility: [\n {method: /T42\\..+/, restrictions: 'local'}\n ]\n },\n peers: {\n visibility: [\n {domain: 'context', restrictions: 'cluster'},\n {domain: 'agm', restrictions: 'local'}\n ]\n },\n metrics: {publishers: []}\n };\n if (config.authentication !== undefined) {\n if (config.authentication.token_ttl) gateway.token = {ttl: config.authentication?.token_ttl as number};\n if (config.authentication.available || config.authentication.default) gateway.authentication = toAuthenticationConfig(config.authentication);\n }\n if (config['globals']) {\n gateway.globals = config['globals'];\n }\n if (config['contexts']) {\n gateway.contexts = config['contexts'];\n }\n if (config['methods']) {\n gateway.methods = config['methods'];\n }\n if (config['peers']) {\n gateway.peers = config['peers'];\n }\n if (config.cluster?.enabled) {\n gateway.mesh = toMeshConfig(config.cluster);\n\n }\n if (config.metrics?.publishers) gateway.metrics = toMetricsConfig(config.metrics);\n return {\n port: config.port ?? 3434,\n host: config.ip ?? config['host'] as string,\n memory: config['memory'],\n gateway: gateway\n };\n}\n", "import {toLogConfig} from './logging.js';\nimport {ServerDelegate} from './server.js';\nimport {toServerConfig} from './config.js';\nimport {\n Gateway,\n GatewayConfig,\n LogInfo,\n LogLevel\n} from '../../../types/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\n\nexport function create(config: GatewayConfig): Gateway {\n return new ServerDelegate(toServerConfig(config));\n}\n\nexport function configure_logging(config?: { level: LogLevel, appender?: (info: LogInfo) => void }) {\n IOGateway.Logging.configure(toLogConfig(config));\n}\n"],
|
|
5
|
-
"mappings": ";AAEA,SAAQ,cAAa;AAErB,IAAM,iBAAN,MAAwC;AAAA,EAKpC,YAA6B,OAAmC;AAAnC;AAAA,EAC7B;AAAA,EALQ;AAAA,EACA;AAAA,EACA;AAAA,EAKA,SAAuC;AAC3C,QAAI,KAAK,YAAY,QAAW;AAC5B,UAAI,MAAyB;AAC7B,UAAI,QAAQ,KAAK,MAAM;AACvB,UAAI,KAAK,MAAM,KAAK,CAAC,aAAa,OAAO;AACrC,cAAM,KAAK,MAAM,KAAK,CAAC;AACvB,gBAAQ,MAAM,MAAM,CAAC;AAAA,MACzB;AACA,YAAM,MAAM,OAAO,KAAK,MAAM,SAAS,GAAG,KAAK;AAC/C,WAAK,UAAU,EAAC,KAAK,IAAG;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,OAAa;AACb,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,QAAkB;AAClB,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,YAAY;AACZ,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA,EAEA,IAAI,OAAe;AACf,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,OAAe;AACf,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,UAAkB;AAClB,WAAO,KAAK,OAAO,EAAE;AAAA,EACzB;AAAA,EAEA,IAAI,aAAgC;AAChC,WAAO,KAAK,OA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AY,SAAQ,UAAU,gBAAgB,OAAO,OAAO;AAChF,SAAO;AAAA,IACH,MAAM,OAAO,QAAQ;AAAA,IACrB,MAAM,OAAO,MAAM,OAAO,MAAM;AAAA,IAChC,QAAQ,OAAO,QAAQ;AAAA,IACvB;AAAA,EACJ;AACJ;;;
|
|
4
|
+
"sourcesContent": ["import {LogInfo, LogLevel} from '@interopio/gateway-server/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\nimport {format} from 'node:util';\n\nclass LogInfoAdapter implements LogInfo {\n private _parsed?: { err?: Error, msg: string };\n private _timestamp?: string;\n private _output?: string;\n\n constructor(private readonly event: IOGateway.Logging.LogEvent) {\n }\n\n private parsed(): { err?: Error, msg: string } {\n if (this._parsed === undefined) {\n let err: Error | undefined = undefined;\n let vargs = this.event.data;\n if (this.event.data[0] instanceof Error) {\n err = this.event.data[0];\n vargs = vargs.slice(1);\n }\n const msg = format(this.event.message, ...vargs);\n this._parsed = {err, msg};\n }\n return this._parsed;\n }\n\n get time(): Date {\n return this.event.time;\n }\n\n get level(): LogLevel {\n return this.event.level;\n }\n\n get namespace() {\n return this.event.name;\n }\n\n get file(): string {\n return undefined as unknown as string;\n }\n\n get line(): number {\n return undefined as unknown as number;\n }\n\n get message(): string {\n return this.parsed().msg;\n }\n\n get stacktrace(): Error | undefined {\n return this.parsed().err;\n }\n\n private get timestamp(): string {\n if (this._timestamp === undefined) {\n this._timestamp = this.time.toISOString();\n }\n return this._timestamp;\n }\n\n get output(): string {\n if (this._output === undefined) {\n const err = this.parsed().err;\n const stacktrace = err ? `\\n${err.stack ?? err}` : '';\n this._output = `${this.timestamp} ${this.level.toUpperCase()} [${this.namespace}] - ${this.message}${stacktrace}`;\n }\n return this._output;\n }\n}\n\nexport function toLogConfig(config?: { level?: LogLevel; appender?: (info: LogInfo) => void }): IOGateway.Logging.LogConfig {\n let level: Exclude<LogLevel, 'report' | 'fatal'> = 'info';\n if (config?.level) {\n if (config.level === 'fatal') {\n level = 'error';\n } else if (config.level !== 'report') {\n level = config.level;\n }\n }\n const result: IOGateway.Logging.LogConfig = {level};\n const appenderFn = config?.appender;\n if (appenderFn) {\n result.appender = (event: IOGateway.Logging.LogEvent) => {\n appenderFn(new LogInfoAdapter(event));\n };\n }\n return result;\n}\n", "import {Gateway, GatewayClient, GatewayMessage} from '@interopio/gateway-server/gateway-ent';\nimport {GatewayServer} from '@interopio/gateway-server';\n\nexport class ServerDelegate implements Gateway {\n private server?: GatewayServer.Server;\n\n constructor(private readonly config: GatewayServer.ServerConfig) {\n }\n\n async connect(cb: (client: GatewayClient, msg: GatewayMessage) => void): Promise<GatewayClient> {\n if (!this.server) {\n throw new Error(`not started`);\n }\n const client = await this.server.gateway.connect((c, m) => cb(c as unknown as GatewayClient, m as GatewayMessage));\n return client as unknown as GatewayClient;\n }\n\n info(): { endpoint: string } {\n return this.server?.gateway.info() as { endpoint: string };\n }\n\n async start(): Promise<Gateway> {\n if (!this.server) {\n this.server = await GatewayServer.Factory(this.config);\n }\n return this;\n }\n\n async stop(): Promise<Gateway> {\n await this.server?.close();\n delete this.server;\n return this;\n }\n}\n", "import {GatewayServer} from '../../../gateway-server';\nimport {IOGateway} from '@interopio/gateway';\nimport { GatewayConfig, MetricsPublisherConfig } from '../../../types/gateway-ent';\n\nfunction toMetricsFilters(legacy?: MetricsPublisherConfig['filters']): IOGateway.MetricFilters | undefined {\n if (legacy) {\n const publishers = legacy.publishers.map(publisher => {\n return {identity: publisher.publisher, metrics: publisher.metrics};\n });\n const non_matched = legacy['non-matched'];\n return {publishers, non_matched};\n }\n}\n\nfunction toMetricsPublisherConfig(legacy: MetricsPublisherConfig & {\n conflation?: { 'max-datapoints-repo'?: number } & MetricsPublisherConfig['conflation']\n}): IOGateway.BasicMetricsPublisherConfig {\n const filters = toMetricsFilters(legacy?.filters);\n const conflation = toConflation(legacy?.conflation);\n return {...legacy, filters, conflation};\n}\n\nfunction toConflation(legacy?: {\n 'max-datapoints-repo'?: number\n} & MetricsPublisherConfig['conflation']): IOGateway.BasicMetricsPublisherConfig['conflation'] | undefined {\n if (legacy) {\n return {interval: legacy.interval};\n }\n}\n\nfunction toMetricsConfig(legacy: GatewayConfig['metrics']): IOGateway.GatewayConfig['metrics'] {\n const metrics: IOGateway.GatewayConfig['metrics'] = {publishers: []};\n legacy?.publishers?.forEach((publisher) => {\n if (typeof publisher === 'string') {\n if (publisher === 'rest') {\n metrics.publishers.push('rest');\n if (legacy.rest) {\n const conf = {...legacy.rest};\n const userAgent = conf[\"user-agent\"];\n delete conf['user-agent'];\n const headers = {...conf.headers, ...(userAgent ? {'user-agent': userAgent} : {})};\n delete conf.headers;\n metrics.rest = {\n endpoint: conf.endpoint,\n headers: headers,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.rest['publishFn'] ??= '@interopio/gateway-server/metrics/publisher/rest';\n }\n } else if (publisher === 'file') {\n metrics.publishers.push('file');\n if (legacy.file) {\n const conf = {...legacy.file};\n const status = conf['skip-status'] === undefined ? true : !conf['skip-status'];\n delete conf['skip-status'];\n metrics.file = {\n location: conf.location,\n status: status,\n ...toMetricsPublisherConfig(conf)\n };\n metrics.file['publishFn'] ??= '@interopio/gateway/metrics/publisher/file';\n }\n } else {\n // unsupported predefined type\n }\n } else {\n const configuration = {...publisher.configuration};\n const splitSize = configuration[\"split-size\"];\n delete configuration[\"split-size\"];\n const file = publisher['file'] as string;\n const custom: IOGateway.CustomMetricsPublisherConfig = {\n split_size: splitSize,\n publisher: {file, configuration},\n ...toMetricsPublisherConfig(configuration)\n }\n metrics.publishers.push(custom);\n }\n });\n if (legacy?.filters) {\n metrics.filters = toMetricsFilters(legacy?.filters);\n }\n return metrics;\n}\ntype GatewayCluster = Required<GatewayConfig>['cluster'];\ntype P2P = Required<GatewayCluster>['p2p'];\n\nfunction trimTrailingSlash(url?: string): string | undefined {\n return url?.endsWith('/') ? url.slice(0, -1) : url;\n}\n\nfunction toCluster(legacy?: P2P): IOGateway.MeshConfig['cluster'] | undefined {\n if (legacy?.directory) {\n const legacyDirectory = legacy.directory;\n const config: IOGateway.MeshConfig['cluster'] = {endpoint: legacy?.['endpoint']};\n if (legacyDirectory.type === 'rest') {\n let directory: IOGateway.RestMeshDirectoryConfig | undefined = undefined;\n if (config.endpoint === undefined) {\n config.endpoint = trimTrailingSlash(legacyDirectory.config?.directory_uri)!;\n }\n else {\n directory = {uri: trimTrailingSlash(legacyDirectory.config?.directory_uri)};\n }\n if (legacyDirectory.config?.announce_interval) {\n directory ??= {};\n directory.interval = Number(legacyDirectory.config.announce_interval);\n }\n if (directory !== undefined) {\n config.directory = directory;\n }\n return config;\n }\n else if (legacyDirectory.type === 'static') {\n config.directory = {members : legacyDirectory.members ?? []};\n return config;\n }\n }\n}\n\nfunction toMeshConfig(legacy: GatewayConfig['cluster']) {\n const mesh: IOGateway.MeshConfig = {};\n if (legacy?.configuration?.node_id) mesh.node = legacy.configuration.node_id;\n if (legacy?.type === 'broker') mesh.broker = {endpoint: legacy.broker!.endpoint!};\n if (legacy?.type === 'p2p') {\n const cluster = toCluster(legacy.p2p);\n if (cluster) {\n mesh.cluster = cluster;\n }\n }\n return mesh;\n}\n\nfunction toAuthenticationConfig(legacy: GatewayConfig['authentication']): IOGateway.AuthenticationConfig {\n const authentication: IOGateway.AuthenticationConfig & {available: string[]} = {available: []};\n if (legacy?.default) {\n authentication.default = legacy.default as string;\n }\n\n const as = legacy?.available as string[];\n as.forEach((a) => {\n if (a === 'basic' || a === 'oauth2' || legacy?.[a]?.['authenticator'] !== undefined) {\n authentication.available.push(a);\n if (legacy?.[a] !== undefined) {\n authentication[a] = legacy[a];\n }\n }\n });\n\n return authentication;\n}\nexport function toServerConfig(config: GatewayConfig): GatewayServer.ServerConfig {\n const gateway: GatewayServer.ServerConfig[\"gateway\"] = {\n route: config.route,\n limits: config.limits,\n origins: config.security?.origin_filters as GatewayServer.OriginFilters,\n authorize: config['authorize'] as GatewayServer.AuthorizationRule ?? {access: 'permitted'},\n clients: config['clients'] ?? {inactive_seconds: 0, buffer_size: 100},\n contexts: {\n lifetime: 'retained',\n visibility: [\n {context: /___channel___.+/, restrictions: 'cluster'},\n {context: /T42\\..+/, restrictions: 'local'}\n ]\n },\n methods: {\n visibility: [\n {method: /T42\\..+/, restrictions: 'local'}\n ]\n },\n peers: {\n visibility: [\n {domain: 'context', restrictions: 'cluster'},\n {domain: 'agm', restrictions: 'local'}\n ]\n },\n metrics: {publishers: []}\n };\n if (config.authentication !== undefined) {\n if (config.authentication.token_ttl) gateway.token = {ttl: config.authentication?.token_ttl as number};\n if (config.authentication.available || config.authentication.default) gateway.authentication = toAuthenticationConfig(config.authentication);\n }\n if (config['globals']) {\n gateway.globals = config['globals'];\n }\n if (config['contexts']) {\n gateway.contexts = config['contexts'];\n }\n if (config['methods']) {\n gateway.methods = config['methods'];\n }\n if (config['peers']) {\n gateway.peers = config['peers'];\n }\n if (config.cluster?.enabled) {\n gateway.mesh = toMeshConfig(config.cluster);\n\n }\n if (config.metrics?.publishers) gateway.metrics = toMetricsConfig(config.metrics);\n return {\n port: config.port ?? 3434,\n host: config.ip ?? config['host'] as string,\n memory: config['memory'],\n gateway: gateway\n };\n}\n", "import {toLogConfig} from './logging.js';\nimport {ServerDelegate} from './server.js';\nimport {toServerConfig} from './config.js';\nimport {\n Gateway,\n GatewayConfig,\n LogInfo,\n LogLevel\n} from '../../../types/gateway-ent';\nimport {IOGateway} from '@interopio/gateway';\n\nexport function create(config: GatewayConfig): Gateway {\n return new ServerDelegate(toServerConfig(config));\n}\n\nexport function configure_logging(config?: { level: LogLevel, appender?: (info: LogInfo) => void }) {\n IOGateway.Logging.configure(toLogConfig(config));\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAQ,cAAa;AAErB,IAAM,iBAAN,MAAwC;AAAA,EAKpC,YAA6B,OAAmC;AAAnC;AAAA,EAC7B;AAAA,EALQ;AAAA,EACA;AAAA,EACA;AAAA,EAKA,SAAuC;AAC3C,QAAI,KAAK,YAAY,QAAW;AAC5B,UAAI,MAAyB;AAC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289
1289
|
}
|
|
1290
1290
|
const addresses = Object.values((0, import_node_os.networkInterfaces)()).flatMap((details) => {
|
|
1291
|
-
return (details ?? []).filter((
|
|
1292
|
-
}).reduce((acc,
|
|
1293
|
-
acc[
|
|
1291
|
+
return (details ?? []).filter((info2) => info2.family === "IPv4");
|
|
1292
|
+
}).reduce((acc, info2) => {
|
|
1293
|
+
acc[info2.internal ? "internal" : "external"].push(info2);
|
|
1294
1294
|
return acc;
|
|
1295
1295
|
}, { internal: [], external: [] });
|
|
1296
1296
|
return (first(addresses.internal) ?? first(addresses.external))?.address;
|
|
@@ -1510,16 +1510,17 @@ function regexifyOriginFilters(originFilters) {
|
|
|
1510
1510
|
}
|
|
1511
1511
|
|
|
1512
1512
|
// src/server/server-header.ts
|
|
1513
|
+
var import_package = __toESM(require("@interopio/gateway-server/package.json"), 1);
|
|
1513
1514
|
var serverHeader = (server) => {
|
|
1514
|
-
|
|
1515
|
+
server ??= `${import_package.default.name} - v${import_package.default.version}`;
|
|
1515
1516
|
return async ({ response }, next) => {
|
|
1516
|
-
if (server
|
|
1517
|
+
if (server !== false && !response.headers.has("server")) {
|
|
1517
1518
|
response.headers.set("Server", server);
|
|
1518
1519
|
}
|
|
1519
1520
|
await next();
|
|
1520
1521
|
};
|
|
1521
1522
|
};
|
|
1522
|
-
var server_header_default = (server
|
|
1523
|
+
var server_header_default = (server) => serverHeader(server);
|
|
1523
1524
|
|
|
1524
1525
|
// src/app/route.ts
|
|
1525
1526
|
function findSocketRoute({ request }, { sockets: routes3 }) {
|
|
@@ -2771,8 +2772,9 @@ async function createCorsConfigSource(context) {
|
|
|
2771
2772
|
// src/app/auth.ts
|
|
2772
2773
|
function createSecurityConfig(context) {
|
|
2773
2774
|
const authorize = [];
|
|
2775
|
+
const defaultAccess = { access: context.authConfig?.type !== "none" ? "authenticated" : "permitted" };
|
|
2774
2776
|
for (const [path, route] of context.sockets) {
|
|
2775
|
-
const rule = route.authorize ??
|
|
2777
|
+
const rule = route.authorize ?? defaultAccess;
|
|
2776
2778
|
let matcher = pattern(path, { method: "GET" });
|
|
2777
2779
|
matcher = and([upgradeMatcher, matcher]);
|
|
2778
2780
|
authorize.push([matcher, rule]);
|
|
@@ -2783,7 +2785,7 @@ function createSecurityConfig(context) {
|
|
|
2783
2785
|
if (context.authorize.length > 0) {
|
|
2784
2786
|
authorize.push(...context.authorize);
|
|
2785
2787
|
}
|
|
2786
|
-
authorize.push(["any-exchange",
|
|
2788
|
+
authorize.push(["any-exchange", defaultAccess]);
|
|
2787
2789
|
return {
|
|
2788
2790
|
authorize,
|
|
2789
2791
|
basic: {
|
|
@@ -2827,23 +2829,23 @@ async function createListener(middleware, context, onSocketError) {
|
|
|
2827
2829
|
if ((request.method === "GET" || request.method === "CONNECT") && upgradeMatchResult.match) {
|
|
2828
2830
|
const socket = request.socket;
|
|
2829
2831
|
const host = request.host;
|
|
2830
|
-
const
|
|
2832
|
+
const info2 = socketKey(request._req.socket);
|
|
2831
2833
|
if (route.wss) {
|
|
2832
2834
|
socket.removeListener("error", onSocketError);
|
|
2833
2835
|
const wss = route.wss;
|
|
2834
2836
|
if (route.maxConnections !== void 0 && wss.clients?.size >= route.maxConnections) {
|
|
2835
|
-
logger10.warn(`${
|
|
2837
|
+
logger10.warn(`${info2} dropping ws connection request from ${host} on ${path}. max connections exceeded.`);
|
|
2836
2838
|
socket.destroy();
|
|
2837
2839
|
return;
|
|
2838
2840
|
}
|
|
2839
2841
|
const origin = request.headers.one("origin");
|
|
2840
2842
|
if (!acceptsOrigin(origin, route.originFilters)) {
|
|
2841
|
-
logger10.info(`${
|
|
2843
|
+
logger10.info(`${info2} dropping ws connection request from ${host} on ${path}. origin ${origin ?? "<missing>"}`);
|
|
2842
2844
|
socket.destroy();
|
|
2843
2845
|
return;
|
|
2844
2846
|
}
|
|
2845
2847
|
if (logger10.enabledFor("debug")) {
|
|
2846
|
-
logger10.debug(`${
|
|
2848
|
+
logger10.debug(`${info2} accepted new ws connection request from ${host} on ${path}`);
|
|
2847
2849
|
}
|
|
2848
2850
|
wss.handleUpgrade(request._req, socket, request._req["_upgradeHead"], (ws) => {
|
|
2849
2851
|
response._res["_header"] = true;
|
|
@@ -2853,7 +2855,7 @@ async function createListener(middleware, context, onSocketError) {
|
|
|
2853
2855
|
wss.emit("connection", ws, request._req);
|
|
2854
2856
|
});
|
|
2855
2857
|
} else {
|
|
2856
|
-
logger10.warn(`${
|
|
2858
|
+
logger10.warn(`${info2} rejected upgrade request from ${host} on ${path}`);
|
|
2857
2859
|
socket.destroy();
|
|
2858
2860
|
}
|
|
2859
2861
|
} else {
|
|
@@ -3007,12 +3009,12 @@ var Factory = async (options) => {
|
|
|
3007
3009
|
}
|
|
3008
3010
|
});
|
|
3009
3011
|
server2.on("listening", async () => {
|
|
3010
|
-
const
|
|
3012
|
+
const info2 = server2.address();
|
|
3011
3013
|
for (const [path, route] of context.sockets) {
|
|
3012
3014
|
try {
|
|
3013
3015
|
logger10.info(`creating ws server for [${path}]. max connections: ${route.maxConnections ?? "<unlimited>"}, origin filters: ${route.originFilters ? JSON.stringify(route.originFilters, regexAwareReplacer) : "<none>"}`);
|
|
3014
3016
|
const wss = new import_ws.WebSocketServer({ noServer: true });
|
|
3015
|
-
const endpoint = `${ssl ? "wss" : "ws"}://${localIp}:${
|
|
3017
|
+
const endpoint = `${ssl ? "wss" : "ws"}://${localIp}:${info2.port}${path}`;
|
|
3016
3018
|
const handler = await route.factory({ endpoint, wss, storage: context.storage });
|
|
3017
3019
|
const pingInterval = route.ping;
|
|
3018
3020
|
if (pingInterval) {
|
|
@@ -3035,7 +3037,7 @@ var Factory = async (options) => {
|
|
|
3035
3037
|
logger10.warn(`failed to init route ${path}`, e);
|
|
3036
3038
|
}
|
|
3037
3039
|
}
|
|
3038
|
-
logger10.info(`http server listening on ${
|
|
3040
|
+
logger10.info(`http server listening on ${info2.address}:${info2.port}`);
|
|
3039
3041
|
resolve(server2);
|
|
3040
3042
|
});
|
|
3041
3043
|
server2.on("upgrade", (req, socket, head) => {
|