oorja 1.9.1 → 1.11.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 (49) hide show
  1. package/README.md +73 -29
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +5 -0
  4. package/bin/run.js +5 -0
  5. package/bin/teletype.js +7 -0
  6. package/dist/commands/signout.js +6 -10
  7. package/dist/commands/teletype/index.d.ts +5 -5
  8. package/dist/commands/teletype/index.js +57 -57
  9. package/dist/index.js +1 -5
  10. package/dist/lib/config.d.ts +4 -2
  11. package/dist/lib/config.js +33 -25
  12. package/dist/lib/encryption.d.ts +2 -2
  13. package/dist/lib/encryption.js +9 -17
  14. package/dist/lib/oorja/index.d.ts +5 -5
  15. package/dist/lib/oorja/index.js +43 -45
  16. package/dist/lib/oorja/preflight.d.ts +3 -3
  17. package/dist/lib/oorja/preflight.js +41 -40
  18. package/dist/lib/surya/errors.js +3 -9
  19. package/dist/lib/surya/index.d.ts +3 -3
  20. package/dist/lib/surya/index.js +168 -170
  21. package/dist/lib/surya/resources.js +2 -5
  22. package/dist/lib/surya/types.d.ts +1 -1
  23. package/dist/lib/surya/types.js +1 -2
  24. package/dist/lib/surya/vendor/phoenix/ajax.js +6 -9
  25. package/dist/lib/surya/vendor/phoenix/channel.d.ts +1 -1
  26. package/dist/lib/surya/vendor/phoenix/channel.js +28 -31
  27. package/dist/lib/surya/vendor/phoenix/constants.js +11 -14
  28. package/dist/lib/surya/vendor/phoenix/index.d.ts +5 -5
  29. package/dist/lib/surya/vendor/phoenix/index.js +6 -13
  30. package/dist/lib/surya/vendor/phoenix/longpoll.js +11 -14
  31. package/dist/lib/surya/vendor/phoenix/presence.js +1 -4
  32. package/dist/lib/surya/vendor/phoenix/push.js +1 -4
  33. package/dist/lib/surya/vendor/phoenix/serializer.js +3 -5
  34. package/dist/lib/surya/vendor/phoenix/socket.d.ts +2 -2
  35. package/dist/lib/surya/vendor/phoenix/socket.js +32 -35
  36. package/dist/lib/surya/vendor/phoenix/timer.js +1 -4
  37. package/dist/lib/surya/vendor/phoenix/utils.js +1 -5
  38. package/dist/lib/teletype/auxiliary.d.ts +1 -1
  39. package/dist/lib/teletype/auxiliary.js +6 -13
  40. package/dist/lib/teletype/index.d.ts +4 -4
  41. package/dist/lib/teletype/index.js +18 -22
  42. package/dist/lib/utils.d.ts +1 -1
  43. package/dist/lib/utils.js +10 -10
  44. package/oclif.manifest.json +3 -3
  45. package/package.json +55 -64
  46. package/bin/dev +0 -17
  47. package/bin/oorja +0 -5
  48. package/bin/teletype +0 -7
  49. /package/bin/{oorja.cmd → run.cmd} +0 -0
