@hexagramio/saga-ts 0.9.293-1 → 0.9.293-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/dist/cjs/index.js CHANGED
@@ -1,205 +1,24 @@
1
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 };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
15
  };
19
16
  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;
17
+ __exportStar(require("./senders/http"), exports);
18
+ __exportStar(require("./senders/socket"), exports);
19
+ __exportStar(require("./commands/bots"), exports);
20
+ __exportStar(require("./commands/users"), exports);
21
+ __exportStar(require("./commands/system"), exports);
22
+ __exportStar(require("./commands/test_data"), exports);
23
+ __exportStar(require("./shared/types"), exports);
205
24
  //# sourceMappingURL=index.js.map
@@ -1 +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,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AA9BD,4BA8BC;AA4BD;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAU,OAAY,EAAE,OAAuB,EAAc,EAAE;;IAE5F,MAAM,OAAO,GAA2B,EAAC,cAAc,EAAE,kBAAkB,EAAC,CAAA;IAC5E,IAAI,OAAO,CAAC,WAAW,EAAE;QACvB,OAAO,CAAC,aAAa,GAAG,UAAU,OAAO,CAAC,WAAW,EAAE,CAAC;KACzD;IAED,MAAM,QAAQ,GAAkB,MAAM,IAAA,eAAK,EAAI;QAC7C,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3B,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,CAAC,IAAI;QACjB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE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O,CAAC,MAAM,EAAE,CAAC,CAAC;oBACnC,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;oBACnE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,QAAa,EAAE,EAAE;wBACjD,KAAK,CAAC,gBAAgB,QAAQ,CAAC,WAAW,QAAQ,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;wBACrE,IAAI,QAAQ,CAAC,WAAW,KAAK,GAAG,EAAE;4BAC/B,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,WAAW,EAAE,QAAQ,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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,mDAAgC;AAChC,kDAA+B;AAC/B,mDAAgC;AAChC,oDAAiC;AACjC,uDAAoC;AACpC,iDAA8B"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Lit of user messages and functions to generate user commands
3
+ * @packageDocumentation
4
+ */
5
+ import { HTTPCommand } from "../senders/http";
6
+ import { SocketCommand } from "../senders/socket";
7
+ import { CreateProperty, Id, List, ReadProperty, Tags, TestData, TimeStamp } from "../shared/types";
8
+ /**
9
+ * used to update basic user
10
+ * @group User Types
11
+ */
12
+ export interface UpdateUser extends Id {
13
+ username?: string;
14
+ tags?: [string];
15
+ email?: string;
16
+ displayname?: string;
17
+ }
18
+ /**
19
+ *
20
+ * @group User Types
21
+ */
22
+ export interface ReadUser extends TimeStamp, Id, TestData, Tags {
23
+ username: string;
24
+ properties: Record<string, ReadProperty>;
25
+ tags?: [string];
26
+ }
27
+ /**
28
+ * Basic User Creation Message
29
+ * @group User Types
30
+ */
31
+ export interface BasicUser extends Tags {
32
+ prefix?: "";
33
+ }
34
+ /**
35
+ * Register User Message
36
+ * @group User Types
37
+ */
38
+ export interface RegisterUser extends Tags {
39
+ username: string;
40
+ password: string;
41
+ email?: string;
42
+ displayname?: string;
43
+ }
44
+ /**
45
+ * Login User Message
46
+ * @group User Types
47
+ */
48
+ export interface LoginUser extends Tags {
49
+ username: string;
50
+ password: string;
51
+ }
52
+ /**
53
+ * Creates a command to get the user associated with the given accessToken
54
+ * @param accessToken the required accessToken
55
+ * @group HTTP Commands
56
+ */
57
+ export declare const WhoAmICommand: (accessToken: string) => HTTPCommand<ReadUser>;
58
+ /**
59
+ * Encapsulates authentication tokens. An authentication object is returned i.e. from {@link LoginUserCommand} It's required for most HTTP Commands.
60
+ */
61
+ export interface Authentication {
62
+ /**
63
+ * Required access token
64
+ */
65
+ accessToken: string;
66
+ /**
67
+ * Used to retrieve a new access token using {@link RefreshTokenCommand}
68
+ */
69
+ refreshToken: string;
70
+ }
71
+ /**
72
+ * Command to login a user
73
+ * @param username string
74
+ * @param password string
75
+ * @group HTTP Commands
76
+ */
77
+ export declare const LoginUserCommand: (data: LoginUser) => HTTPCommand<ReadUser & Authentication>;
78
+ /**
79
+ * Create command to register a user
80
+ * @param username string
81
+ * @param password string
82
+ * @group HTTP Commands
83
+ */
84
+ export declare const RegisterUserCommand: (data: RegisterUser) => HTTPCommand<ReadUser & Authentication>;
85
+ /**
86
+ * Command to create a generated user
87
+ * @param basicUser an optional model
88
+ * @group HTTP Commands
89
+ */
90
+ export declare const CreateGenerateBasicUserCommand: (data?: BasicUser) => HTTPCommand<ReadUser>;
91
+ /**
92
+ * Command to create a test user
93
+ * @param basicUser an optional model
94
+ * @group HTTP Commands
95
+ */
96
+ export declare const CreateTestUserCommand: (username?: string) => HTTPCommand<ReadUser>;
97
+ /**
98
+ * List Users command
99
+ * @param search search criteria for ysers
100
+ * @param accessToken the required accessToken
101
+ * @group HTTP Commands
102
+ */
103
+ export declare const ListUsersCommand: (accessToken: string, search?: string) => HTTPCommand<List<ReadUser>>;
104
+ /**
105
+ * Get a user command
106
+ * @param id the id of the user
107
+ * @param accessToken the required accessToken
108
+ * @group HTTP Commands
109
+ */
110
+ export declare const GetUserCommand: (accessToken: string, id: string) => HTTPCommand<ReadUser>;
111
+ /**
112
+ * Refresh token command
113
+ * @param id the id of the user
114
+ * @param refreshToken the refresh token
115
+ * @group HTTP Commands
116
+ */
117
+ export declare const RefreshTokenCommand: (refreshToken: string, id: string) => HTTPCommand<Authentication>;
118
+ /**
119
+ * Delete a user command
120
+ * @param id the id of the user
121
+ * @param accessToken the required accessToken
122
+ * @group HTTP Commands
123
+ */
124
+ export declare const GetDeleteCommand: (accessToken: string, id: string) => HTTPCommand<ReadUser>;
125
+ /**
126
+ * Update the user command
127
+ * @param data the user needing to be updated, the _id of the user is used to select the user
128
+ * @param accessToken the required accessToken
129
+ * @group HTTP Commands
130
+ */
131
+ export declare const UpdateUserCommand: (accessToken: string, data: UpdateUser) => HTTPCommand<ReadUser>;
132
+ /**
133
+ * Add a bot property command
134
+ * @param data the property
135
+ * @param accessToken the required accessToken
136
+ * @group HTTP Commands
137
+ */
138
+ export declare const AddUserPropertyCommand: (accessToken: string, data: CreateProperty) => HTTPCommand<ReadProperty>;
139
+ /**
140
+ * A command to join a users realtime socket
141
+ * @param _id the id of the user
142
+ * @group Socket Commands
143
+ */
144
+ export declare const JoinUserCommand: (_id: string) => SocketCommand;
145
+ /**
146
+ * A command to leave a users realtime socket
147
+ * @param _id the id of the user
148
+ * @group Socket Commands
149
+ */
150
+ export declare const LeaveUserCommand: (_id: string) => SocketCommand;
151
+ //# sourceMappingURL=users.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/commands/users.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAElG;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,EAAE;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AACD;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI;IACrC,MAAM,CAAC,EAAC,EAAE,CAAA;CACX;AAED;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,IAAI;IAExC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,W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QAAM,cAAc,KAAE,YAAY,YAAY,CAOvG,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAQ,MAAM,KAAG,aAM5C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAQ,MAAM,KAAG,aAM7C,CAAA"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Creates a command to get the user associated with the given accessToken
3
+ * @param accessToken the required accessToken
4
+ * @group HTTP Commands
5
+ */
6
+ export const WhoAmICommand = (accessToken) => {
7
+ return {
8
+ method: "GET",
9
+ path: "/users/whoami",
10
+ accessToken
11
+ };
12
+ };
13
+ /**
14
+ * Command to login a user
15
+ * @param username string
16
+ * @param password string
17
+ * @group HTTP Commands
18
+ */
19
+ export const LoginUserCommand = (data) => {
20
+ return {
21
+ method: "POST",
22
+ path: "/users/login",
23
+ data
24
+ };
25
+ };
26
+ /**
27
+ * Create command to register a user
28
+ * @param username string
29
+ * @param password string
30
+ * @group HTTP Commands
31
+ */
32
+ export const RegisterUserCommand = (data) => {
33
+ return {
34
+ method: "POST",
35
+ path: "/users",
36
+ data
37
+ };
38
+ };
39
+ /**
40
+ * Command to create a generated user
41
+ * @param basicUser an optional model
42
+ * @group HTTP Commands
43
+ */
44
+ export const CreateGenerateBasicUserCommand = (data = {}) => {
45
+ return {
46
+ method: "POST",
47
+ path: "/users/generate/basic",
48
+ data
49
+ };
50
+ };
51
+ /**
52
+ * Command to create a test user
53
+ * @param basicUser an optional model
54
+ * @group HTTP Commands
55
+ */
56
+ export const CreateTestUserCommand = (username) => {
57
+ return {
58
+ method: "POST",
59
+ path: "/users/generate/test",
60
+ data: {
61
+ username
62
+ }
63
+ };
64
+ };
65
+ /**
66
+ * List Users command
67
+ * @param search search criteria for ysers
68
+ * @param accessToken the required accessToken
69
+ * @group HTTP Commands
70
+ */
71
+ export const ListUsersCommand = (accessToken, search) => {
72
+ return {
73
+ method: "GET",
74
+ path: "/users",
75
+ params: search ? new URLSearchParams({ search }) : undefined,
76
+ accessToken
77
+ };
78
+ };
79
+ /**
80
+ * Get a user command
81
+ * @param id the id of the user
82
+ * @param accessToken the required accessToken
83
+ * @group HTTP Commands
84
+ */
85
+ export const GetUserCommand = (accessToken, id) => {
86
+ return {
87
+ method: "GET",
88
+ path: `/users/${id}`,
89
+ accessToken
90
+ };
91
+ };
92
+ /**
93
+ * Refresh token command
94
+ * @param id the id of the user
95
+ * @param refreshToken the refresh token
96
+ * @group HTTP Commands
97
+ */
98
+ export const RefreshTokenCommand = (refreshToken, id) => {
99
+ return {
100
+ method: "POST",
101
+ path: `/users/${id}/refresh_token`,
102
+ data: { refreshToken }
103
+ };
104
+ };
105
+ /**
106
+ * Delete a user command
107
+ * @param id the id of the user
108
+ * @param accessToken the required accessToken
109
+ * @group HTTP Commands
110
+ */
111
+ export const GetDeleteCommand = (accessToken, id) => {
112
+ return {
113
+ method: "DELETE",
114
+ path: `/users/${id}`,
115
+ accessToken
116
+ };
117
+ };
118
+ /**
119
+ * Update the user command
120
+ * @param data the user needing to be updated, the _id of the user is used to select the user
121
+ * @param accessToken the required accessToken
122
+ * @group HTTP Commands
123
+ */
124
+ export const UpdateUserCommand = (accessToken, data) => {
125
+ return {
126
+ method: "PUT",
127
+ path: `/users/${data._id}`,
128
+ data,
129
+ accessToken
130
+ };
131
+ };
132
+ /**
133
+ * Add a bot property command
134
+ * @param data the property
135
+ * @param accessToken the required accessToken
136
+ * @group HTTP Commands
137
+ */
138
+ export const AddUserPropertyCommand = (accessToken, data) => {
139
+ return {
140
+ method: "POST",
141
+ path: `/users/${data.parent_id}/properties`,
142
+ data,
143
+ accessToken
144
+ };
145
+ };
146
+ /**
147
+ * A command to join a users realtime socket
148
+ * @param _id the id of the user
149
+ * @group Socket Commands
150
+ */
151
+ export const JoinUserCommand = (_id) => {
152
+ return {
153
+ method: "/users",
154
+ join: true,
155
+ id: _id
156
+ };
157
+ };
158
+ /**
159
+ * A command to leave a users realtime socket
160
+ * @param _id the id of the user
161
+ * @group Socket Commands
162
+ */
163
+ export const LeaveUserCommand = (_id) => {
164
+ return {
165
+ method: "/users",
166
+ join: false,
167
+ id: _id
168
+ };
169
+ };
170
+ //# sourceMappingURL=users.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/commands/users.ts"],"names":[],"mappings":"AA4DA;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAE,CAAC,WAAmB,EAAwB,EAAE;IACxE,OAAO;QACL,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,eAAe;QACrB,WAAW;KACZ,CAAA;AACH,CAAC,CAAA;AAgBD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAe,EAA0C,EAAE;IAC1F,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,cAAc;QACpB,IAAI;KACL,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAkB,EAA0C,EAAE;IAChG,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,QAAQ;QACd,IAAI;KACL,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,OAAe,EAAE,EAAuB,EAAE;IACvF,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,uBAAuB;QAC7B,IAAI;KACL,CAAA;AACH,CAAC,CAAA;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAuB,EAAE;IAC7E,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE;YACJ,QAAQ;SACT;KACF,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAC,MAAe,EAA+B,EAAE;IACnG,OAAO;QACL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