oorja 2.1.4 → 2.1.6

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
  }
@@ -5,7 +5,6 @@ export const initScreen = (username, hostname, shell, multiplexed) => {
5
5
  if (multiplexed) {
6
6
  console.log(chalk.yellowBright('You have allowed room participants to write to your shell'));
7
7
  }
8
- console.log(chalk.blue(`${chalk.bold(`${username}@${hostname}`)} Spawning streaming shell: ${chalk.bold(`${shell}`)}`));
9
8
  console.log(`Note: Your shell size may adjust for optimum viewing experience for all participants.\n
10
9
  This session is end-to-end encrypted.
11
10
  To terminate stream run ${chalk.yellowBright('exit')} or press ${chalk.yellowBright('ctrl-d')} \n`);
@@ -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";
@@ -39,10 +39,10 @@ export const teletypeApp = (options) => {
39
39
  multiplexed: options.multiplex,
40
40
  },
41
41
  onJoin: () => {
42
- initScreen(username, hostname, options.shell, options.multiplex);
43
42
  const stdin = options.process.stdin;
44
43
  const stdout = options.process.stdout;
45
44
  const dimensions = userDimensions[SELF];
45
+ console.log(chalk.blue(`${chalk.bold(`${username}@${hostname}`)} Spawning streaming shell: ${chalk.bold(`${options.shell}`)}`));
46
46
  term = spawn(options.shell, [], {
47
47
  name: 'xterm-256color',
48
48
  cols: dimensions.cols,
@@ -51,6 +51,7 @@ export const teletypeApp = (options) => {
51
51
  env: options.process.env,
52
52
  });
53
53
  ptyFuture.promise.then(() => {
54
+ initScreen(username, hostname, options.shell, options.multiplex);
54
55
  if (options.shell.endsWith('bash')) {
55
56
  stdout.write('Adjusting shell prompt to show streaming indicator\n');
56
57
  term.write("export PS1='📡 [streaming] '$PS1\n");
@@ -96,15 +97,15 @@ export const teletypeApp = (options) => {
96
97
  stdin.on('data', (d) => term.write(d.toString('utf8')));
97
98
  },
98
99
  onClose: () => {
99
- console.log(chalk.redBright('connection closed, terminated stream.'));
100
+ printExitMessage(chalk.redBright('connection closed, terminated stream.'));
100
101
  process.exit(3);
101
102
  },
102
103
  onError: (err) => {
103
104
  if (err instanceof Unauthorized) {
104
- console.log(chalk.redBright(err.message));
105
+ printExitMessage(chalk.redBright(err.message));
105
106
  }
106
107
  else {
107
- console.log(chalk.redBright('connection error, terminated stream.'));
108
+ printExitMessage(chalk.redBright('connection error, terminated stream.'));
108
109
  }
109
110
  process.exit(4);
110
111
  },
@@ -125,7 +126,7 @@ export const teletypeApp = (options) => {
125
126
  term.write(data);
126
127
  }
127
128
  else {
128
- console.log(chalk.redBright(`unexpected input from user: ${userId}, terminating stream for safety. Please report this issue`));
129
+ printExitMessage(chalk.redBright(`unexpected input from user: ${userId}, terminating stream for safety. Please report this issue`));
129
130
  process.exit(5);
130
131
  }
131
132
  }
@@ -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.4"
88
+ "version": "2.1.6"
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.4",
4
+ "version": "2.1.6",
5
5
  "keywords": [
6
6
  "teletype",
7
7
  "terminal",