oorja 2.1.3 → 2.1.5

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.
@@ -5,7 +5,7 @@ import * as os from 'os';
5
5
  import chalk from 'chalk';
6
6
  import { ROOM_LINK_SAMPLE } from '../../lib/config.js';
7
7
  import { getApp } from '../../lib/oorja/index.js';
8
- import { promptRoomLink } from '../../lib/utils.js';
8
+ import { printExitMessage, promptRoomLink } from '../../lib/utils.js';
9
9
  const DEFAULT_SHELL = os.platform() === 'win32' ? 'powershell.exe' : process.env.SHELL || 'bash';
10
10
  export default class TeleTypeCommand extends Command {
11
11
  static order = 1;
@@ -81,7 +81,7 @@ Will also allow participants to write to your terminal!
81
81
  async streamToLink(options) {
82
82
  const roomLink = options.roomLink || (await promptRoomLink());
83
83
  if (!roomLink) {
84
- console.log(chalk.redBright('Space link not provided :('));
84
+ printExitMessage(chalk.redBright('Space link not provided :('));
85
85
  process.exit();
86
86
  }
87
87
  const app = await getApp({ roomLink });
@@ -111,7 +111,7 @@ Will also allow participants to write to your terminal!
111
111
  },
112
112
  })
113
113
  .catch((e) => {
114
- console.log('Failed to create space.');
114
+ printExitMessage('Failed to create space.');
115
115
  process.exit(9);
116
116
  });
117
117
  spinner.succeed(chalk.bold('Space created')).clear();
@@ -1,6 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  export const CLI_VERSION = 2.5;
3
3
  import Conf from 'conf';
4
+ import { printExitMessage } from './utils.js';
4
5
  export const config = new Conf({
5
6
  projectName: 'oorja',
6
7
  schema: {
@@ -41,7 +42,7 @@ export const determineENV = (roomURL) => {
41
42
  case 'localhost:3000':
42
43
  return 'local';
43
44
  default:
44
- console.error(INVALID_ROOM_LINK_MESSAGE);
45
+ printExitMessage(INVALID_ROOM_LINK_MESSAGE);
45
46
  process.exit(1);
46
47
  }
47
48
  };
@@ -7,6 +7,7 @@ import { getConnectConfig } from '../config.js';
7
7
  import { Unauthorized, BadRequest } from './errors.js';
8
8
  import { Socket, Presence } from 'phoenix';
9
9
  import camelcaseKeys from 'camelcase-keys';
10
+ import { printExitMessage } from '../utils.js';
10
11
  export class ApiClientError extends Error {
11
12
  }
12
13
  export class ConnectClient {
@@ -157,7 +158,7 @@ export class ConnectClient {
157
158
  reject();
158
159
  return;
159
160
  }
160
- console.error('connection error');
161
+ printExitMessage('connection error');
161
162
  process.exit(2);
162
163
  });
163
164
  // @ts-ignore
@@ -195,6 +196,7 @@ export class ConnectClient {
195
196
  onError(new Unauthorized('unauthorized: user needs to join the room before a stream can be started.'));
196
197
  return;
197
198
  }
199
+ printExitMessage('error on channel');
198
200
  process.exit(3);
199
201
  });
200
202
  return chan;
@@ -1,4 +1,5 @@
1
1
  import haversine from 'haversine-distance';
2
+ import { printExitMessage } from '../utils.js';
2
3
  export class OorjaClientError extends Error {
3
4
  }
4
5
  const _maybeError = (response) => {
@@ -27,7 +28,7 @@ export const getRegion = async () => {
27
28
  method: 'GET',
28
29
  });
29
30
  if (response.status !== 200) {
30
- console.error('There seems to be an issue with the network');
31
+ printExitMessage('There seems to be an issue with the network');
31
32
  process.exit(1);
32
33
  }
33
34
  const settings = (await response.json());
@@ -46,7 +47,7 @@ export const getRegion = async () => {
46
47
  return minDistance.name;
47
48
  }
48
49
  catch {
49
- console.error('error determining region');
50
+ printExitMessage('error determining region');
50
51
  process.exit(1);
51
52
  }
52
53
  };
