@hexagramio/saga-ts 0.9.293
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/LICENSE +19 -0
- package/README.md +36 -0
- package/dist/cjs/commands/bots.d.ts +74 -0
- package/dist/cjs/commands/bots.d.ts.map +1 -0
- package/dist/cjs/commands/bots.js +133 -0
- package/dist/cjs/commands/bots.js.map +1 -0
- package/dist/cjs/commands/system.d.ts +18 -0
- package/dist/cjs/commands/system.d.ts.map +1 -0
- package/dist/cjs/commands/system.js +30 -0
- package/dist/cjs/commands/system.js.map +1 -0
- package/dist/cjs/commands/test_data.d.ts +10 -0
- package/dist/cjs/commands/test_data.d.ts.map +1 -0
- package/dist/cjs/commands/test_data.js +17 -0
- package/dist/cjs/commands/test_data.js.map +1 -0
- package/dist/cjs/commands/user.d.ts +137 -0
- package/dist/cjs/commands/user.d.ts.map +1 -0
- package/dist/cjs/commands/user.js +186 -0
- package/dist/cjs/commands/user.js.map +1 -0
- package/dist/cjs/index.d.ts +116 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +205 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/shared_types.d.ts +58 -0
- package/dist/cjs/lib/shared_types.d.ts.map +1 -0
- package/dist/cjs/lib/shared_types.js +3 -0
- package/dist/cjs/lib/shared_types.js.map +1 -0
- package/dist/commands/bots.d.ts +74 -0
- package/dist/commands/bots.d.ts.map +1 -0
- package/dist/commands/bots.js +121 -0
- package/dist/commands/bots.js.map +1 -0
- package/dist/commands/system.d.ts +18 -0
- package/dist/commands/system.d.ts.map +1 -0
- package/dist/commands/system.js +25 -0
- package/dist/commands/system.js.map +1 -0
- package/dist/commands/test_data.d.ts +10 -0
- package/dist/commands/test_data.d.ts.map +1 -0
- package/dist/commands/test_data.js +13 -0
- package/dist/commands/test_data.js.map +1 -0
- package/dist/commands/user.d.ts +137 -0
- package/dist/commands/user.d.ts.map +1 -0
- package/dist/commands/user.js +170 -0
- package/dist/commands/user.js.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/shared_types.d.ts +58 -0
- package/dist/lib/shared_types.d.ts.map +1 -0
- package/dist/lib/shared_types.js +2 -0
- package/dist/lib/shared_types.js.map +1 -0
- package/dist/transport/http.d.ts +7 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +75 -0
- package/dist/transport/http.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LeaveUserCommand = exports.JoinUserCommand = exports.AddUserPropertyCommand = exports.UpdateUserCommand = exports.GetDeleteCommand = exports.RefreshTokenCommand = exports.GetUserCommand = exports.ListUsersCommand = exports.CreateTestUserCommand = exports.CreateGenerateBasicUserCommand = exports.RegisterUserCommand = exports.LoginUserCommand = exports.WhoAmICommand = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a command to get the user associated with the given accessToken
|
|
6
|
+
* @param accessToken the required accessToken
|
|
7
|
+
* @group HTTP Commands
|
|
8
|
+
*/
|
|
9
|
+
const WhoAmICommand = (accessToken) => {
|
|
10
|
+
return {
|
|
11
|
+
method: "GET",
|
|
12
|
+
path: "/users/whoami",
|
|
13
|
+
accessToken
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.WhoAmICommand = WhoAmICommand;
|
|
17
|
+
/**
|
|
18
|
+
* Command to login a user
|
|
19
|
+
* @param username string
|
|
20
|
+
* @param password string
|
|
21
|
+
* @group HTTP Commands
|
|
22
|
+
*/
|
|
23
|
+
const LoginUserCommand = (data) => {
|
|
24
|
+
return {
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: "/users/login",
|
|
27
|
+
data
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.LoginUserCommand = LoginUserCommand;
|
|
31
|
+
/**
|
|
32
|
+
* Create command to register a user
|
|
33
|
+
* @param username string
|
|
34
|
+
* @param password string
|
|
35
|
+
* @group HTTP Commands
|
|
36
|
+
*/
|
|
37
|
+
const RegisterUserCommand = (data) => {
|
|
38
|
+
return {
|
|
39
|
+
method: "POST",
|
|
40
|
+
path: "/users",
|
|
41
|
+
data
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.RegisterUserCommand = RegisterUserCommand;
|
|
45
|
+
/**
|
|
46
|
+
* Command to create a generated user
|
|
47
|
+
* @param basicUser an optional model
|
|
48
|
+
* @group HTTP Commands
|
|
49
|
+
*/
|
|
50
|
+
const CreateGenerateBasicUserCommand = (data = {}) => {
|
|
51
|
+
return {
|
|
52
|
+
method: "POST",
|
|
53
|
+
path: "/users/generate/basic",
|
|
54
|
+
data
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.CreateGenerateBasicUserCommand = CreateGenerateBasicUserCommand;
|
|
58
|
+
/**
|
|
59
|
+
* Command to create a test user
|
|
60
|
+
* @param basicUser an optional model
|
|
61
|
+
* @group HTTP Commands
|
|
62
|
+
*/
|
|
63
|
+
const CreateTestUserCommand = (username) => {
|
|
64
|
+
return {
|
|
65
|
+
method: "POST",
|
|
66
|
+
path: "/users/generate/test",
|
|
67
|
+
data: {
|
|
68
|
+
username
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.CreateTestUserCommand = CreateTestUserCommand;
|
|
73
|
+
/**
|
|
74
|
+
* List Users command
|
|
75
|
+
* @param search search criteria for ysers
|
|
76
|
+
* @param accessToken the required accessToken
|
|
77
|
+
* @group HTTP Commands
|
|
78
|
+
*/
|
|
79
|
+
const ListUsersCommand = (accessToken, search) => {
|
|
80
|
+
return {
|
|
81
|
+
method: "GET",
|
|
82
|
+
path: "/users",
|
|
83
|
+
params: search ? new URLSearchParams({ search }) : undefined,
|
|
84
|
+
accessToken
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.ListUsersCommand = ListUsersCommand;
|
|
88
|
+
/**
|
|
89
|
+
* Get a user command
|
|
90
|
+
* @param id the id of the user
|
|
91
|
+
* @param accessToken the required accessToken
|
|
92
|
+
* @group HTTP Commands
|
|
93
|
+
*/
|
|
94
|
+
const GetUserCommand = (accessToken, id) => {
|
|
95
|
+
return {
|
|
96
|
+
method: "GET",
|
|
97
|
+
path: `/users/${id}`,
|
|
98
|
+
accessToken
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.GetUserCommand = GetUserCommand;
|
|
102
|
+
/**
|
|
103
|
+
* Refresh token command
|
|
104
|
+
* @param id the id of the user
|
|
105
|
+
* @param refreshToken the refresh token
|
|
106
|
+
* @group HTTP Commands
|
|
107
|
+
*/
|
|
108
|
+
const RefreshTokenCommand = (refreshToken, id) => {
|
|
109
|
+
return {
|
|
110
|
+
method: "POST",
|
|
111
|
+
path: `/users/${id}/refresh_token`,
|
|
112
|
+
data: { refreshToken }
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
exports.RefreshTokenCommand = RefreshTokenCommand;
|
|
116
|
+
/**
|
|
117
|
+
* Delete a user command
|
|
118
|
+
* @param id the id of the user
|
|
119
|
+
* @param accessToken the required accessToken
|
|
120
|
+
* @group HTTP Commands
|
|
121
|
+
*/
|
|
122
|
+
const GetDeleteCommand = (accessToken, id) => {
|
|
123
|
+
return {
|
|
124
|
+
method: "DELETE",
|
|
125
|
+
path: `/users/${id}`,
|
|
126
|
+
accessToken
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
exports.GetDeleteCommand = GetDeleteCommand;
|
|
130
|
+
/**
|
|
131
|
+
* Update the user command
|
|
132
|
+
* @param data the user needing to be updated, the _id of the user is used to select the user
|
|
133
|
+
* @param accessToken the required accessToken
|
|
134
|
+
* @group HTTP Commands
|
|
135
|
+
*/
|
|
136
|
+
const UpdateUserCommand = (accessToken, data) => {
|
|
137
|
+
return {
|
|
138
|
+
method: "PUT",
|
|
139
|
+
path: `/users/${data._id}`,
|
|
140
|
+
data,
|
|
141
|
+
accessToken
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
exports.UpdateUserCommand = UpdateUserCommand;
|
|
145
|
+
/**
|
|
146
|
+
* Add a bot property command
|
|
147
|
+
* @param data the property
|
|
148
|
+
* @param accessToken the required accessToken
|
|
149
|
+
* @group HTTP Commands
|
|
150
|
+
*/
|
|
151
|
+
const AddUserPropertyCommand = (accessToken, data) => {
|
|
152
|
+
return {
|
|
153
|
+
method: "POST",
|
|
154
|
+
path: `/users/${data.parent_id}/properties`,
|
|
155
|
+
data,
|
|
156
|
+
accessToken
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
exports.AddUserPropertyCommand = AddUserPropertyCommand;
|
|
160
|
+
/**
|
|
161
|
+
* A command to join a users realtime socket
|
|
162
|
+
* @param _id the id of the user
|
|
163
|
+
* @group Socket Commands
|
|
164
|
+
*/
|
|
165
|
+
const JoinUserCommand = (_id) => {
|
|
166
|
+
return {
|
|
167
|
+
method: "/users",
|
|
168
|
+
join: true,
|
|
169
|
+
id: _id
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
exports.JoinUserCommand = JoinUserCommand;
|
|
173
|
+
/**
|
|
174
|
+
* A command to leave a users realtime socket
|
|
175
|
+
* @param _id the id of the user
|
|
176
|
+
* @group Socket Commands
|
|
177
|
+
*/
|
|
178
|
+
const LeaveUserCommand = (_id) => {
|
|
179
|
+
return {
|
|
180
|
+
method: "/users",
|
|
181
|
+
join: false,
|
|
182
|
+
id: _id
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
exports.LeaveUserCommand = LeaveUserCommand;
|
|
186
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/commands/user.ts"],"names":[],"mappings":";;;AA8DA;;;;GAIG;AACI,MA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;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,GAAU,EAAiB,EAAE;IAC3D,OAAO;QACL,MAAM,EAAC,QAAQ;QACf,IAAI,EAAC,IAAI;QACT,EAAE,EAAC,GAAG;KACP,CAAA;AACH,CAAC,CAAA;AANY,QAAA,eAAe,mBAM3B;AAED;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,GAAU,EAAiB,EAAE;IAC5D,OAAO;QACL,MAAM,EAAC,QAAQ;QACf,IAAI,EAAC,KAAK;QACV,EAAE,EAAC,GAAG;KACP,CAAA;AACH,CAAC,CAAA;AANY,QAAA,gBAAgB,oBAM5B"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central Module that contains the methods to issue
|
|
3
|
+
* HTTPCommands and SocketCommands to a SAGA host
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/// <reference types="node" />
|
|
7
|
+
import { URLSearchParams } from "url";
|
|
8
|
+
import { ReadMessage, ReadProperty } from "./lib/shared_types";
|
|
9
|
+
/**
|
|
10
|
+
* The APIError is thrown when a HTTPCommand or SocketCommands fails to execute
|
|
11
|
+
*/
|
|
12
|
+
export declare class APIError extends Error {
|
|
13
|
+
/**
|
|
14
|
+
* a saga status code as explained in the actual saga documentation,
|
|
15
|
+
* very much aligned to HTTP Status codes
|
|
16
|
+
*/
|
|
17
|
+
statusCode: number;
|
|
18
|
+
/**
|
|
19
|
+
* The path of the HTTPCommand or SocketCommand that caused the error
|
|
20
|
+
*/
|
|
21
|
+
path?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Details on what field were not permitted
|
|
24
|
+
*/
|
|
25
|
+
errors?: Record<string, string>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a
|
|
28
|
+
* @param message the error message
|
|
29
|
+
* @param statusCode a saga status code as explained in the actual saga documentation, very much aligned to HTTP Status codes
|
|
30
|
+
* @param errors list of field names and the reason why the field wasn't permitted
|
|
31
|
+
* @param path The path of the HTTPCommand or SocketCommand that caused the error
|
|
32
|
+
*/
|
|
33
|
+
constructor(message: string, statusCode: number, errors?: Record<string, string>, path?: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Encapsulates authentication tokens. An authentication object is returned i.e. from {@link LoginUserCommand} It's required for most HTTP Commands.
|
|
37
|
+
*/
|
|
38
|
+
export interface Authentication {
|
|
39
|
+
/**
|
|
40
|
+
* Required access token
|
|
41
|
+
*/
|
|
42
|
+
accessToken: string;
|
|
43
|
+
/**
|
|
44
|
+
* Used to retrieve a new access token using {@link RefreshTokenCommand}
|
|
45
|
+
*/
|
|
46
|
+
refreshToken: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Interface to represent the various mutations of a HTTP Command profile.
|
|
50
|
+
*/
|
|
51
|
+
export interface HTTPCommand<T> {
|
|
52
|
+
method: "GET" | "PUT" | "POST" | "DELETE";
|
|
53
|
+
path: string;
|
|
54
|
+
params?: URLSearchParams;
|
|
55
|
+
data?: any;
|
|
56
|
+
accessToken?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Send the HTTP Command to the host with the given baseURL
|
|
60
|
+
* @param baseURL the baseURL of the HTTP Api, i.e 'https://example.api.hexagram.io'
|
|
61
|
+
* @param command the actual command to send
|
|
62
|
+
* @return a promise containing the response from the command
|
|
63
|
+
* @throws an APIError if the operations fails
|
|
64
|
+
*/
|
|
65
|
+
export declare const sendHTTPCommand: <T>(baseURL: URL, command: HTTPCommand<T>) => Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* The events a socket session can receive.
|
|
68
|
+
*/
|
|
69
|
+
export interface EventMap {
|
|
70
|
+
"/properties": ReadProperty;
|
|
71
|
+
"/messages": ReadMessage;
|
|
72
|
+
"authenticated": any;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A socket join command
|
|
76
|
+
*/
|
|
77
|
+
export interface SocketJoinCommand {
|
|
78
|
+
method: "/users" | "/bots" | "/globals" | "/jobs/runnable_calls" | "/jobs/versions" | "/scripts/runnable_calls" | "/scripts/versions" | "/system" | "/npm_packages";
|
|
79
|
+
id: string;
|
|
80
|
+
join: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The discriminating union type of socket commands,
|
|
84
|
+
* for it just contains the join commands, but the
|
|
85
|
+
* intent is to hold other socket commands as well
|
|
86
|
+
*/
|
|
87
|
+
export type SocketCommand = SocketJoinCommand;
|
|
88
|
+
/**
|
|
89
|
+
* Class that wraps saga socket connection logic and manages realtime saga socket events. The
|
|
90
|
+
*/
|
|
91
|
+
export declare class SocketSession {
|
|
92
|
+
private socket;
|
|
93
|
+
private readonly maxRetries;
|
|
94
|
+
private commandStack;
|
|
95
|
+
private ready;
|
|
96
|
+
/**
|
|
97
|
+
* Set connection parameters.
|
|
98
|
+
* @param host the host to connect to
|
|
99
|
+
* @param accessToken the access token to authenticate
|
|
100
|
+
* @param errorNotify callback function that will be called when errors occur
|
|
101
|
+
*/
|
|
102
|
+
constructor(host: URL, accessToken: string, errorNotify: (error: APIError) => any, options?: {
|
|
103
|
+
delayAuthentication?: number;
|
|
104
|
+
triggerDisconnectAndConnect?: number;
|
|
105
|
+
});
|
|
106
|
+
private emitStackedCommands;
|
|
107
|
+
on<E extends keyof EventMap>(type: E, listener: (ev: EventMap[E]) => undefined): void;
|
|
108
|
+
off<E extends keyof EventMap>(type: E, listener?: (ev: EventMap[E]) => undefined): void;
|
|
109
|
+
/**
|
|
110
|
+
* Send commands to the server
|
|
111
|
+
* @param command
|
|
112
|
+
* @throws APIError if error ack is send back from server
|
|
113
|
+
*/
|
|
114
|
+
emitCommand(command: SocketCommand): Promise<unknown>;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAIH,OAAO,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AG,eAAe,CAAA;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAG9C;;GAEG;AACH,qBAAa,aAAa;IAExB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAO;IAClC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;;OAKG;gBAED,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,GAAG,EACrC,OAAO,CAAC,EAAC;QAAC,mBAAmB,CAAC,EAAC,MAAM,CAAC;QAAA,2BAA2B,CAAC,EAAC,MAAM,CAAA;KAAC;IAyD7E,OAAO,CAAC,mBAAmB;IAW1B,EAAE,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,SAAS,GAAG,IAAI;IAKrF,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,SAAS,GAAG,IAAI;IAKvF;;;;OAIG;IACG,WAAW,CAAC,OAAO,EAAE,aAAa;CA0BzC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Central Module that contains the methods to issue
|
|
4
|
+
* HTTPCommands and SocketCommands to a SAGA host
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.SocketSession = exports.sendHTTPCommand = exports.APIError = void 0;
|
|
21
|
+
const axios_1 = __importDefault(require("axios"));
|
|
22
|
+
const socket_io_client_1 = __importDefault(require("socket.io-client"));
|
|
23
|
+
const parse_link_header_1 = __importDefault(require("parse-link-header"));
|
|
24
|
+
const debug_1 = __importDefault(require("debug"));
|
|
25
|
+
const debug = (0, debug_1.default)("saga-ts");
|
|
26
|
+
/**
|
|
27
|
+
* The APIError is thrown when a HTTPCommand or SocketCommands fails to execute
|
|
28
|
+
*/
|
|
29
|
+
class APIError extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* Create a
|
|
32
|
+
* @param message the error message
|
|
33
|
+
* @param statusCode a saga status code as explained in the actual saga documentation, very much aligned to HTTP Status codes
|
|
34
|
+
* @param errors list of field names and the reason why the field wasn't permitted
|
|
35
|
+
* @param path The path of the HTTPCommand or SocketCommand that caused the error
|
|
36
|
+
*/
|
|
37
|
+
constructor(message, statusCode, errors, path) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.statusCode = statusCode;
|
|
40
|
+
this.errors = errors;
|
|
41
|
+
this.path = path;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.APIError = APIError;
|
|
45
|
+
/**
|
|
46
|
+
* Send the HTTP Command to the host with the given baseURL
|
|
47
|
+
* @param baseURL the baseURL of the HTTP Api, i.e 'https://example.api.hexagram.io'
|
|
48
|
+
* @param command the actual command to send
|
|
49
|
+
* @return a promise containing the response from the command
|
|
50
|
+
* @throws an APIError if the operations fails
|
|
51
|
+
*/
|
|
52
|
+
const sendHTTPCommand = (baseURL, command) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
54
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
55
|
+
if (command.accessToken) {
|
|
56
|
+
headers.Authorization = `Bearer ${command.accessToken}`;
|
|
57
|
+
}
|
|
58
|
+
const response = yield (0, axios_1.default)({
|
|
59
|
+
headers,
|
|
60
|
+
baseURL: baseURL.toString(),
|
|
61
|
+
validateStatus: () => true,
|
|
62
|
+
method: command.method,
|
|
63
|
+
url: command.path,
|
|
64
|
+
params: command.params,
|
|
65
|
+
data: command.data
|
|
66
|
+
});
|
|
67
|
+
if (response.status !== 200) {
|
|
68
|
+
throw new APIError(response.data.toString(), response.status, (_a = response.data) === null || _a === void 0 ? void 0 : _a.errors, command.path);
|
|
69
|
+
}
|
|
70
|
+
else if (response.headers['link'] || response.headers['link'] === '') {
|
|
71
|
+
const parsed = (0, parse_link_header_1.default)(response.headers['link']);
|
|
72
|
+
const list = (url) => {
|
|
73
|
+
return {
|
|
74
|
+
method: "GET",
|
|
75
|
+
path: url.pathname,
|
|
76
|
+
params: url.searchParams,
|
|
77
|
+
accessToken: command.accessToken
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
result: response.data,
|
|
82
|
+
prevCommand: ((_b = parsed === null || parsed === void 0 ? void 0 : parsed.prev) === null || _b === void 0 ? void 0 : _b.url) ? list(new URL((_c = parsed === null || parsed === void 0 ? void 0 : parsed.prev) === null || _c === void 0 ? void 0 : _c.url)) : undefined,
|
|
83
|
+
nextCommand: ((_d = parsed === null || parsed === void 0 ? void 0 : parsed.next) === null || _d === void 0 ? void 0 : _d.url) ? list(new URL((_e = parsed === null || parsed === void 0 ? void 0 : parsed.next) === null || _e === void 0 ? void 0 : _e.url)) : undefined
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return response.data;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
exports.sendHTTPCommand = sendHTTPCommand;
|
|
91
|
+
/**
|
|
92
|
+
* Class that wraps saga socket connection logic and manages realtime saga socket events. The
|
|
93
|
+
*/
|
|
94
|
+
class SocketSession {
|
|
95
|
+
/**
|
|
96
|
+
* Set connection parameters.
|
|
97
|
+
* @param host the host to connect to
|
|
98
|
+
* @param accessToken the access token to authenticate
|
|
99
|
+
* @param errorNotify callback function that will be called when errors occur
|
|
100
|
+
*/
|
|
101
|
+
constructor(host, accessToken, errorNotify, options) {
|
|
102
|
+
this.maxRetries = 100;
|
|
103
|
+
this.commandStack = [];
|
|
104
|
+
this.ready = false;
|
|
105
|
+
this.socket = (0, socket_io_client_1.default)(host.toString(), {
|
|
106
|
+
transports: ['websocket', 'polling'],
|
|
107
|
+
reconnection: true,
|
|
108
|
+
reconnectionDelay: 1000,
|
|
109
|
+
reconnectionDelayMax: 5000,
|
|
110
|
+
reconnectionAttempts: this.maxRetries,
|
|
111
|
+
})
|
|
112
|
+
.on('connect', () => {
|
|
113
|
+
debug('connect');
|
|
114
|
+
if ((options === null || options === void 0 ? void 0 : options.delayAuthentication) && (options === null || options === void 0 ? void 0 : options.delayAuthentication) > 0) {
|
|
115
|
+
setTimeout(() => this.socket.emit('authentication', { accessToken }), options.delayAuthentication);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.socket.emit('authentication', { accessToken });
|
|
119
|
+
}
|
|
120
|
+
if ((options === null || options === void 0 ? void 0 : options.triggerDisconnectAndConnect) && options.triggerDisconnectAndConnect > 0) {
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
options.triggerDisconnectAndConnect = 0;
|
|
123
|
+
this.socket.disconnect();
|
|
124
|
+
this.socket.connect();
|
|
125
|
+
this.emitStackedCommands();
|
|
126
|
+
}, options.triggerDisconnectAndConnect);
|
|
127
|
+
}
|
|
128
|
+
//this.socket.emit('authentication', {accessToken});
|
|
129
|
+
})
|
|
130
|
+
.on('disconnect', err => {
|
|
131
|
+
this.ready = false;
|
|
132
|
+
debug(`disconnect ${err}`);
|
|
133
|
+
})
|
|
134
|
+
.on('error', err => {
|
|
135
|
+
debug(`error ${err}`);
|
|
136
|
+
errorNotify(new APIError(err.message, 500));
|
|
137
|
+
})
|
|
138
|
+
.on('unauthorized', (err) => {
|
|
139
|
+
debug('unauthorized');
|
|
140
|
+
errorNotify(new APIError(err.message, 401));
|
|
141
|
+
})
|
|
142
|
+
.on('authenticated', () => {
|
|
143
|
+
debug('authenticated');
|
|
144
|
+
this.ready = true;
|
|
145
|
+
this.emitStackedCommands();
|
|
146
|
+
});
|
|
147
|
+
this.socket.io.on('reconnect', () => {
|
|
148
|
+
debug('reconnect');
|
|
149
|
+
this.emitStackedCommands();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
emitStackedCommands() {
|
|
153
|
+
debug(`emitStackedCommands ${this.commandStack.length}`);
|
|
154
|
+
for (const command of this.commandStack) {
|
|
155
|
+
debug(`send queued ${command.method} ${command.join} ${command.id}`);
|
|
156
|
+
this.socket.emit(`${command.method}/${command.join ? "join" : "leave"}`, command.id, (response) => {
|
|
157
|
+
debug(`queued command response ${response.status_code}`);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
this.commandStack = this.commandStack.filter(command => command.join !== undefined);
|
|
161
|
+
}
|
|
162
|
+
on(type, listener) {
|
|
163
|
+
//@ts-ignore
|
|
164
|
+
this.socket.on(type, listener);
|
|
165
|
+
}
|
|
166
|
+
off(type, listener) {
|
|
167
|
+
//@ts-ignore
|
|
168
|
+
this.socket.off(type, listener);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Send commands to the server
|
|
172
|
+
* @param command
|
|
173
|
+
* @throws APIError if error ack is send back from server
|
|
174
|
+
*/
|
|
175
|
+
emitCommand(command) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
if (!this.ready) {
|
|
179
|
+
debug(`command queued ${command.method} ${command.join} ${command.id}`);
|
|
180
|
+
this.commandStack.push(command);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
debug(`sending ${command.method}`);
|
|
184
|
+
const path = `${command.method}/${command.join ? "join" : "leave"}`;
|
|
185
|
+
this.socket.emit(path, command.id, (response) => {
|
|
186
|
+
debug(`received ack ${response.status_code} for ${command.method} `);
|
|
187
|
+
if (response.status_code !== 200) {
|
|
188
|
+
reject(new APIError(response.body.name.toString(), response.status_code, response.body.errors, path));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
//we only need to queue messages that join/leave
|
|
192
|
+
//for replay when the socket reconnects
|
|
193
|
+
if (command.join !== undefined) {
|
|
194
|
+
this.commandStack.push(command);
|
|
195
|
+
}
|
|
196
|
+
resolve(response);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.SocketSession = SocketSession;
|
|
205
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;AAEH,kDAA4C;AAC5C,wEAAkD;AAGlD,0EAAgD;AAChD,kDAA0B;AAG1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;AAG/B;;GAEG;AACH,MAAa,QAAS,SAAQ,KAAK;IAiBjC;;;;;;OAMG;IACH,YAAY,OAAe,EAAE,UAAkB,EAAE,MAA8B,EAAE,IAAa;QAC5F,KAAK,CAAC,OAAO,C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AAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;yBACxG;6BAAM;4BACL,gDAAgD;4BAChD,uCAAuC;4BACvC,IAAG,OAAO,CAAC,IAAI,KAAK,SAAS,EAAC;gCAC5B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;6BAChC;4BACD,OAAO,CAAC,QAAQ,CAAC,CAAA;yBAClB;oBACH,CAAC,CACF,CAAA;iBACF;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA9HD,sCA8HC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HTTPCommand } from "../index";
|
|
2
|
+
/**
|
|
3
|
+
* Will be used in Read* Objects that have a timestamp
|
|
4
|
+
* @hidden
|
|
5
|
+
*/
|
|
6
|
+
export interface TimeStamp {
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* For read* Objects that have an _id
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
export interface Id {
|
|
15
|
+
_id: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* For read* Objects that have an _id
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
export interface TestData {
|
|
22
|
+
/**
|
|
23
|
+
* Is true when the data is for testing only
|
|
24
|
+
*/
|
|
25
|
+
test_data?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface Tags {
|
|
28
|
+
tags?: [string];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* For read* Objects that have an _id
|
|
32
|
+
*/
|
|
33
|
+
export interface List<T> {
|
|
34
|
+
prevCommand?: HTTPCommand<List<T>>;
|
|
35
|
+
nextCommand?: HTTPCommand<List<T>>;
|
|
36
|
+
result: T[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create Property Interface
|
|
40
|
+
*/
|
|
41
|
+
export interface CreateProperty extends TestData {
|
|
42
|
+
name: string;
|
|
43
|
+
value: any;
|
|
44
|
+
parent_id?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ReadProperty extends CreateProperty {
|
|
47
|
+
_id: string;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
}
|
|
50
|
+
export interface CreateMessage extends TestData {
|
|
51
|
+
body: string;
|
|
52
|
+
from: "user" | "bot";
|
|
53
|
+
user_id: string;
|
|
54
|
+
bot_id: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ReadMessage extends CreateMessage, Id, TimeStamp {
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=shared_types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared_types.d.ts","sourceRoot":"","sources":["../../../src/lib/shared_types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,EAAE;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,CAAC,EAAE,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAY,SAAQ,aAAa,EAAE,EAAE,EAAE,SAAS;CAEhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared_types.js","sourceRoot":"","sources":["../../../src/lib/shared_types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HTTPCommand, SocketCommand } from "../index";
|
|
2
|
+
import { CreateProperty, Id, List, ReadProperty, Tags, TestData, TimeStamp } from "../lib/shared_types";
|
|
3
|
+
export interface CreateBot extends TestData, Tags {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UpdateBot extends CreateBot, Id {
|
|
7
|
+
}
|
|
8
|
+
export interface ReadBot extends UpdateBot, TimeStamp {
|
|
9
|
+
properties: Record<string, ReadProperty>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* List Bots command
|
|
13
|
+
* @param search search criteria for bots
|
|
14
|
+
* @param accessToken the required accessToken
|
|
15
|
+
* @group HTTP Commands
|
|
16
|
+
*/
|
|
17
|
+
export declare const ListBotsCommand: (accessToken: string, search?: string) => HTTPCommand<List<ReadBot>>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new bot command
|
|
20
|
+
* @param data a CreateBot Object
|
|
21
|
+
* @param accessToken the required accessToken
|
|
22
|
+
* @group HTTP Commands
|
|
23
|
+
*/
|
|
24
|
+
export declare function CreateBotCommand(accessToken: string, data: CreateBot): HTTPCommand<ReadBot>;
|
|
25
|
+
/**
|
|
26
|
+
* Create an array of bots command
|
|
27
|
+
* @param data a CreateBot Object array
|
|
28
|
+
* @param accessToken the required accessToken
|
|
29
|
+
* @group HTTP Commands
|
|
30
|
+
*/
|
|
31
|
+
export declare function CreateBotsCommand(accessToken: string, data: CreateBot[]): HTTPCommand<ReadBot[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get a bot command
|
|
34
|
+
* @param id the id of the bot
|
|
35
|
+
* @param accessToken the required accessToken
|
|
36
|
+
* @group HTTP Commands
|
|
37
|
+
*/
|
|
38
|
+
export declare const GetBotCommand: (accessToken: string, id: string) => HTTPCommand<ReadBot>;
|
|
39
|
+
/**
|
|
40
|
+
* Update the bot command
|
|
41
|
+
* @param data the bot needing to be updated, the _id of the bot is used to select the bot
|
|
42
|
+
* @param accessToken the required accessToken
|
|
43
|
+
* @group HTTP Commands
|
|
44
|
+
*/
|
|
45
|
+
export declare const UpdateBotCommand: (accessToken: string, data: UpdateBot) => HTTPCommand<ReadBot>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a bot command
|
|
48
|
+
* @param id the id of the bot to delete
|
|
49
|
+
* @param accessToken the required accessToken
|
|
50
|
+
* @group HTTP Commands
|
|
51
|
+
*/
|
|
52
|
+
export declare const DeleteBotCommand: (accessToken: string, _id: string) => HTTPCommand<{
|
|
53
|
+
ok: true;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Add a bot property command
|
|
57
|
+
* @param data the property
|
|
58
|
+
* @param accessToken the required accessToken
|
|
59
|
+
* @group HTTP Commands
|
|
60
|
+
*/
|
|
61
|
+
export declare const AddBotPropertyCommand: (accessToken: string, data: CreateProperty) => HTTPCommand<ReadProperty>;
|
|
62
|
+
/**
|
|
63
|
+
* A command to join a bots realtime socket
|
|
64
|
+
* @param _id id of the bot
|
|
65
|
+
* @group Socket Commands
|
|
66
|
+
*/
|
|
67
|
+
export declare const JoinBotCommand: (_id: string) => SocketCommand;
|
|
68
|
+
/**
|
|
69
|
+
* A command to leave a bots realtime socket
|
|
70
|
+
* @param _id id of the bot
|
|
71
|
+
* @group Socket Commands
|
|
72
|
+
*/
|
|
73
|
+
export declare const LeaveBotCommand: (_id: string) => SocketCommand;
|
|
74
|
+
//# sourceMappingURL=bots.d.ts.map
|