oorja 1.5.1 → 1.6.2
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 +5 -3
- package/lib/commands/signout.js +2 -2
- package/lib/commands/teletype/index.js +3 -3
- package/lib/lib/config.d.ts +5 -6
- package/lib/lib/config.js +12 -7
- package/lib/lib/encryption.d.ts +1 -1
- package/lib/lib/encryption.js +12 -7
- package/lib/lib/index.js +1 -0
- package/lib/lib/oorja/index.js +14 -13
- package/lib/lib/oorja/preflight.d.ts +1 -1
- package/lib/lib/oorja/preflight.js +17 -11
- package/lib/lib/surya/index.d.ts +2 -2
- package/lib/lib/surya/index.js +15 -13
- package/lib/lib/surya/types.d.ts +10 -10
- package/lib/lib/surya/vendor/phoenix/ajax.d.ts +8 -0
- package/lib/lib/surya/vendor/phoenix/ajax.js +85 -0
- package/lib/lib/surya/vendor/phoenix/channel.d.ts +154 -0
- package/lib/lib/surya/vendor/phoenix/channel.js +311 -0
- package/lib/lib/surya/vendor/phoenix/constants.d.ts +33 -0
- package/lib/lib/surya/vendor/phoenix/constants.js +32 -0
- package/lib/lib/surya/vendor/phoenix/index.d.ts +199 -0
- package/lib/lib/surya/vendor/phoenix/index.js +207 -0
- package/lib/lib/surya/vendor/phoenix/longpoll.d.ts +12 -0
- package/lib/lib/surya/vendor/phoenix/longpoll.js +129 -0
- package/lib/lib/surya/vendor/phoenix/presence.d.ts +44 -0
- package/lib/lib/surya/vendor/phoenix/presence.js +155 -0
- package/lib/lib/surya/vendor/phoenix/push.d.ts +57 -0
- package/lib/lib/surya/vendor/phoenix/push.js +125 -0
- package/lib/lib/surya/vendor/phoenix/serializer.d.ts +53 -0
- package/lib/lib/surya/vendor/phoenix/serializer.js +102 -0
- package/lib/lib/surya/vendor/phoenix/socket.d.ts +222 -0
- package/lib/lib/surya/vendor/phoenix/socket.js +544 -0
- package/lib/lib/surya/vendor/phoenix/timer.d.ts +25 -0
- package/lib/lib/surya/vendor/phoenix/timer.js +43 -0
- package/lib/lib/surya/vendor/phoenix/utils.d.ts +1 -0
- package/lib/lib/surya/vendor/phoenix/utils.js +15 -0
- package/lib/lib/teletype/auxiliary.d.ts +1 -1
- package/lib/lib/teletype/auxiliary.js +8 -4
- package/lib/lib/teletype/index.d.ts +1 -1
- package/lib/lib/teletype/index.js +13 -12
- package/lib/lib/utils.js +2 -1
- package/oclif.manifest.json +1 -1
- package/package.json +10 -9
- package/lib/lib/surya/vendor/phoenix.d.ts +0 -486
- package/lib/lib/surya/vendor/phoenix.js +0 -1299
package/README.md
CHANGED
|
@@ -24,8 +24,10 @@ Your stream can be view-only or collaboration enabled (command-line flag).
|
|
|
24
24
|
|
|
25
25
|
# Install and stream!
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
|
|
27
|
+
- Currently cli is available via npm. <br />
|
|
28
|
+
<a href="https://nodejs.org/en/download/" target="_blank">
|
|
29
|
+
You can setup node/npm from here
|
|
30
|
+
</a>
|
|
29
31
|
- **optional but highly recommended for successful install -> [npm install without sudo](https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md)**.
|
|
30
32
|
- `npm install -g oorja`
|
|
31
33
|
- `teletype`
|
|
@@ -93,7 +95,7 @@ EXAMPLES
|
|
|
93
95
|
Will also allow room participants to write to your terminal!
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
_See code: [src/commands/teletype/index.ts](https://github.com/akshaykmr/teletype/blob/v1.
|
|
98
|
+
_See code: [src/commands/teletype/index.ts](https://github.com/akshaykmr/teletype/blob/v1.6.1/src/commands/teletype/index.ts)_
|
|
97
99
|
|
|
98
100
|
|
|
99
101
|
## `oorja signout`
|
package/lib/commands/signout.js
CHANGED
|
@@ -5,8 +5,8 @@ const command_1 = require("@oclif/command");
|
|
|
5
5
|
const config_1 = require("../lib/config");
|
|
6
6
|
class SignOut extends command_1.Command {
|
|
7
7
|
async run() {
|
|
8
|
-
const env = config_1.determineENV();
|
|
9
|
-
config_1.setENVAccessToken(env, "");
|
|
8
|
+
const env = (0, config_1.determineENV)();
|
|
9
|
+
(0, config_1.setENVAccessToken)(env, "");
|
|
10
10
|
console.log("Sign-out complete");
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -36,18 +36,18 @@ class TeleTypeCommand extends command_1.Command {
|
|
|
36
36
|
process.exit(0);
|
|
37
37
|
}
|
|
38
38
|
async streamToLink(options) {
|
|
39
|
-
const roomLink = options.roomLink || (await utils_1.promptRoomLink());
|
|
39
|
+
const roomLink = options.roomLink || (await (0, utils_1.promptRoomLink)());
|
|
40
40
|
if (!roomLink) {
|
|
41
41
|
console.log(chalk.redBright("Room link not provided :("));
|
|
42
42
|
process.exit();
|
|
43
43
|
}
|
|
44
|
-
const app = await oorja_1.getApp({ roomLink });
|
|
44
|
+
const app = await (0, oorja_1.getApp)({ roomLink });
|
|
45
45
|
const roomKey = app.getRoomKey(roomLink);
|
|
46
46
|
this.clearstdin();
|
|
47
47
|
await app.teletype(Object.assign(Object.assign({ roomKey }, options), { process }));
|
|
48
48
|
}
|
|
49
49
|
async createRoomAndStream({ shell, multiplex, }) {
|
|
50
|
-
const app = await oorja_1.getApp();
|
|
50
|
+
const app = await (0, oorja_1.getApp)();
|
|
51
51
|
const spinner = ora({
|
|
52
52
|
text: chalk.bold("Creating room with TeleType app"),
|
|
53
53
|
discardStdin: false,
|
package/lib/lib/config.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { URL } from "url";
|
|
3
|
-
export declare const CLI_VERSION = 1.
|
|
2
|
+
export declare const CLI_VERSION = 1.6;
|
|
4
3
|
export declare const config: any;
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type env = "staging" | "local" | "prod" | "prod-teletype";
|
|
5
|
+
export type SuryaConfig = {
|
|
7
6
|
host: string;
|
|
8
7
|
enableTLS: boolean;
|
|
9
8
|
token: string;
|
|
@@ -11,10 +10,10 @@ export declare type SuryaConfig = {
|
|
|
11
10
|
export declare const getSuryaConfig: (env: env) => SuryaConfig;
|
|
12
11
|
export declare const ROOM_LINK_SAMPLE = "https://oorja.io/rooms?id=foo#key";
|
|
13
12
|
export declare const INVALID_ROOM_LINK_MESSAGE: string;
|
|
14
|
-
export declare const determineENV: (roomURL?: URL
|
|
13
|
+
export declare const determineENV: (roomURL?: URL) => env;
|
|
15
14
|
export declare const getENVAccessToken: (env: env) => string;
|
|
16
15
|
export declare const setENVAccessToken: (env: env, token: string) => void;
|
|
17
|
-
export
|
|
16
|
+
export type oorjaConfig = {
|
|
18
17
|
host: string;
|
|
19
18
|
enableTLS: boolean;
|
|
20
19
|
};
|
package/lib/lib/config.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getoorjaConfig = exports.setENVAccessToken = exports.getENVAccessToken = exports.determineENV = exports.INVALID_ROOM_LINK_MESSAGE = exports.ROOM_LINK_SAMPLE = exports.getSuryaConfig = exports.config = exports.CLI_VERSION = void 0;
|
|
4
4
|
const chalk = require("chalk");
|
|
5
|
-
exports.CLI_VERSION = 1.
|
|
5
|
+
exports.CLI_VERSION = 1.6;
|
|
6
6
|
const Conf = require("conf");
|
|
7
7
|
exports.config = new Conf({
|
|
8
8
|
projectName: "oorja",
|
|
9
9
|
projectVersion: exports.CLI_VERSION,
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
const getSuryaConfig = (env) => {
|
|
12
12
|
const getHost = (env) => {
|
|
13
13
|
switch (env) {
|
|
14
14
|
case "local":
|
|
@@ -21,13 +21,14 @@ exports.getSuryaConfig = (env) => {
|
|
|
21
21
|
};
|
|
22
22
|
return {
|
|
23
23
|
host: getHost(env),
|
|
24
|
-
token: exports.getENVAccessToken(env),
|
|
24
|
+
token: (0, exports.getENVAccessToken)(env),
|
|
25
25
|
enableTLS: env !== "local",
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
+
exports.getSuryaConfig = getSuryaConfig;
|
|
28
29
|
exports.ROOM_LINK_SAMPLE = "https://oorja.io/rooms?id=foo#key";
|
|
29
30
|
exports.INVALID_ROOM_LINK_MESSAGE = `${chalk.redBright("invalid url ")}🤔. It should look like: ${chalk.blue(exports.ROOM_LINK_SAMPLE)}`;
|
|
30
|
-
|
|
31
|
+
const determineENV = (roomURL) => {
|
|
31
32
|
if (!roomURL)
|
|
32
33
|
return exports.config.get("env") || "prod-teletype";
|
|
33
34
|
switch (roomURL.host) {
|
|
@@ -44,13 +45,16 @@ exports.determineENV = (roomURL) => {
|
|
|
44
45
|
process.exit(1);
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
exports.
|
|
48
|
+
exports.determineENV = determineENV;
|
|
49
|
+
const getENVAccessToken = (env) => {
|
|
48
50
|
return exports.config.get(`${env}-access-token`);
|
|
49
51
|
};
|
|
50
|
-
exports.
|
|
52
|
+
exports.getENVAccessToken = getENVAccessToken;
|
|
53
|
+
const setENVAccessToken = (env, token) => {
|
|
51
54
|
exports.config.set(`${env}-access-token`, token);
|
|
52
55
|
};
|
|
53
|
-
exports.
|
|
56
|
+
exports.setENVAccessToken = setENVAccessToken;
|
|
57
|
+
const getoorjaConfig = (env) => {
|
|
54
58
|
let host;
|
|
55
59
|
switch (env) {
|
|
56
60
|
case "local":
|
|
@@ -71,3 +75,4 @@ exports.getoorjaConfig = (env) => {
|
|
|
71
75
|
enableTLS: env !== "local",
|
|
72
76
|
};
|
|
73
77
|
};
|
|
78
|
+
exports.getoorjaConfig = getoorjaConfig;
|
package/lib/lib/encryption.d.ts
CHANGED
package/lib/lib/encryption.js
CHANGED
|
@@ -6,30 +6,35 @@ const msgpack_1 = require("@msgpack/msgpack");
|
|
|
6
6
|
const ALG = "aes-128-gcm";
|
|
7
7
|
const KEY_SIZE = 16; // 128 bit AES
|
|
8
8
|
const AUTH_TAG_LEN = 16;
|
|
9
|
-
|
|
9
|
+
const createRoomKey = (roomId) => ({
|
|
10
10
|
roomId,
|
|
11
11
|
key: createAESEncryptionKey(),
|
|
12
12
|
});
|
|
13
|
+
exports.createRoomKey = createRoomKey;
|
|
13
14
|
const createAESEncryptionKey = () => crypto.randomBytes(KEY_SIZE);
|
|
14
|
-
|
|
15
|
-
exports.
|
|
15
|
+
const exportKey = (key) => key.toString("base64");
|
|
16
|
+
exports.exportKey = exportKey;
|
|
17
|
+
const importKey = (exportedKey) => Buffer.from(exportedKey, "base64");
|
|
18
|
+
exports.importKey = importKey;
|
|
16
19
|
const createIV = () => crypto.randomBytes(16);
|
|
17
|
-
|
|
20
|
+
const encrypt = (data, roomKey) => {
|
|
18
21
|
const iv = createIV();
|
|
19
22
|
const cipher = crypto.createCipheriv(ALG, roomKey.key, iv);
|
|
20
23
|
return {
|
|
21
24
|
iv,
|
|
22
25
|
data: Buffer.concat([
|
|
23
|
-
cipher.update(msgpack_1.encode(data)),
|
|
26
|
+
cipher.update((0, msgpack_1.encode)(data)),
|
|
24
27
|
cipher.final(),
|
|
25
28
|
cipher.getAuthTag(),
|
|
26
29
|
]),
|
|
27
30
|
};
|
|
28
31
|
};
|
|
29
|
-
exports.
|
|
32
|
+
exports.encrypt = encrypt;
|
|
33
|
+
const decrypt = (payload, roomKey) => {
|
|
30
34
|
const data = payload.data.slice(0, payload.data.length - AUTH_TAG_LEN);
|
|
31
35
|
const authTag = payload.data.slice(payload.data.length - AUTH_TAG_LEN);
|
|
32
36
|
const decipher = crypto.createDecipheriv(ALG, roomKey.key, payload.iv);
|
|
33
37
|
decipher.setAuthTag(authTag);
|
|
34
|
-
return msgpack_1.decode(Buffer.concat([decipher.update(data), decipher.final()]));
|
|
38
|
+
return (0, msgpack_1.decode)(Buffer.concat([decipher.update(data), decipher.final()]));
|
|
35
39
|
};
|
|
40
|
+
exports.decrypt = decrypt;
|
package/lib/lib/index.js
CHANGED
package/lib/lib/oorja/index.js
CHANGED
|
@@ -18,23 +18,23 @@ class OORJA {
|
|
|
18
18
|
this.user = user;
|
|
19
19
|
this.createRoom = async (options) => {
|
|
20
20
|
const room = await this.suryaClient.createRoom(options);
|
|
21
|
-
const roomKey = encryption_1.createRoomKey(room.id);
|
|
21
|
+
const roomKey = (0, encryption_1.createRoomKey)(room.id);
|
|
22
22
|
return {
|
|
23
23
|
room,
|
|
24
24
|
roomKey,
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
this.linkForRoom = (roomKey) => {
|
|
28
|
-
return `${oorjaURL(this.config)}/rooms?id=${roomKey.roomId}#${encryption_1.exportKey(roomKey.key)}`;
|
|
28
|
+
return `${oorjaURL(this.config)}/rooms?id=${roomKey.roomId}#${(0, encryption_1.exportKey)(roomKey.key)}`;
|
|
29
29
|
};
|
|
30
30
|
this.teletype = (options) => {
|
|
31
|
-
return teletype_1.teletypeApp(Object.assign({ userId: this.user.id, joinChannel: this.suryaClient.joinChannel }, options));
|
|
31
|
+
return (0, teletype_1.teletypeApp)(Object.assign({ userId: this.user.id, joinChannel: this.suryaClient.joinChannel }, options));
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
getRoomKey(roomLink) {
|
|
35
35
|
const url = parseRoomURL(roomLink);
|
|
36
36
|
return {
|
|
37
|
-
key: encryption_1.importKey(url.hash),
|
|
37
|
+
key: (0, encryption_1.importKey)(url.hash),
|
|
38
38
|
roomId: url.searchParams.get("id"),
|
|
39
39
|
};
|
|
40
40
|
}
|
|
@@ -57,35 +57,35 @@ const oorjaURL = (config) => {
|
|
|
57
57
|
};
|
|
58
58
|
const linkForTokenGen = (config) => `${oorjaURL(config)}/access_token`;
|
|
59
59
|
const init = async (env, options = {}) => {
|
|
60
|
-
const config = config_1.getoorjaConfig(env);
|
|
60
|
+
const config = (0, config_1.getoorjaConfig)(env);
|
|
61
61
|
let suryaClient = new surya_1.SuryaClient(env);
|
|
62
|
-
await preflight_1.validateCliVersion(suryaClient);
|
|
63
|
-
let user = await preflight_1.resumeSession(env, suryaClient, options.roomId);
|
|
62
|
+
await (0, preflight_1.validateCliVersion)(suryaClient);
|
|
63
|
+
let user = await (0, preflight_1.resumeSession)(env, suryaClient, options.roomId);
|
|
64
64
|
if (!user) {
|
|
65
65
|
let token = "";
|
|
66
66
|
if (options.roomId) {
|
|
67
|
-
token = await preflight_1.loginByRoomOTP(suryaClient, options.roomId);
|
|
67
|
+
token = await (0, preflight_1.loginByRoomOTP)(suryaClient, options.roomId);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
token = await preflight_1.promptAuth(suryaClient, linkForTokenGen(config));
|
|
70
|
+
token = await (0, preflight_1.promptAuth)(suryaClient, linkForTokenGen(config));
|
|
71
71
|
if (!token) {
|
|
72
72
|
console.log("Token not provided :(");
|
|
73
73
|
process.exit(12);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
config_1.setENVAccessToken(env, token);
|
|
76
|
+
(0, config_1.setENVAccessToken)(env, token);
|
|
77
77
|
}
|
|
78
78
|
await suryaClient.destroy();
|
|
79
79
|
suryaClient = new surya_1.SuryaClient(env);
|
|
80
|
-
user = await preflight_1.preflight(env, suryaClient);
|
|
80
|
+
user = await (0, preflight_1.preflight)(env, suryaClient);
|
|
81
81
|
return new OORJA(config, suryaClient, user);
|
|
82
82
|
};
|
|
83
83
|
let currentEnv;
|
|
84
84
|
let oorja;
|
|
85
|
-
|
|
85
|
+
const getApp = async (options = {}) => {
|
|
86
86
|
const { roomLink } = options;
|
|
87
87
|
const roomURL = roomLink ? parseRoomURL(roomLink) : undefined;
|
|
88
|
-
const env = config_1.determineENV(undefined);
|
|
88
|
+
const env = (0, config_1.determineENV)(undefined);
|
|
89
89
|
if (oorja) {
|
|
90
90
|
if (env !== currentEnv) {
|
|
91
91
|
return Promise.reject("Attempt to run different env in same session");
|
|
@@ -94,3 +94,4 @@ exports.getApp = async (options = {}) => {
|
|
|
94
94
|
}
|
|
95
95
|
return await init(env, { roomId: roomURL ? getRoomId(roomURL) : undefined });
|
|
96
96
|
};
|
|
97
|
+
exports.getApp = getApp;
|
|
@@ -5,5 +5,5 @@ 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>;
|
|
7
7
|
export declare const validateCliVersion: (suryaClient: SuryaClient) => Promise<void>;
|
|
8
|
-
export declare const resumeSession: (env: env, suryaClient: SuryaClient, roomId?: string
|
|
8
|
+
export declare const resumeSession: (env: env, suryaClient: SuryaClient, roomId?: string) => Promise<User | null>;
|
|
9
9
|
export declare const preflight: (env: env, suryaClient: SuryaClient) => Promise<User>;
|
|
@@ -10,12 +10,13 @@ const promptToken = () => new Input({
|
|
|
10
10
|
name: "Access Token",
|
|
11
11
|
message: "Please enter your access token for authentication:",
|
|
12
12
|
}).run();
|
|
13
|
-
|
|
13
|
+
const promptRoomParticipantOTP = () => new Input({
|
|
14
14
|
name: "OTP prompt",
|
|
15
15
|
message: "Please enter your OTP for authentication:",
|
|
16
16
|
}).run();
|
|
17
|
+
exports.promptRoomParticipantOTP = promptRoomParticipantOTP;
|
|
17
18
|
const OTP_HELP_MESSAGE = "You can generate OTP from the room, it's in the instruction steps";
|
|
18
|
-
|
|
19
|
+
const promptAuth = async (suryaClient, generateTokenLink) => {
|
|
19
20
|
const ANON = "Proceed as an anonymous user";
|
|
20
21
|
const SIGN_IN = "Sign-in with oorja";
|
|
21
22
|
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`);
|
|
@@ -33,8 +34,9 @@ exports.promptAuth = async (suryaClient, generateTokenLink) => {
|
|
|
33
34
|
}
|
|
34
35
|
throw Error("Unexpected input");
|
|
35
36
|
};
|
|
36
|
-
exports.
|
|
37
|
-
|
|
37
|
+
exports.promptAuth = promptAuth;
|
|
38
|
+
const loginByRoomOTP = async (suryaClient, roomId) => {
|
|
39
|
+
const otp = await (0, exports.promptRoomParticipantOTP)();
|
|
38
40
|
if (!otp) {
|
|
39
41
|
console.log("OTP not provided :(");
|
|
40
42
|
console.log(OTP_HELP_MESSAGE);
|
|
@@ -52,15 +54,17 @@ exports.loginByRoomOTP = async (suryaClient, roomId) => {
|
|
|
52
54
|
throw e;
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
|
-
exports.
|
|
57
|
+
exports.loginByRoomOTP = loginByRoomOTP;
|
|
58
|
+
const validateCliVersion = async (suryaClient) => {
|
|
56
59
|
const manifest = await suryaClient.fetchCliManifest();
|
|
57
60
|
if (manifest.cliVersion > config_1.CLI_VERSION) {
|
|
58
61
|
console.log(chalk.redBright("Your oorja cli is outdated. Please run: npm update -g oorja"));
|
|
59
62
|
process.exit(1);
|
|
60
63
|
}
|
|
61
64
|
};
|
|
62
|
-
exports.
|
|
63
|
-
|
|
65
|
+
exports.validateCliVersion = validateCliVersion;
|
|
66
|
+
const resumeSession = async (env, suryaClient, roomId) => {
|
|
67
|
+
const token = (0, config_1.getENVAccessToken)(env);
|
|
64
68
|
if (!token)
|
|
65
69
|
return null;
|
|
66
70
|
// try to validate authorization with existing token
|
|
@@ -73,13 +77,14 @@ exports.resumeSession = async (env, suryaClient, roomId) => {
|
|
|
73
77
|
}
|
|
74
78
|
catch (e) {
|
|
75
79
|
if (e instanceof errors_1.Unauthorized) {
|
|
76
|
-
config_1.setENVAccessToken(env, "");
|
|
80
|
+
(0, config_1.setENVAccessToken)(env, "");
|
|
77
81
|
return null;
|
|
78
82
|
}
|
|
79
83
|
throw e;
|
|
80
84
|
}
|
|
81
85
|
};
|
|
82
|
-
exports.
|
|
86
|
+
exports.resumeSession = resumeSession;
|
|
87
|
+
const preflight = async (env, suryaClient) => {
|
|
83
88
|
const spinner = ora({
|
|
84
89
|
text: "Authenticating",
|
|
85
90
|
discardStdin: false,
|
|
@@ -89,7 +94,7 @@ exports.preflight = async (env, suryaClient) => {
|
|
|
89
94
|
spinner.succeed(`Authenticated: Welcome ${user.name}`);
|
|
90
95
|
if (user.profileType === "anon") {
|
|
91
96
|
// don't persist tokens for anonymous users
|
|
92
|
-
config_1.setENVAccessToken(env, "");
|
|
97
|
+
(0, config_1.setENVAccessToken)(env, "");
|
|
93
98
|
console.log(chalk.yellowBright("You're an anonymous user. CLI will not remember the auth-token"));
|
|
94
99
|
}
|
|
95
100
|
spinner.start("Connecting..");
|
|
@@ -105,7 +110,7 @@ exports.preflight = async (env, suryaClient) => {
|
|
|
105
110
|
});
|
|
106
111
|
}
|
|
107
112
|
catch (e) {
|
|
108
|
-
config_1.setENVAccessToken(env, "");
|
|
113
|
+
(0, config_1.setENVAccessToken)(env, "");
|
|
109
114
|
if (e instanceof errors_1.Unauthorized) {
|
|
110
115
|
spinner.fail("Your access token failed authentication, resetting...");
|
|
111
116
|
process.exit(33);
|
|
@@ -116,3 +121,4 @@ exports.preflight = async (env, suryaClient) => {
|
|
|
116
121
|
throw e;
|
|
117
122
|
}
|
|
118
123
|
};
|
|
124
|
+
exports.preflight = preflight;
|
package/lib/lib/surya/index.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export declare class SuryaClient {
|
|
|
18
18
|
joinChannel: ({ channel, params, onJoin, onClose, onError, onMessage, handleSessionJoin, handleSessionLeave, }: JoinChannelOptions<any>) => Channel;
|
|
19
19
|
destroy: () => Promise<unknown>;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type CreateRoomOptions = {
|
|
22
22
|
roomName: string;
|
|
23
23
|
apps: RoomApps;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
25
|
+
export type JoinChannelOptions<T> = {
|
|
26
26
|
channel: string;
|
|
27
27
|
params: T;
|
|
28
28
|
onJoin?: () => void;
|
package/lib/lib/surya/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class SuryaClient {
|
|
|
27
27
|
this.fetchSessionUser = async () => {
|
|
28
28
|
try {
|
|
29
29
|
const response = await this.client.get("/session/user");
|
|
30
|
-
return resources_1.defaultParser(response.data.data);
|
|
30
|
+
return (0, resources_1.defaultParser)(response.data.data);
|
|
31
31
|
}
|
|
32
32
|
catch (error) {
|
|
33
33
|
return handleError(error);
|
|
@@ -43,7 +43,7 @@ class SuryaClient {
|
|
|
43
43
|
};
|
|
44
44
|
try {
|
|
45
45
|
const response = await this.client.post("/rooms", body);
|
|
46
|
-
return resources_1.defaultParser(response.data.data);
|
|
46
|
+
return (0, resources_1.defaultParser)(response.data.data);
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
49
|
return handleError(error);
|
|
@@ -73,7 +73,7 @@ class SuryaClient {
|
|
|
73
73
|
this.fetchRoom = async (roomId) => {
|
|
74
74
|
try {
|
|
75
75
|
const response = await this.client.get(`/rooms/${roomId}`);
|
|
76
|
-
return resources_1.defaultParser(response.data.data);
|
|
76
|
+
return (0, resources_1.defaultParser)(response.data.data);
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
79
|
return handleError(error);
|
|
@@ -85,13 +85,13 @@ class SuryaClient {
|
|
|
85
85
|
let encodeMessage = (rawdata, callback) => {
|
|
86
86
|
if (!rawdata)
|
|
87
87
|
return;
|
|
88
|
-
return callback(msgpack_1.encode(rawdata));
|
|
88
|
+
return callback((0, msgpack_1.encode)(rawdata));
|
|
89
89
|
};
|
|
90
90
|
let decodeMessage = (rawdata, callback) => {
|
|
91
91
|
if (!rawdata)
|
|
92
92
|
return;
|
|
93
93
|
const data = new Uint8Array(rawdata);
|
|
94
|
-
return callback(msgpack_1.decode(data.buffer));
|
|
94
|
+
return callback((0, msgpack_1.decode)(data.buffer));
|
|
95
95
|
};
|
|
96
96
|
return new Promise((resolve, reject) => {
|
|
97
97
|
let initialConnection = false;
|
|
@@ -164,7 +164,7 @@ class SuryaClient {
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
};
|
|
167
|
-
const config = config_1.getSuryaConfig(env);
|
|
167
|
+
const config = (0, config_1.getSuryaConfig)(env);
|
|
168
168
|
this.client = axios_1.default.create({
|
|
169
169
|
httpsAgent: new https.Agent({
|
|
170
170
|
minVersion: "TLSv1.2",
|
|
@@ -183,13 +183,15 @@ class SuryaClient {
|
|
|
183
183
|
exports.SuryaClient = SuryaClient;
|
|
184
184
|
const suryaBaseURL = (host, tlsEnabled) => `${tlsEnabled ? "https" : "http"}://${host}/api/v1`;
|
|
185
185
|
const handleError = (error) => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
186
|
+
if (error instanceof axios_1.AxiosError) {
|
|
187
|
+
const { response } = error;
|
|
188
|
+
if (response) {
|
|
189
|
+
switch (response.status) {
|
|
190
|
+
case 401:
|
|
191
|
+
throw new errors_1.Unauthorized();
|
|
192
|
+
case 400:
|
|
193
|
+
throw new errors_1.BadRequest();
|
|
194
|
+
}
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
197
|
throw error;
|
package/lib/lib/surya/types.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
type ProfileType = "GitHub" | "Google" | "anon";
|
|
3
|
+
export type RoomApp = {
|
|
4
4
|
appId: string;
|
|
5
5
|
config: any;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type RoomApps = {
|
|
8
8
|
defaultFocus?: string;
|
|
9
9
|
appList: RoomApp[];
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type UserProfile = {
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
14
14
|
nickname: string;
|
|
15
15
|
picture: string;
|
|
16
16
|
profileType: ProfileType;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type ResourceTimestamps = {
|
|
19
19
|
createdAt: Date;
|
|
20
20
|
updatedAt: Date;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type CliManifest = {
|
|
23
23
|
cliVersion: number;
|
|
24
24
|
suryaHosts: string[];
|
|
25
25
|
};
|
|
26
|
-
export
|
|
27
|
-
export
|
|
26
|
+
export type User = UserProfile & ResourceTimestamps;
|
|
27
|
+
export type Room = {
|
|
28
28
|
id: string;
|
|
29
29
|
creator_id: string;
|
|
30
30
|
locked: boolean;
|
|
@@ -32,11 +32,11 @@ export declare type Room = {
|
|
|
32
32
|
participants: UserProfile[];
|
|
33
33
|
apps: RoomApps;
|
|
34
34
|
};
|
|
35
|
-
export
|
|
35
|
+
export type RoomKey = {
|
|
36
36
|
roomId: string;
|
|
37
37
|
key: Buffer;
|
|
38
38
|
};
|
|
39
|
-
export
|
|
39
|
+
export type Hash<T> = {
|
|
40
40
|
[key: string]: T;
|
|
41
41
|
};
|
|
42
42
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default class Ajax {
|
|
2
|
+
static request(method: any, endPoint: any, accept: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
3
|
+
static xdomainRequest(req: any, method: any, endPoint: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
4
|
+
static xhrRequest(req: any, method: any, endPoint: any, accept: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
5
|
+
static parseJSON(resp: any): any;
|
|
6
|
+
static serialize(obj: any, parentKey: any): any;
|
|
7
|
+
static appendParams(url: any, params: any): any;
|
|
8
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class Ajax {
|
|
6
|
+
static request(method, endPoint, accept, body, timeout, ontimeout, callback) {
|
|
7
|
+
if (constants_1.global.XDomainRequest) {
|
|
8
|
+
let req = new constants_1.global.XDomainRequest(); // IE8, IE9
|
|
9
|
+
return this.xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
let req = new constants_1.global.XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari
|
|
13
|
+
return this.xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
static xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback) {
|
|
17
|
+
req.timeout = timeout;
|
|
18
|
+
req.open(method, endPoint);
|
|
19
|
+
req.onload = () => {
|
|
20
|
+
let response = this.parseJSON(req.responseText);
|
|
21
|
+
callback && callback(response);
|
|
22
|
+
};
|
|
23
|
+
if (ontimeout) {
|
|
24
|
+
req.ontimeout = ontimeout;
|
|
25
|
+
}
|
|
26
|
+
// Work around bug in IE9 that requires an attached onprogress handler
|
|
27
|
+
req.onprogress = () => { };
|
|
28
|
+
req.send(body);
|
|
29
|
+
return req;
|
|
30
|
+
}
|
|
31
|
+
static xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback) {
|
|
32
|
+
req.open(method, endPoint, true);
|
|
33
|
+
req.timeout = timeout;
|
|
34
|
+
req.setRequestHeader("Content-Type", accept);
|
|
35
|
+
req.onerror = () => callback && callback(null);
|
|
36
|
+
req.onreadystatechange = () => {
|
|
37
|
+
if (req.readyState === constants_1.XHR_STATES.complete && callback) {
|
|
38
|
+
let response = this.parseJSON(req.responseText);
|
|
39
|
+
callback(response);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (ontimeout) {
|
|
43
|
+
req.ontimeout = ontimeout;
|
|
44
|
+
}
|
|
45
|
+
req.send(body);
|
|
46
|
+
return req;
|
|
47
|
+
}
|
|
48
|
+
static parseJSON(resp) {
|
|
49
|
+
if (!resp || resp === "") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(resp);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console && console.log("failed to parse JSON response", resp);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static serialize(obj, parentKey) {
|
|
61
|
+
let queryStr = [];
|
|
62
|
+
for (var key in obj) {
|
|
63
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
let paramKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
67
|
+
let paramVal = obj[key];
|
|
68
|
+
if (typeof paramVal === "object") {
|
|
69
|
+
queryStr.push(this.serialize(paramVal, paramKey));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
queryStr.push(encodeURIComponent(paramKey) + "=" + encodeURIComponent(paramVal));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return queryStr.join("&");
|
|
76
|
+
}
|
|
77
|
+
static appendParams(url, params) {
|
|
78
|
+
if (Object.keys(params).length === 0) {
|
|
79
|
+
return url;
|
|
80
|
+
}
|
|
81
|
+
let prefix = url.match(/\?/) ? "&" : "?";
|
|
82
|
+
return `${url}${prefix}${this.serialize(params)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = Ajax;
|