@@ -6,6 +6,7 @@ import { importKey, createRoomKey, exportKey } from '../encryption.js';
6
6
  import { loginByRoomOTP, preflight, promptAuth, resumeSession, validateCliVersion } from './preflight.js';
7
7
  import { getRegion } from './client.js';
8
8
  import ora from 'ora';
9
+ import { printExitMessage } from '../utils.js';
9
10
  export class InvalidRoomLink extends Error {
10
11
  }
11
12
  class OORJA {
@@ -47,7 +48,7 @@ class OORJA {
47
48
  const parseRoomURL = (roomLink) => {
48
49
  const url = new URL(roomLink);
49
50
  if (!url.hash || !getRoomId(url)) {
50
- console.log(INVALID_ROOM_LINK_MESSAGE);
51
+ printExitMessage(INVALID_ROOM_LINK_MESSAGE);
51
52
  process.exit(3);
52
53
  }
53
54
  return url;
@@ -80,7 +81,7 @@ const init = async (env, options = {}) => {
80
81
  else {
81
82
  token = await promptAuth(connectClient, linkForTokenGen(config));
82
83
  if (!token) {
83
- console.log('Token not provided :(');
84
+ printExitMessage('Token not provided :(');
84
85
  process.exit(12);
85
86
  }
86
87
  }
@@ -3,6 +3,7 @@ import inquirer from 'inquirer';
3
3
  import ora from 'ora';
4
4
  import { setENVAccessToken, CLI_VERSION, getENVAccessToken } from '../config.js';
5
5
  import { BadRequest, Unauthorized } from '../connect/errors.js';
6
+ import { printExitMessage } from '../utils.js';
6
7
  const promptToken = () => inquirer
7
8
  .prompt([
8
9
  {
@@ -48,7 +49,7 @@ export const loginByRoomOTP = async (connectClient, roomId) => {
48
49
  const otp = await promptRoomParticipantOTP();
49
50
  if (!otp) {
50
51
  console.log('OTP not provided :(');
51
- console.log(OTP_HELP_MESSAGE);
52
+ printExitMessage(OTP_HELP_MESSAGE);
52
53
  process.exit(213);
53
54
  }
54
55
  try {
@@ -57,7 +58,7 @@ export const loginByRoomOTP = async (connectClient, roomId) => {
57
58
  catch (e) {
58
59
  if (e instanceof BadRequest) {
59
60
  console.log(chalk.redBright('Invalid otp. It may have expired.'));
60
- console.log(OTP_HELP_MESSAGE);
61
+ printExitMessage(OTP_HELP_MESSAGE);
61
62
  process.exit();
62
63
  }
63
64
  throw e;
@@ -66,7 +67,7 @@ export const loginByRoomOTP = async (connectClient, roomId) => {
66
67
  export const validateCliVersion = async (connectClient) => {
67
68
  const manifest = await connectClient.fetchCliManifest();
68
69
  if (manifest.cliVersion > CLI_VERSION) {
69
- console.log(chalk.redBright('Your oorja cli is outdated. Please run: npm update -g oorja'));
70
+ printExitMessage(chalk.redBright('Your oorja cli is outdated. Please run: npm update -g oorja'));
70
71
  process.exit(1);
71
72
  }
72
73
  };
@@ -118,11 +119,13 @@ export const preflight = async (env, connectClient) => {
118
119
  catch (e) {
119
120
  setENVAccessToken(env, '');
120
121
  if (e instanceof Unauthorized) {
121
- spinner.fail('Your access token failed authentication, resetting...');
122
+ spinner.fail();
123
+ printExitMessage('Your access token failed authentication, resetting...');
122
124
  process.exit(33);
123
125
  }
124
126
  else {
125
- spinner.fail('Something went wrong :(');
127
+ spinner.fail();
128
+ printExitMessage('Something went wrong :(');
126
129
  }
127
130
  throw e;
128
131
  }
@@ -4,7 +4,7 @@ import { getDimensions, initScreen, areDimensionEqual, resizeBestFit } from './a
4
4
  import chalk from 'chalk';
5
5
  import { Unauthorized } from '../connect/errors.js';
6
6
  import { encrypt, decrypt } from '../encryption.js';
7
- import { Future } from '../utils.js';
7
+ import { Future, printExitMessage } from '../utils.js';
8
8
  var MessageType;
9
9
  (function (MessageType) {
10
10
  MessageType["IN"] = "i";
@@ -57,10 +57,8 @@ export const teletypeApp = (options) => {
57
57
  }
58
58
  if (options.shell.endsWith('zsh')) {
59
59
  stdout.write('Adjusting shell prompt to show streaming indicator\n');
60
- const zshFunc = ' _streaming_prompt_precmd() { if [[ "$PROMPT" != *\'📡 [streaming] \'* ]]; then PROMPT="📡 [streaming] $PROMPT"; fi; }\n';
61
- const zshHook = ' precmd_functions+=(_streaming_prompt_precmd)\n';
62
- term.write(zshFunc);
63
- term.write(zshHook);
60
+ // FIXME: this doesnt work on macos (or its probably due to some conflict with powerlevel10k)
61
+ term.write("PROMPT='📡 [streaming] '$PROMPT\n");
64
62
  }
65
63
  if (options.shell.endsWith('fish')) {
66
64
  stdout.write('Adjusting shell prompt to show streaming indicator\n');
@@ -71,11 +69,13 @@ export const teletypeApp = (options) => {
71
69
  // track own dimensions and keep it up to date
72
70
  setInterval(reEvaluateOwnDimensions, 1000);
73
71
  term.onData((d) => {
72
+ stdout.write(d);
74
73
  if (!ptyReady) {
75
74
  ptyReady = true;
76
- ptyFuture.resolve(true);
75
+ setTimeout(() => {
76
+ ptyFuture.resolve(true);
77
+ }, 100);
77
78
  }
78
- stdout.write(d);
79
79
  if (sessionCount < 2) {
80
80
  // 1 sub for own channel session
81
81
  // < 2 means no subscribers. no point pushing data.
@@ -96,15 +96,15 @@ export const teletypeApp = (options) => {
96
96
  stdin.on('data', (d) => term.write(d.toString('utf8')));
97
97
  },
98
98
  onClose: () => {
99
- console.log(chalk.redBright('connection closed, terminated stream.'));
99
+ printExitMessage(chalk.redBright('connection closed, terminated stream.'));
100
100
  process.exit(3);
101
101
  },
102
102
  onError: (err) => {
103
103
  if (err instanceof Unauthorized) {
104
- console.log(chalk.redBright(err.message));
104
+ printExitMessage(chalk.redBright(err.message));
105
105
  }
106
106
  else {
107
- console.log(chalk.redBright('connection error, terminated stream.'));
107
+ printExitMessage(chalk.redBright('connection error, terminated stream.'));
108
108
  }
109
109
  process.exit(4);
110
110
  },
@@ -125,7 +125,7 @@ export const teletypeApp = (options) => {
125
125
  term.write(data);
126
126
  }
127
127
  else {
128
- console.log(chalk.redBright(`unexpected input from user: ${userId}, terminating stream for safety. Please report this issue`));
128
+ printExitMessage(chalk.redBright(`unexpected input from user: ${userId}, terminating stream for safety. Please report this issue`));
129
129
  process.exit(5);
130
130
  }
131
131
  }
@@ -1,3 +1,4 @@
1
+ export declare const printExitMessage: (printMessage: string) => void;
1
2
  export declare const promptRoomLink: () => Promise<any>;
2
3
  export declare class Future<T> {
3
4
  promise: Promise<T>;
package/dist/lib/utils.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import inquirer from 'inquirer';
2
+ import { writeSync } from 'fs';
3
+ export const printExitMessage = (printMessage) => {
4
+ writeSync(process.stdout.fd, printMessage);
5
+ };
2
6
  export const promptRoomLink = async () => {
3
7
  const { spaceLink } = await inquirer.prompt([
4
8
  {
@@ -85,5 +85,5 @@
85
85
  ]
86
86
  }
87
87
  },
88
- "version": "2.1.3"
88
+ "version": "2.1.5"
89
89
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oorja",
3
3
  "description": "stream terminals to the web and more.",
4
- "version": "2.1.3",
4
+ "version": "2.1.5",
5
5
  "keywords": [
6
6
  "teletype",
7
7
  "terminal",