@ours.network/tg-connector 0.3.3-nightly.2 → 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 +41 -23
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -140,6 +140,40 @@ function serviceEnvironment(config, stateDir) {
140
140
  if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
141
141
  return env;
142
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
+ }
143
177
 
144
178
  // src/routing.ts
145
179
  function looksLikeBotToken(s) {
@@ -559,29 +593,13 @@ function installLaunchd() {
559
593
  const plistPath = launchdPlistPath();
560
594
  fs2.mkdirSync(dirname2(plistPath), { recursive: true });
561
595
  const env = serviceEnv();
562
- const envEntries = Object.entries(env).map(([k, v]) => ` <key>${k}</key><string>${v}</string>`).join("\n");
563
- const plist = `<?xml version="1.0" encoding="UTF-8"?>
564
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
565
- <plist version="1.0">
566
- <dict>
567
- <key>Label</key><string>${LAUNCHD_LABEL}</string>
568
- <key>ProgramArguments</key>
569
- <array>
570
- <string>${process.execPath}</string>
571
- <string>${SELF}</string>
572
- <string>serve</string>
573
- </array>
574
- <key>EnvironmentVariables</key>
575
- <dict>
576
- ${envEntries}
577
- </dict>
578
- <key>RunAtLoad</key><true/>
579
- <key>KeepAlive</key><true/>
580
- <key>StandardOutPath</key><string>${LOG_PATH}</string>
581
- <key>StandardErrorPath</key><string>${LOG_PATH}</string>
582
- </dict>
583
- </plist>
584
- `;
596
+ const plist = launchdPlist({
597
+ label: LAUNCHD_LABEL,
598
+ execPath: process.execPath,
599
+ self: SELF,
600
+ logPath: LOG_PATH,
601
+ env
602
+ });
585
603
  fs2.writeFileSync(plistPath, plist);
586
604
  out(`wrote ${plistPath}`);
587
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.2",
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",