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.
- package/README.md +73 -29
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.js +5 -0
- package/bin/teletype.js +7 -0
- package/dist/commands/signout.js +6 -10
- package/dist/commands/teletype/index.d.ts +5 -5
- package/dist/commands/teletype/index.js +57 -57
- package/dist/index.js +1 -5
- package/dist/lib/config.d.ts +4 -2
- package/dist/lib/config.js +33 -25
- package/dist/lib/encryption.d.ts +2 -2
- package/dist/lib/encryption.js +9 -17
- package/dist/lib/oorja/index.d.ts +5 -5
- package/dist/lib/oorja/index.js +43 -45
- package/dist/lib/oorja/preflight.d.ts +3 -3
- package/dist/lib/oorja/preflight.js +41 -40
- package/dist/lib/surya/errors.js +3 -9
- package/dist/lib/surya/index.d.ts +3 -3
- package/dist/lib/surya/index.js +168 -170
- package/dist/lib/surya/resources.js +2 -5
- package/dist/lib/surya/types.d.ts +1 -1
- package/dist/lib/surya/types.js +1 -2
- package/dist/lib/surya/vendor/phoenix/ajax.js +6 -9
- package/dist/lib/surya/vendor/phoenix/channel.d.ts +1 -1
- package/dist/lib/surya/vendor/phoenix/channel.js +28 -31
- package/dist/lib/surya/vendor/phoenix/constants.js +11 -14
- package/dist/lib/surya/vendor/phoenix/index.d.ts +5 -5
- package/dist/lib/surya/vendor/phoenix/index.js +6 -13
- package/dist/lib/surya/vendor/phoenix/longpoll.js +11 -14
- package/dist/lib/surya/vendor/phoenix/presence.js +1 -4
- package/dist/lib/surya/vendor/phoenix/push.js +1 -4
- package/dist/lib/surya/vendor/phoenix/serializer.js +3 -5
- package/dist/lib/surya/vendor/phoenix/socket.d.ts +2 -2
- package/dist/lib/surya/vendor/phoenix/socket.js +32 -35
- package/dist/lib/surya/vendor/phoenix/timer.js +1 -4
- package/dist/lib/surya/vendor/phoenix/utils.js +1 -5
- package/dist/lib/teletype/auxiliary.d.ts +1 -1
- package/dist/lib/teletype/auxiliary.js +6 -13
- package/dist/lib/teletype/index.d.ts +4 -4
- package/dist/lib/teletype/index.js +18 -22
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +10 -10
- package/oclif.manifest.json +3 -3
- package/package.json +55 -64
- package/bin/dev +0 -17
- package/bin/oorja +0 -5
- package/bin/teletype +0 -7
- /package/bin/{oorja.cmd → run.cmd} +0 -0
package/dist/lib/oorja/index.js
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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:
|
|
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
|
|
46
|
+
const url = new URL(roomLink);
|
|
48
47
|
if (!url.hash || !getRoomId(url)) {
|
|
49
|
-
console.log(
|
|
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
|
|
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 =
|
|
65
|
-
let suryaClient = new
|
|
66
|
-
await
|
|
67
|
-
let user = await
|
|
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
|
|
70
|
+
token = await loginByRoomOTP(suryaClient, options.roomId);
|
|
72
71
|
}
|
|
73
72
|
else {
|
|
74
|
-
token = await
|
|
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
|
-
|
|
79
|
+
setENVAccessToken(env, token);
|
|
81
80
|
}
|
|
82
81
|
await suryaClient.destroy();
|
|
83
|
-
suryaClient = new
|
|
84
|
-
user = await
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const promptRoomParticipantOTP = () =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
38
|
-
const
|
|
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
|
|
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
|
-
|
|
58
|
-
const validateCliVersion = async (suryaClient) => {
|
|
62
|
+
export const validateCliVersion = async (suryaClient) => {
|
|
59
63
|
const manifest = await suryaClient.fetchCliManifest();
|
|
60
|
-
if (manifest.cliVersion >
|
|
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
|
-
|
|
66
|
-
const
|
|
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
|
|
80
|
-
|
|
82
|
+
if (e instanceof Unauthorized) {
|
|
83
|
+
setENVAccessToken(env, "");
|
|
81
84
|
return null;
|
|
82
85
|
}
|
|
83
86
|
throw e;
|
|
84
87
|
}
|
|
85
88
|
};
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
-
if (e instanceof
|
|
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;
|
package/dist/lib/surya/errors.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
7
|
-
class Unauthorized extends ClientError {
|
|
3
|
+
export class Unauthorized extends ClientError {
|
|
8
4
|
}
|
|
9
|
-
|
|
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 {
|