@@ -1,58 +1,57 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getApp = exports.InvalidRoomLink = void 0;
4
- const config_1 = require("../config");
5
- const teletype_1 = require("../teletype");
6
- const surya_1 = require("../surya");
7
- const url_1 = require("url");
8
- const encryption_1 = require("../encryption");
9
- const preflight_1 = require("./preflight");
10
- class InvalidRoomLink extends Error {
1
+ import { determineENV, getoorjaConfig, INVALID_ROOM_LINK_MESSAGE, setENVAccessToken, } from "../config.js";
2
+ import { teletypeApp } from "../teletype/index.js";
3
+ import { SuryaClient } from "../surya/index.js";
4
+ import { URL, URLSearchParams } from "url";
5
+ import { importKey, createRoomKey, exportKey } from "../encryption.js";
6
+ import { loginByRoomOTP, preflight, promptAuth, resumeSession, validateCliVersion, } from "./preflight.js";
7
+ export class InvalidRoomLink extends Error {
11
8
  }
12
- exports.InvalidRoomLink = InvalidRoomLink;
13
9
  class OORJA {
10
+ config;
11
+ suryaClient;
12
+ user;
14
13
  // should capture domain related commands and queries
15
14
  constructor(config, suryaClient, user) {
16
15
  this.config = config;
17
16
  this.suryaClient = suryaClient;
18
17
  this.user = user;
19
- this.createRoom = async (options) => {
20
- const room = await this.suryaClient.createRoom(options);
21
- const roomKey = (0, encryption_1.createRoomKey)(room.id);
22
- return {
23
- room,
24
- roomKey,
25
- };
26
- };
27
- this.linkForRoom = (roomKey) => {
28
- return `${oorjaURL(this.config)}/rooms?id=${roomKey.roomId}#${(0, encryption_1.exportKey)(roomKey.key)}`;
29
- };
30
- this.teletype = (options) => {
31
- return (0, teletype_1.teletypeApp)({
32
- userId: this.user.id,
33
- joinChannel: this.suryaClient.joinChannel,
34
- ...options,
35
- });
36
- };
37
18
  }
19
+ createRoom = async (options) => {
20
+ const room = await this.suryaClient.createRoom(options);
21
+ const roomKey = createRoomKey(room.id);
22
+ return {
23
+ room,
24
+ roomKey,
25
+ };
26
+ };
27
+ linkForRoom = (roomKey) => {
28
+ return `${oorjaURL(this.config)}/rooms?id=${roomKey.roomId}#${exportKey(roomKey.key)}`;
29
+ };
38
30
  getRoomKey(roomLink) {
39
31
  const url = parseRoomURL(roomLink);
40
32
  return {
41
- key: (0, encryption_1.importKey)(url.hash),
33
+ key: importKey(url.hash),
42
34
  roomId: getRoomId(url),
43
35
  };
44
36
  }
37
+ teletype = (options) => {
38
+ return teletypeApp({
39
+ userId: this.user.id,
40
+ joinChannel: this.suryaClient.joinChannel,
41
+ ...options,
42
+ });
43
+ };
45
44
  }
46
45
  const parseRoomURL = (roomLink) => {
47
- const url = new url_1.URL(roomLink);
46
+ const url = new URL(roomLink);
48
47
  if (!url.hash || !getRoomId(url)) {
49
- console.log(config_1.INVALID_ROOM_LINK_MESSAGE);
48
+ console.log(INVALID_ROOM_LINK_MESSAGE);
50
49
  process.exit(3);
51
50
  }
52
51
  return url;
53
52
  };
54
53
  const getRoomId = (roomURL) => {
55
- const params = new url_1.URLSearchParams(roomURL.search);
54
+ const params = new URLSearchParams(roomURL.search);
56
55
  return params.get("id") || undefined;
57
56
  };
58
57
  const oorjaURL = (config) => {
@@ -61,35 +60,35 @@ const oorjaURL = (config) => {
61
60
  };
62
61
  const linkForTokenGen = (config) => `${oorjaURL(config)}/access_token`;
63
62
  const init = async (env, options = {}) => {
64
- const config = (0, config_1.getoorjaConfig)(env);
65
- let suryaClient = new surya_1.SuryaClient(env);
66
- await (0, preflight_1.validateCliVersion)(suryaClient);
67
- let user = await (0, preflight_1.resumeSession)(env, suryaClient, options.roomId);
63
+ const config = getoorjaConfig(env);
64
+ let suryaClient = new SuryaClient(env);
65
+ await validateCliVersion(suryaClient);
66
+ let user = await resumeSession(env, suryaClient, options.roomId);
68
67
  if (!user) {
69
68
  let token = "";
70
69
  if (options.roomId) {
71
- token = await (0, preflight_1.loginByRoomOTP)(suryaClient, options.roomId);
70
+ token = await loginByRoomOTP(suryaClient, options.roomId);
72
71
  }
73
72
  else {
74
- token = await (0, preflight_1.promptAuth)(suryaClient, linkForTokenGen(config));
73
+ token = await promptAuth(suryaClient, linkForTokenGen(config));
75
74
  if (!token) {
76
75
  console.log("Token not provided :(");
77
76
  process.exit(12);
78
77
  }
79
78
  }
80
- (0, config_1.setENVAccessToken)(env, token);
79
+ setENVAccessToken(env, token);
81
80
  }
82
81
  await suryaClient.destroy();
83
- suryaClient = new surya_1.SuryaClient(env);
84
- user = await (0, preflight_1.preflight)(env, suryaClient);
82
+ suryaClient = new SuryaClient(env);
83
+ user = await preflight(env, suryaClient);
85
84
  return new OORJA(config, suryaClient, user);
86
85
  };
87
86
  let currentEnv;
88
87
  let oorja;
89
- const getApp = async (options = {}) => {
88
+ export const getApp = async (options = {}) => {
90
89
  const { roomLink } = options;
91
90
  const roomURL = roomLink ? parseRoomURL(roomLink) : undefined;
92
- const env = (0, config_1.determineENV)(undefined);
91
+ const env = determineENV(undefined);
93
92
  if (oorja) {
94
93
  if (env !== currentEnv) {
95
94
  return Promise.reject("Attempt to run different env in same session");
@@ -98,4 +97,3 @@ const getApp = async (options = {}) => {
98
97
  }
99
98
  return await init(env, { roomId: roomURL ? getRoomId(roomURL) : undefined });
100
99
  };
101
- exports.getApp = getApp;
@@ -1,6 +1,6 @@
1
- import { env } from "../config";
2
- import { SuryaClient } from "../surya";
3
- import { User } from "../surya/types";
1
+ import { env } from "../config.js";
2
+ import { SuryaClient } from "../surya/index.js";
3
+ import { User } from "../surya/types.js";
4
4
  export declare const promptRoomParticipantOTP: () => Promise<string>;
5
5
  export declare const promptAuth: (suryaClient: SuryaClient, generateTokenLink: string) => Promise<string>;
6
6
  export declare const loginByRoomOTP: (suryaClient: SuryaClient, roomId: string) => Promise<string>;
@@ -1,29 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preflight = exports.resumeSession = exports.validateCliVersion = exports.loginByRoomOTP = exports.promptAuth = exports.promptRoomParticipantOTP = void 0;
4
- const chalk = require("chalk");
5
- const { Input, Select } = require("enquirer");
6
- const ora = require("ora");
7
- const config_1 = require("../config");
8
- const errors_1 = require("../surya/errors");
9
- const promptToken = () => new Input({
10
- name: "Access Token",
11
- message: "Please enter your access token for authentication:",
12
- }).run();
13
- const promptRoomParticipantOTP = () => new Input({
14
- name: "OTP prompt",
15
- message: "Please enter your OTP for authentication:",
16
- }).run();
17
- exports.promptRoomParticipantOTP = promptRoomParticipantOTP;
1
+ import chalk from "chalk";
2
+ import inquirer from 'inquirer';
3
+ import ora from "ora";
4
+ import { setENVAccessToken, CLI_VERSION, getENVAccessToken, } from "../config.js";
5
+ import { BadRequest, Unauthorized } from "../surya/errors.js";
6
+ const promptToken = () => inquirer.prompt([
7
+ {
8
+ type: 'input',
9
+ name: 'accessToken',
10
+ message: 'Please enter your access token for authentication:',
11
+ }
12
+ ]).then(answers => answers.accessToken);
13
+ export const promptRoomParticipantOTP = () => inquirer.prompt([
14
+ {
15
+ type: 'input',
16
+ name: 'otp',
17
+ message: 'Please enter your OTP for authentication (switch to teletype app in the room and click on blue "Generate OTP" button):',
18
+ }
19
+ ]).then(answers => answers.otp);
18
20
  const OTP_HELP_MESSAGE = "You can generate OTP from the room, it's in the instruction steps";
19
- const promptAuth = async (suryaClient, generateTokenLink) => {
21
+ export const promptAuth = async (suryaClient, generateTokenLink) => {
20
22
  const ANON = "Proceed as an anonymous user";
21
23
  const SIGN_IN = "Sign-in with oorja";
22
24
  console.log(`\n${chalk.bold("PRO-TIP:")} If you sign-in, you can control your shell from the web-ui as well, without enabling collaboration mode for the other participants\n`);
23
- const answer = await new Select({
24
- message: "You need an access-token for authentication.\n ",
25
- choices: [ANON, SIGN_IN],
26
- }).run();
25
+ const { answer } = await inquirer.prompt([
26
+ {
27
+ type: 'list',
28
+ name: 'answer',
29
+ message: 'You need an access-token for authentication.\n ',
30
+ choices: [ANON, SIGN_IN],
31
+ }
32
+ ]);
27
33
  switch (answer) {
28
34
  case ANON:
29
35
  console.log("Creating anonymous user...");
@@ -34,9 +40,8 @@ const promptAuth = async (suryaClient, generateTokenLink) => {
34
40
  }
35
41
  throw Error("Unexpected input");
36
42
  };
37
- exports.promptAuth = promptAuth;
38
- const loginByRoomOTP = async (suryaClient, roomId) => {
39
- const otp = await (0, exports.promptRoomParticipantOTP)();
43
+ export const loginByRoomOTP = async (suryaClient, roomId) => {
44
+ const otp = await promptRoomParticipantOTP();
40
45
  if (!otp) {
41
46
  console.log("OTP not provided :(");
42
47
  console.log(OTP_HELP_MESSAGE);
@@ -46,7 +51,7 @@ const loginByRoomOTP = async (suryaClient, roomId) => {
46
51
  return await suryaClient.accessTokenFromRoomParticipantOTP(roomId, otp);
47
52
  }
48
53
  catch (e) {
49
- if (e instanceof errors_1.BadRequest) {
54
+ if (e instanceof BadRequest) {
50
55
  console.log(chalk.redBright("Invalid otp. It may have expired."));
51
56
  console.log(OTP_HELP_MESSAGE);
52
57
  process.exit();
@@ -54,17 +59,15 @@ const loginByRoomOTP = async (suryaClient, roomId) => {
54
59
  throw e;
55
60
  }
56
61
  };
57
- exports.loginByRoomOTP = loginByRoomOTP;
58
- const validateCliVersion = async (suryaClient) => {
62
+ export const validateCliVersion = async (suryaClient) => {
59
63
  const manifest = await suryaClient.fetchCliManifest();
60
- if (manifest.cliVersion > config_1.CLI_VERSION) {
64
+ if (manifest.cliVersion > CLI_VERSION) {
61
65
  console.log(chalk.redBright("Your oorja cli is outdated. Please run: npm update -g oorja"));
62
66
  process.exit(1);
63
67
  }
64
68
  };
65
- exports.validateCliVersion = validateCliVersion;
66
- const resumeSession = async (env, suryaClient, roomId) => {
67
- const token = (0, config_1.getENVAccessToken)(env);
69
+ export const resumeSession = async (env, suryaClient, roomId) => {
70
+ const token = getENVAccessToken(env);
68
71
  if (!token)
69
72
  return null;
70
73
  // try to validate authorization with existing token
@@ -76,15 +79,14 @@ const resumeSession = async (env, suryaClient, roomId) => {
76
79
  return user;
77
80
  }
78
81
  catch (e) {
79
- if (e instanceof errors_1.Unauthorized) {
80
- (0, config_1.setENVAccessToken)(env, "");
82
+ if (e instanceof Unauthorized) {
83
+ setENVAccessToken(env, "");
81
84
  return null;
82
85
  }
83
86
  throw e;
84
87
  }
85
88
  };
86
- exports.resumeSession = resumeSession;
87
- const preflight = async (env, suryaClient) => {
89
+ export const preflight = async (env, suryaClient) => {
88
90
  const spinner = ora({
89
91
  text: "Authenticating",
90
92
  discardStdin: false,
@@ -94,7 +96,7 @@ const preflight = async (env, suryaClient) => {
94
96
  spinner.succeed(`Authenticated: Welcome ${user.name}`);
95
97
  if (user.profileType === "anon") {
96
98
  // don't persist tokens for anonymous users
97
- (0, config_1.setENVAccessToken)(env, "");
99
+ setENVAccessToken(env, "");
98
100
  console.log(chalk.yellowBright("You're an anonymous user. CLI will not remember the auth-token"));
99
101
  }
100
102
  spinner.start("Connecting..");
@@ -110,8 +112,8 @@ const preflight = async (env, suryaClient) => {
110
112
  });
111
113
  }
112
114
  catch (e) {
113
- (0, config_1.setENVAccessToken)(env, "");
114
- if (e instanceof errors_1.Unauthorized) {
115
+ setENVAccessToken(env, "");
116
+ if (e instanceof Unauthorized) {
115
117
  spinner.fail("Your access token failed authentication, resetting...");
116
118
  process.exit(33);
117
119
  }
@@ -121,4 +123,3 @@ const preflight = async (env, suryaClient) => {
121
123
  throw e;
122
124
  }
123
125
  };
124
- exports.preflight = preflight;
@@ -1,12 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BadRequest = exports.Unauthorized = exports.ClientError = void 0;
4
- class ClientError extends Error {
1
+ export class ClientError extends Error {
5
2
  }
6
- exports.ClientError = ClientError;
7
- class Unauthorized extends ClientError {
3
+ export class Unauthorized extends ClientError {
8
4
  }
9
- exports.Unauthorized = Unauthorized;
10
- class BadRequest extends ClientError {
5
+ export class BadRequest extends ClientError {
11
6
  }
12
- exports.BadRequest = BadRequest;
@@ -1,6 +1,6 @@
1
- import { User, RoomApps, Room, CliManifest } from "./types";
2
- import { env } from "../config";
3
- import { Channel } from "./vendor/phoenix";
1
+ import { User, RoomApps, Room, CliManifest } from "./types.js";
2
+ import { env } from "../config.js";
3
+ import { Channel } from "./vendor/phoenix/index.js";
4
4
  export declare class SuryaError extends Error {
5
5
  }
6
6
  export declare class SuryaClient {