@ours.network/tg-connector 0.3.3-nightly.1 → 0.3.3-nightly.3

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 (2) hide show
  1. package/dist/cli.js +54 -32
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -129,6 +129,52 @@ function loadConfig() {
129
129
  };
130
130
  }
131
131
 
132
+ // src/service-definition.ts
133
+ function serviceEnvironment(config, stateDir) {
134
+ const env = {
135
+ OURS_TG_CONTROL_PORT: String(config.controlPort),
136
+ OURS_TG_STATE_DIR: stateDir,
137
+ OURS_TG_POLL_TIMEOUT: String(config.pollTimeoutSec)
138
+ };
139
+ if (config.daemonUrl) env.OURS_TG_DAEMON_URL = config.daemonUrl;
140
+ if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
141
+ return env;
142
+ }
143
+ function xmlText(value) {
144
+ return String(value).replace(/[&<>"']/g, (character) => ({
145
+ "&": "&amp;",
146
+ "<": "&lt;",
147
+ ">": "&gt;",
148
+ '"': "&quot;",
149
+ "'": "&apos;"
150
+ })[character]);
151
+ }
152
+ function launchdPlist(input) {
153
+ const envEntries = Object.entries(input.env).map(([key, value]) => ` <key>${xmlText(key)}</key><string>${xmlText(value)}</string>`).join("\n");
154
+ return `<?xml version="1.0" encoding="UTF-8"?>
155
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
156
+ <plist version="1.0">
157
+ <dict>
158
+ <key>Label</key><string>${xmlText(input.label)}</string>
159
+ <key>ProgramArguments</key>
160
+ <array>
161
+ <string>${xmlText(input.execPath)}</string>
162
+ <string>${xmlText(input.self)}</string>
163
+ <string>serve</string>
164
+ </array>
165
+ <key>EnvironmentVariables</key>
166
+ <dict>
167
+ ${envEntries}
168
+ </dict>
169
+ <key>RunAtLoad</key><true/>
170
+ <key>KeepAlive</key><true/>
171
+ <key>StandardOutPath</key><string>${xmlText(input.logPath)}</string>
172
+ <key>StandardErrorPath</key><string>${xmlText(input.logPath)}</string>
173
+ </dict>
174
+ </plist>
175
+ `;
176
+ }
177
+
132
178
  // src/routing.ts
133
179
  function looksLikeBotToken(s) {
134
180
  return /^\d+:[A-Za-z0-9_-]+$/.test(s);
@@ -493,15 +539,7 @@ function run(cmd, args) {
493
539
  const r = spawnSync(cmd, args, { stdio: "inherit" });
494
540
  return r.status === 0;
495
541
  }
496
- function serviceEnv() {
497
- return {
498
- OURS_TG_DAEMON_URL: CONFIG.daemonUrl,
499
- OURS_TG_DAEMON_STATE_DIR: CONFIG.daemonStateDir,
500
- OURS_TG_CONTROL_PORT: String(CONFIG.controlPort),
501
- OURS_TG_STATE_DIR: STATE_DIR,
502
- OURS_TG_POLL_TIMEOUT: String(CONFIG.pollTimeoutSec)
503
- };
504
- }
542
+ var serviceEnv = () => serviceEnvironment(CONFIG, STATE_DIR);
505
543
  function installSystemd() {
506
544
  const unitPath = systemdUnitPath();
507
545
  fs2.mkdirSync(dirname2(unitPath), { recursive: true });
@@ -555,29 +593,13 @@ function installLaunchd() {
555
593
  const plistPath = launchdPlistPath();
556
594
  fs2.mkdirSync(dirname2(plistPath), { recursive: true });
557
595
  const env = serviceEnv();
558
- const envEntries = Object.entries(env).map(([k, v]) => ` <key>${k}</key><string>${v}</string>`).join("\n");
559
- const plist = `<?xml version="1.0" encoding="UTF-8"?>
560
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
561
- <plist version="1.0">
562
- <dict>
563
- <key>Label</key><string>${LAUNCHD_LABEL}</string>
564
- <key>ProgramArguments</key>
565
- <array>
566
- <string>${process.execPath}</string>
567
- <string>${SELF}</string>
568
- <string>serve</string>
569
- </array>
570
- <key>EnvironmentVariables</key>
571
- <dict>
572
- ${envEntries}
573
- </dict>
574
- <key>RunAtLoad</key><true/>
575
- <key>KeepAlive</key><true/>
576
- <key>StandardOutPath</key><string>${LOG_PATH}</string>
577
- <key>StandardErrorPath</key><string>${LOG_PATH}</string>
578
- </dict>
579
- </plist>
580
- `;
596
+ const plist = launchdPlist({
597
+ label: LAUNCHD_LABEL,
598
+ execPath: process.execPath,
599
+ self: SELF,
600
+ logPath: LOG_PATH,
601
+ env
602
+ });
581
603
  fs2.writeFileSync(plistPath, plist);
582
604
  out(`wrote ${plistPath}`);
583
605
  run("launchctl", ["unload", plistPath]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ours.network/tg-connector",
3
- "version": "0.3.3-nightly.1",
3
+ "version": "0.3.3-nightly.3",
4
4
  "description": "Bridge Telegram bots to ours.network agents — attaches to an already-running ours daemon and bridges one Telegram chat/topic to one agent per route. Run `ours-tg-connector add_new_connection`.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",