beamsocial 0.18.0 → 0.19.0

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/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { User } from './models/users.js';
3
3
  import { Session } from './models/auth.js';
4
4
  import { Post } from './models/posts.js';
5
5
  import { Comment } from './models/comments.js';
6
+ import { Inbox } from './models/inbox.js';
6
7
  export declare class Client {
7
8
  private readonly baseURL;
8
9
  private token?;
@@ -11,6 +12,7 @@ export declare class Client {
11
12
  login(username: string, password: string): Promise<Session | null>;
12
13
  refresh(token?: string): Promise<void>;
13
14
  me(): Promise<Session | null>;
15
+ inbox(): Promise<Inbox | null>;
14
16
  update_settings(settings: Settings): Promise<void>;
15
17
  /*************************************/
16
18
  getUser(name: string): Promise<User | null>;
@@ -22,8 +24,9 @@ export declare class Client {
22
24
  writeComment(content: string, visibility?: "me" | "friends" | "followers" | "everyone", answers_to?: string, post_id?: string): Promise<Comment>;
23
25
  getComment(id: string): Promise<Comment>;
24
26
  }
25
- export { User } from './models/users.js';
26
27
  export { Session } from './models/auth.js';
28
+ export { Inbox, IncomingRequest, OutgoingRequest } from './models/inbox.js';
29
+ export { User } from './models/users.js';
27
30
  export { Post } from './models/posts.js';
28
31
  export { Comment } from './models/comments.js';
29
32
  export type { Badge } from './models/types/profiles.js';
package/lib/index.js CHANGED
@@ -12,6 +12,7 @@ import { User } from './models/users.js';
12
12
  import { Session } from './models/auth.js';
13
13
  import { Post } from './models/posts.js';
14
14
  import { Comment } from './models/comments.js';
15
+ import { Inbox } from './models/inbox.js';
15
16
  export class Client {
16
17
  constructor(baseURL, token) {
17
18
  this.baseURL = baseURL;
@@ -78,6 +79,33 @@ export class Client {
78
79
  }
79
80
  });
80
81
  }
82
+ inbox() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ try {
85
+ const res = yield axios.get(this.baseURL + '/me/inbox', {
86
+ withCredentials: true,
87
+ });
88
+ const data = res.data;
89
+ const inbox = new Inbox(data.id);
90
+ inbox.__load(data, this.session, this.baseURL);
91
+ return inbox;
92
+ }
93
+ catch (err) {
94
+ if (axios.isAxiosError(err) && err.response) {
95
+ const res = err.response;
96
+ if (res.status === 401) {
97
+ throw new Error('NotLoggedIn');
98
+ }
99
+ else {
100
+ throw new Error('Error');
101
+ }
102
+ }
103
+ else {
104
+ throw err;
105
+ }
106
+ }
107
+ });
108
+ }
81
109
  update_settings(settings) {
82
110
  return __awaiter(this, void 0, void 0, function* () {
83
111
  try {
@@ -97,7 +125,7 @@ export class Client {
97
125
  throw new Error('NotLoggedIn');
98
126
  }
99
127
  else {
100
- throw new Error();
128
+ throw new Error('Error');
101
129
  }
102
130
  }
103
131
  else {
@@ -128,7 +156,7 @@ export class Client {
128
156
  return null;
129
157
  }
130
158
  else {
131
- throw new Error();
159
+ throw new Error('Error');
132
160
  }
133
161
  }
134
162
  else {
@@ -163,7 +191,7 @@ export class Client {
163
191
  throw new Error('PostTooLong');
164
192
  }
165
193
  else {
166
- throw new Error();
194
+ throw new Error('Error');
167
195
  }
168
196
  }
169
197
  else {
@@ -196,7 +224,7 @@ export class Client {
196
224
  throw new Error('PostNotFound');
197
225
  }
198
226
  else {
199
- throw new Error();
227
+ throw new Error('Error');
200
228
  }
201
229
  }
202
230
  else {
@@ -233,7 +261,7 @@ export class Client {
233
261
  throw new Error('UserNotFound');
234
262
  }
235
263
  else {
236
- throw new Error();
264
+ throw new Error('Error');
237
265
  }
238
266
  }
239
267
  else {
@@ -269,7 +297,7 @@ export class Client {
269
297
  throw new Error('PostTooLong');
270
298
  }
271
299
  else {
272
- throw new Error();
300
+ throw new Error('Error');
273
301
  }
274
302
  }
275
303
  else {
@@ -302,7 +330,7 @@ export class Client {
302
330
  throw new Error('CommentNotFound');
303
331
  }
304
332
  else {
305
- throw new Error();
333
+ throw new Error('Error');
306
334
  }
307
335
  }
308
336
  else {
@@ -312,7 +340,8 @@ export class Client {
312
340
  });
313
341
  }
314
342
  }
315
- export { User } from './models/users.js';
316
343
  export { Session } from './models/auth.js';
344
+ export { Inbox, IncomingRequest, OutgoingRequest } from './models/inbox.js';
345
+ export { User } from './models/users.js';
317
346
  export { Post } from './models/posts.js';
318
347
  export { Comment } from './models/comments.js';
@@ -1,5 +1,4 @@
1
1
  import type { Profile, Settings, Relations, Tastes } from "./types/profiles";
2
- import type { Inbox } from "./types/inbox";
3
2
  export declare class Session {
4
3
  readonly id: string;
5
4
  readonly token: string | null;
@@ -8,7 +7,6 @@ export declare class Session {
8
7
  settings: Settings;
9
8
  relations: Relations;
10
9
  tastes: Tastes;
11
- inbox: Inbox;
12
10
  constructor(id: string, token: string | null);
13
11
  __load(url: string, data: {
14
12
  profile?: Profile;
@@ -16,6 +14,5 @@ export declare class Session {
16
14
  settings?: Settings;
17
15
  relations?: Relations;
18
16
  tastes?: Tastes;
19
- inbox?: Inbox;
20
17
  }): void;
21
18
  }
@@ -6,7 +6,6 @@ export class Session {
6
6
  this.settings = {};
7
7
  this.relations = {};
8
8
  this.tastes = {};
9
- this.inbox = {};
10
9
  this.id = id;
11
10
  this.token = token;
12
11
  }
@@ -21,8 +20,6 @@ export class Session {
21
20
  this.relations = data.relations;
22
21
  if (data.tastes)
23
22
  this.tastes = data.tastes;
24
- if (data.inbox)
25
- this.inbox = data.inbox;
26
23
  }
27
24
  }
28
25
  ;
@@ -38,8 +38,8 @@ export class Comment {
38
38
  this.visibility = data.visibility;
39
39
  this.likes = data.likes;
40
40
  this.answers = data.answers;
41
- this.creation_date = new Date(data.creation_date),
42
- this.update_date = data.update_date ? new Date(data.update_date) : null;
41
+ this.creation_date = new Date(data.creation_date);
42
+ this.update_date = data.update_date ? new Date(data.update_date) : null;
43
43
  }
44
44
  like() {
45
45
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,36 @@
1
+ import type { RawInbox, Notification, RawPendingRequest } from "./types/inbox.js";
2
+ import { Session } from "./auth.js";
3
+ import { User } from "./users.js";
4
+ export declare class IncomingRequest {
5
+ from: User;
6
+ to: User;
7
+ date: Date;
8
+ constructor(data: RawPendingRequest, __session?: Session, __url?: string);
9
+ accept(request?: "follow" | "child"): Promise<void>;
10
+ reject(request?: "follow" | "child"): Promise<void>;
11
+ }
12
+ export declare class OutgoingRequest {
13
+ from: User;
14
+ to: User;
15
+ date: Date;
16
+ constructor(data: RawPendingRequest, __session?: Session, __url?: string);
17
+ cancel(request?: "follow" | "child"): Promise<void>;
18
+ }
19
+ export declare class Inbox {
20
+ private __token?;
21
+ private __url?;
22
+ private __session?;
23
+ id: string;
24
+ outgoing: {
25
+ child: OutgoingRequest[];
26
+ follow: OutgoingRequest[];
27
+ };
28
+ incoming: {
29
+ child: IncomingRequest[];
30
+ follow: IncomingRequest[];
31
+ };
32
+ unread: Notification[];
33
+ read: Notification[];
34
+ constructor(id: string);
35
+ __load(data: RawInbox, __session?: Session, __url?: string): void;
36
+ }
@@ -0,0 +1,73 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { User } from "./users.js";
11
+ export class IncomingRequest {
12
+ constructor(data, __session, __url) {
13
+ this.from = new User(data.from.id);
14
+ this.from.__load(data.from, __session, __url);
15
+ this.to = new User(data.to.id);
16
+ this.to.__load(data.to, __session, __url);
17
+ this.date = new Date(data.date);
18
+ }
19
+ accept() {
20
+ return __awaiter(this, arguments, void 0, function* (request = "follow") {
21
+ this.from.accept(request);
22
+ });
23
+ }
24
+ reject() {
25
+ return __awaiter(this, arguments, void 0, function* (request = "follow") {
26
+ this.from.reject(request);
27
+ });
28
+ }
29
+ }
30
+ export class OutgoingRequest {
31
+ constructor(data, __session, __url) {
32
+ this.from = new User(data.from.id);
33
+ this.from.__load(data.from, __session, __url);
34
+ this.to = new User(data.to.id);
35
+ this.to.__load(data.to, __session, __url);
36
+ this.date = new Date(data.date);
37
+ }
38
+ cancel() {
39
+ return __awaiter(this, arguments, void 0, function* (request = "follow") {
40
+ this.from.unfollow();
41
+ });
42
+ }
43
+ }
44
+ export class Inbox {
45
+ constructor(id) {
46
+ this.outgoing = {
47
+ child: [],
48
+ follow: []
49
+ };
50
+ this.incoming = {
51
+ child: [],
52
+ follow: []
53
+ };
54
+ this.unread = [];
55
+ this.read = [];
56
+ this.id = id;
57
+ }
58
+ __load(data, __session, __url) {
59
+ this.__token = (__session === null || __session === void 0 ? void 0 : __session.token) || this.__token;
60
+ this.__session = __session;
61
+ this.__url = __url + '/me';
62
+ this.outgoing = {
63
+ child: data.outgoing.child.map((req) => new OutgoingRequest(req, __session, __url)),
64
+ follow: data.outgoing.follow.map((req) => new OutgoingRequest(req, __session, __url))
65
+ };
66
+ this.incoming = {
67
+ child: data.incoming.child.map((req) => new IncomingRequest(req, __session, __url)),
68
+ follow: data.incoming.follow.map((req) => new IncomingRequest(req, __session, __url))
69
+ };
70
+ this.unread = data.unread;
71
+ this.read = data.read;
72
+ }
73
+ }
@@ -1,14 +1,4 @@
1
1
  import type { Profile } from './profiles.js';
2
- export type PartialNotificationBase = {
3
- id: string;
4
- date: Date;
5
- type: string;
6
- isGroupable: boolean;
7
- read: boolean;
8
- };
9
- export type PartialNotificationSingle = PartialNotificationBase & {
10
- author: string;
11
- };
12
2
  export type NotificationBase = {
13
3
  id: string;
14
4
  date: Date;
@@ -20,13 +10,6 @@ export type NotificationBase = {
20
10
  export type NotificationSingle = NotificationBase & {
21
11
  author: Profile;
22
12
  };
23
- export type PartialNotificationPost = PartialNotificationSingle & {
24
- target: string;
25
- };
26
- export type PartialNotificationComment = PartialNotificationSingle & {
27
- target: string;
28
- post: string;
29
- };
30
13
  export type NotificationPost = NotificationSingle & {
31
14
  target: string;
32
15
  };
@@ -43,22 +26,21 @@ export type NotificationBan = NotificationBase & {
43
26
  reason: string;
44
27
  };
45
28
  export type Notification = NotificationSingle | NotificationWarn | NotificationBan | NotificationPost | NotificationComment;
46
- export type PartialNotification = PartialNotificationSingle | PartialNotificationPost | PartialNotificationComment;
47
- export type PartialInbox = {
48
- id: string;
49
- requests: {
50
- children: string[];
51
- following: string[];
52
- followers: string[];
53
- };
54
- other: PartialNotificationSingle[];
29
+ export type RawPendingRequest = {
30
+ from: Profile;
31
+ to: Profile;
32
+ date: Date;
55
33
  };
56
- export type Inbox = {
34
+ export type RawInbox = {
57
35
  id: string;
58
- requests: {
59
- children: Profile[];
60
- following: Profile[];
61
- followers: Profile[];
36
+ outgoing: {
37
+ child: RawPendingRequest[];
38
+ follow: RawPendingRequest[];
39
+ };
40
+ incoming: {
41
+ child: RawPendingRequest[];
42
+ follow: RawPendingRequest[];
62
43
  };
63
- other: Notification[];
44
+ unread: Notification[];
45
+ read: Notification[];
64
46
  };
@@ -43,6 +43,8 @@ export type Relations = {
43
43
  followers: string[];
44
44
  friends: string[];
45
45
  children: string[];
46
+ outgoing: string[];
47
+ incoming: string[];
46
48
  parent: string | null;
47
49
  };
48
50
  export type Tastes = {
@@ -26,6 +26,7 @@ export declare class User {
26
26
  follow(): Promise<void>;
27
27
  unfollow(): Promise<void>;
28
28
  accept(request?: "follow" | "child"): Promise<void>;
29
+ reject(request?: "follow" | "child"): Promise<void>;
29
30
  block(): Promise<void>;
30
31
  unblock(): Promise<void>;
31
32
  }
@@ -124,7 +124,7 @@ export class User {
124
124
  this.followers += 1;
125
125
  }
126
126
  else if (res.status == 206) {
127
- (_a = this.__session) === null || _a === void 0 ? void 0 : _a.inbox.requests.following.push(this);
127
+ (_a = this.__session) === null || _a === void 0 ? void 0 : _a.relations.outgoing.push(this.id);
128
128
  }
129
129
  return;
130
130
  }
@@ -183,7 +183,6 @@ export class User {
183
183
  }
184
184
  accept() {
185
185
  return __awaiter(this, arguments, void 0, function* (request = "follow") {
186
- var _a;
187
186
  try {
188
187
  const res = yield axios.post(this.__url + `/accept/${request}`, {}, {
189
188
  withCredentials: true,
@@ -191,9 +190,6 @@ export class User {
191
190
  if (res.status == 200) {
192
191
  this.followers += 1;
193
192
  }
194
- else if (res.status == 206) {
195
- (_a = this.__session) === null || _a === void 0 ? void 0 : _a.inbox.requests.following.push(this);
196
- }
197
193
  return;
198
194
  }
199
195
  catch (err) {
@@ -218,6 +214,25 @@ export class User {
218
214
  }
219
215
  });
220
216
  }
217
+ reject() {
218
+ return __awaiter(this, arguments, void 0, function* (request = "follow") {
219
+ try {
220
+ const res = yield axios.post(this.__url + `/reject/${request}`, {}, {
221
+ withCredentials: true,
222
+ });
223
+ return;
224
+ }
225
+ catch (err) {
226
+ if (axios.isAxiosError(err) && err.response) {
227
+ const res = err.response;
228
+ throw new Error('Error');
229
+ }
230
+ else {
231
+ throw err;
232
+ }
233
+ }
234
+ });
235
+ }
221
236
  block() {
222
237
  return __awaiter(this, void 0, void 0, function* () {
223
238
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beamsocial",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "description": "API-wrapper pour Beam",
6
6
  "main": "index.js",