@syncbridge/builtins 0.4.1

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) 2025 Panates (Panates Teknoloji Yatirim A.S.). All rights reserved.
2
+
3
+ This software and associated documentation files (the "Software") are
4
+ the proprietary property of Panates and are protected by copyright laws
5
+ and international copyright treaties.
6
+
7
+ Unauthorized copying, distribution, modification, reverse engineering,
8
+ or use of this software, in whole or in part, is strictly prohibited
9
+ without the express written permission of Panates.
10
+
11
+ This Software is provided solely for use in accordance with the terms
12
+ of a valid license agreement. Any unauthorized use may result in
13
+ civil and/or criminal penalties.
14
+
15
+ For licensing inquiries, please contact: info@panates.com
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # SyncBridge Builtin Components
@@ -0,0 +1,34 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { getStream } from 'file-stream-rotator';
3
+ export declare class TransmitLogger extends EventEmitter {
4
+ protected _stream?: ReturnType<typeof getStream>;
5
+ readonly name: string;
6
+ useBase64: boolean;
7
+ constructor(options: TransmitLogger.Options);
8
+ received(content: Buffer | string, peer?: string): void;
9
+ transmitted(content: Buffer | string, peer?: string): void;
10
+ info(content: string, peer?: string): void;
11
+ protected _write(direction: string, content: Buffer | string, peer?: string): void;
12
+ protected _getHeader(direction: string, contentSize: number, peer?: string): string;
13
+ }
14
+ /**
15
+ * Variables
16
+ */
17
+ declare class TransmitLogVariables {
18
+ constructor(init?: Partial<TransmitLogVariables>);
19
+ maxFileSize: string;
20
+ maxFiles: string;
21
+ }
22
+ export declare namespace TransmitLogger {
23
+ interface Options {
24
+ logDirectory?: string;
25
+ name: string;
26
+ frequency?: string;
27
+ maxFileSize?: string;
28
+ maxFiles?: string;
29
+ useBase64?: boolean;
30
+ }
31
+ const Variables: typeof TransmitLogVariables;
32
+ type Variables = TransmitLogVariables;
33
+ }
34
+ export {};
@@ -0,0 +1,90 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { EventEmitter } from 'node:events';
3
+ import * as path from 'node:path';
4
+ import { DefineVariable } from '@syncbridge/common';
5
+ import { format } from 'date-fns';
6
+ import { getStream } from 'file-stream-rotator';
7
+ export class TransmitLogger extends EventEmitter {
8
+ _stream;
9
+ name;
10
+ useBase64 = false;
11
+ constructor(options) {
12
+ super();
13
+ this.name = options.name;
14
+ if (options.logDirectory) {
15
+ this._stream = getStream({
16
+ filename: path.join(options.logDirectory, `%DATE%-${options.name || ''}`),
17
+ extension: '.log',
18
+ audit_file: path.join(options.logDirectory, `.audit.json`),
19
+ date_format: 'YYYY-MM-DD',
20
+ size: options?.maxFileSize || '10m',
21
+ max_logs: options?.maxFiles || '14d',
22
+ });
23
+ this._stream.on('rotate', () => {
24
+ this.emit('rotate');
25
+ });
26
+ this._stream.on('new', () => {
27
+ this.emit('new');
28
+ });
29
+ }
30
+ this.useBase64 = options.useBase64 || false;
31
+ }
32
+ received(content, peer) {
33
+ this._write('R', content, peer);
34
+ }
35
+ transmitted(content, peer) {
36
+ this._write('T', content, peer);
37
+ }
38
+ info(content, peer) {
39
+ this._write('I', content, peer);
40
+ }
41
+ _write(direction, content, peer) {
42
+ if (!this._stream)
43
+ return;
44
+ const buffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
45
+ this._stream.write(this._getHeader(direction, buffer.length, peer));
46
+ if (this.useBase64)
47
+ this._stream.write(buffer.toString('base64'));
48
+ else
49
+ this._stream.write(buffer, 'binary');
50
+ this._stream.write(`\n\n`);
51
+ }
52
+ _getHeader(direction, contentSize, peer) {
53
+ const t = new Date();
54
+ const timestamp = format(t, 'yyyyMMdd|HHmmss.S');
55
+ return `<<${direction}|${timestamp}|${contentSize}|${this.useBase64 ? 'b64' : ''}|${peer || ''}>>\n`;
56
+ }
57
+ }
58
+ /**
59
+ * Variables
60
+ */
61
+ class TransmitLogVariables {
62
+ constructor(init) {
63
+ if (init)
64
+ Object.assign(this, init);
65
+ }
66
+ }
67
+ __decorate([
68
+ DefineVariable({
69
+ label: 'Max file size',
70
+ description: 'Maximum size of the file after which it will rotate. This can be a number of bytes, ' +
71
+ 'or units of kb, mb, and gb. If using the units, add "k", "m", or "g" as the suffix. ' +
72
+ 'The units need to directly follow the number.',
73
+ pattern: '^\\d+[k|m|g]?$',
74
+ default: '10m',
75
+ }),
76
+ __metadata("design:type", String)
77
+ ], TransmitLogVariables.prototype, "maxFileSize", void 0);
78
+ __decorate([
79
+ DefineVariable({
80
+ label: 'Max Files',
81
+ description: 'Maximum number of logs to keep. If not set, no logs will be removed. ' +
82
+ 'This can be a number of files or number of days. If using days, add "d" as the suffix',
83
+ pattern: '^\\d+[d]?$',
84
+ default: '14d',
85
+ }),
86
+ __metadata("design:type", String)
87
+ ], TransmitLogVariables.prototype, "maxFiles", void 0);
88
+ (function (TransmitLogger) {
89
+ TransmitLogger.Variables = TransmitLogVariables;
90
+ })(TransmitLogger || (TransmitLogger = {}));
package/classes.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './classes/transmit-logger.js';
package/classes.js ADDED
@@ -0,0 +1 @@
1
+ export * from './classes/transmit-logger.js';
@@ -0,0 +1,25 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { ComponentBase } from '@syncbridge/common';
3
+ import { TransmitLogger } from '../classes/transmit-logger.js';
4
+ import { IoClientComponentVariables } from './io-client-base.variables.js';
5
+ /**
6
+ *
7
+ */
8
+ export declare class IoClientBaseComponent<TEvents extends IoClientBaseComponent.Events = IoClientBaseComponent.Events> extends ComponentBase<TEvents> {
9
+ readonly protocol: string;
10
+ transmitLogger?: TransmitLogger;
11
+ values: IoClientComponentVariables;
12
+ protected _init(): Promise<void>;
13
+ write(data: string | Buffer): void;
14
+ }
15
+ /**
16
+ * @namespace
17
+ */
18
+ export declare namespace IoClientBaseComponent {
19
+ interface Events extends ComponentBase.Events {
20
+ data: [data: Buffer, ...any];
21
+ transmit: [data: Buffer, ...any];
22
+ }
23
+ const Variables: typeof IoClientComponentVariables;
24
+ type Variables = IoClientComponentVariables;
25
+ }
@@ -0,0 +1,60 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import path from 'node:path';
3
+ import { Component, ComponentBase } from '@syncbridge/common';
4
+ import { TransmitLogger } from '../classes/transmit-logger.js';
5
+ import { panatesAuthor } from '../constants.js';
6
+ import { IoClientComponentVariables } from './io-client-base.variables.js';
7
+ /**
8
+ *
9
+ */
10
+ let IoClientBaseComponent = class IoClientBaseComponent extends ComponentBase {
11
+ protocol = '';
12
+ transmitLogger;
13
+ async _init() {
14
+ await super._init();
15
+ const { communicationLogs } = this.values;
16
+ const { dataDirectory } = this.processor;
17
+ if (communicationLogs) {
18
+ const transmitLogger = (this.transmitLogger = new TransmitLogger({
19
+ ...communicationLogs,
20
+ logDirectory: dataDirectory
21
+ ? path.join(dataDirectory, 'comm-logs')
22
+ : undefined,
23
+ name: this.path.replace(/\//g, '-'),
24
+ maxFiles: communicationLogs?.maxFiles,
25
+ maxFileSize: communicationLogs?.maxFileSize,
26
+ }));
27
+ this.on('data', (data, info) => {
28
+ transmitLogger.received(data, info);
29
+ });
30
+ this.on('transmit', (data, info) => {
31
+ transmitLogger.transmitted(data, info);
32
+ });
33
+ }
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
+ write(data) {
37
+ throw new Error(`"${this.constructor.name}" component do not support write operations.`);
38
+ }
39
+ };
40
+ __decorate([
41
+ Component.UseVariables(),
42
+ __metadata("design:type", IoClientComponentVariables)
43
+ ], IoClientBaseComponent.prototype, "values", void 0);
44
+ IoClientBaseComponent = __decorate([
45
+ Component({
46
+ abstract: true,
47
+ className: 'IoClient',
48
+ displayName: 'IO Client',
49
+ description: 'Abstract component for IO operations',
50
+ author: panatesAuthor,
51
+ tags: ['io', 'stream'],
52
+ })
53
+ ], IoClientBaseComponent);
54
+ export { IoClientBaseComponent };
55
+ /**
56
+ * @namespace
57
+ */
58
+ (function (IoClientBaseComponent) {
59
+ IoClientBaseComponent.Variables = IoClientComponentVariables;
60
+ })(IoClientBaseComponent || (IoClientBaseComponent = {}));
@@ -0,0 +1,7 @@
1
+ import { TransmitLogger } from '../classes/transmit-logger.js';
2
+ /**
3
+ *
4
+ */
5
+ export declare class IoClientComponentVariables {
6
+ communicationLogs?: TransmitLogger.Variables;
7
+ }
@@ -0,0 +1,15 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { DefineVariable } from '@syncbridge/common';
3
+ import { TransmitLogger } from '../classes/transmit-logger.js';
4
+ /**
5
+ *
6
+ */
7
+ export class IoClientComponentVariables {
8
+ }
9
+ __decorate([
10
+ DefineVariable({
11
+ label: 'Communication Logs',
12
+ description: 'Stores communication logs if enabled',
13
+ }),
14
+ __metadata("design:type", TransmitLogger.Variables)
15
+ ], IoClientComponentVariables.prototype, "communicationLogs", void 0);
@@ -0,0 +1 @@
1
+ export * from './components/io-client-base.component.js';
package/components.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components/io-client-base.component.js';
package/constants.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { AuthorMetadata } from '@syncbridge/common';
2
+ export declare const version = "1";
3
+ export declare const noOp: () => undefined;
4
+ export declare const panatesAuthor: AuthorMetadata;
package/constants.js ADDED
@@ -0,0 +1,7 @@
1
+ export const version = '0.4.1';
2
+ export const noOp = () => undefined;
3
+ export const panatesAuthor = {
4
+ name: 'Panates Technology AS',
5
+ email: 'info@panates.com',
6
+ url: 'https://www.panates.com',
7
+ };
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as classes from './classes.js';
2
+ import * as components from './components.js';
3
+ import * as processors from './processors.js';
4
+ export { classes, components, processors };
5
+ export * from './classes.js';
6
+ export * from './components.js';
7
+ export * from './processors.js';
8
+ declare const cfg: import("@syncbridge/common").IExtensionPackage;
9
+ export default cfg;
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { makeExtensionPackage } from '@syncbridge/common';
2
+ import * as classes from './classes.js';
3
+ import * as components from './components.js';
4
+ import * as processors from './processors.js';
5
+ export { classes, components, processors };
6
+ export * from './classes.js';
7
+ export * from './components.js';
8
+ export * from './processors.js';
9
+ const cfg = makeExtensionPackage({
10
+ processors: Object.values(processors),
11
+ components: Object.values(components),
12
+ });
13
+ export default cfg;
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@syncbridge/builtins",
3
+ "version": "0.4.1",
4
+ "description": "SyncBridge builtin extensions",
5
+ "author": "Panates Inc",
6
+ "license": "UNLICENSED",
7
+ "dependencies": {
8
+ "@ngrok/ngrok": "^1.7.0",
9
+ "@pinggy/pinggy": "^0.3.2",
10
+ "@serialport/bindings-interface": "^1.2.2",
11
+ "@sqb/connect": "^4.19.6",
12
+ "@sqb/oracle": "^4.21.1",
13
+ "@sqb/postgres": "^4.21.1",
14
+ "ansi-colors": "^4.1.3",
15
+ "backoff": "^2.5.0",
16
+ "date-fns": "^4.1.0",
17
+ "fast-tokenizer": "^1.9.0",
18
+ "file-stream-rotator": "^1.0.0",
19
+ "hl7v2": "^1.7.0",
20
+ "hl7v2-net": "^1.7.0",
21
+ "lightning-pool": "^4.12.0",
22
+ "node-events-async": "^1.5.0",
23
+ "oracledb": "^6.10.0",
24
+ "putil-varhelpers": "^1.7.0",
25
+ "reconnect-core": "^1.3.0",
26
+ "serialport": "^13.0.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@syncbridge/common": "^0.4.1",
30
+ "@sqb/builder": ">=4.19.6 <5",
31
+ "@sqb/connect": ">=4.19.6 <5"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./index.d.ts",
36
+ "default": "./index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "type": "module",
41
+ "module": "./index.js",
42
+ "types": "./index.d.ts",
43
+ "engines": {
44
+ "node": ">=20.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
@@ -0,0 +1,7 @@
1
+ import { ProcessorBase } from '@syncbridge/common';
2
+ import { IoClientBaseComponent } from '../components.js';
3
+ export declare class IOBridgeProcessor extends ProcessorBase {
4
+ readonly peer1: IoClientBaseComponent;
5
+ readonly peer2: IoClientBaseComponent;
6
+ protected _init(): Promise<void>;
7
+ }
@@ -0,0 +1,49 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Processor, ProcessorBase } from '@syncbridge/common';
3
+ import { IoClientBaseComponent } from '../components.js';
4
+ import { panatesAuthor } from '../constants.js';
5
+ let IOBridgeProcessor = class IOBridgeProcessor extends ProcessorBase {
6
+ async _init() {
7
+ await super._init();
8
+ this.peer1.on('data', (data) => {
9
+ try {
10
+ this.peer2.write(data);
11
+ }
12
+ catch (err) {
13
+ err.message = `Failed to write data to peer2: ${err.message}`;
14
+ this.emit('error', err);
15
+ }
16
+ });
17
+ this.peer2.on('data', (data) => {
18
+ try {
19
+ this.peer1.write(data);
20
+ }
21
+ catch (err) {
22
+ err.message = `Failed to write data to peer1: ${err.message}`;
23
+ this.emit('error', err);
24
+ }
25
+ });
26
+ }
27
+ };
28
+ __decorate([
29
+ Processor.UseComponent({
30
+ interfaces: IoClientBaseComponent.interfaces,
31
+ required: true,
32
+ }),
33
+ __metadata("design:type", IoClientBaseComponent)
34
+ ], IOBridgeProcessor.prototype, "peer1", void 0);
35
+ __decorate([
36
+ Processor.UseComponent({
37
+ interfaces: IoClientBaseComponent.interfaces,
38
+ required: true,
39
+ }),
40
+ __metadata("design:type", IoClientBaseComponent)
41
+ ], IOBridgeProcessor.prototype, "peer2", void 0);
42
+ IOBridgeProcessor = __decorate([
43
+ Processor({
44
+ description: 'Create a bridge between two IO peers',
45
+ author: panatesAuthor,
46
+ tags: ['io', 'bridge'],
47
+ })
48
+ ], IOBridgeProcessor);
49
+ export { IOBridgeProcessor };
@@ -0,0 +1 @@
1
+ export * from './processors/io-bridge.processor.js';
package/processors.js ADDED
@@ -0,0 +1 @@
1
+ export * from './processors/io-bridge.processor.js';