beamsocial 0.7.4 → 0.9.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.js CHANGED
@@ -31,7 +31,7 @@ export class Client {
31
31
  return null;
32
32
  }
33
33
  else {
34
- throw new Error('Error logging in');
34
+ throw new Error();
35
35
  }
36
36
  }
37
37
  else {
@@ -68,7 +68,7 @@ export class Client {
68
68
  return null;
69
69
  }
70
70
  else {
71
- throw new Error('Error fetching session');
71
+ throw new Error();
72
72
  }
73
73
  }
74
74
  else {
@@ -95,10 +95,10 @@ export class Client {
95
95
  if (axios.isAxiosError(err) && err.response) {
96
96
  const res = err.response;
97
97
  if (res.status == 401) {
98
- throw new Error('Not logged in');
98
+ throw new Error('NotLoggedIn');
99
99
  }
100
100
  else {
101
- throw new Error('Error updating settings');
101
+ throw new Error();
102
102
  }
103
103
  }
104
104
  else {
@@ -125,13 +125,13 @@ export class Client {
125
125
  if (axios.isAxiosError(err) && err.response) {
126
126
  const res = err.response;
127
127
  if (res.status === 403) {
128
- throw new Error('Private account');
128
+ throw new Error('PrivateAccount');
129
129
  }
130
130
  else if (res.status === 404) {
131
131
  return null;
132
132
  }
133
133
  else {
134
- throw new Error('Error fetching user');
134
+ throw new Error();
135
135
  }
136
136
  }
137
137
  else {
@@ -161,13 +161,13 @@ export class Client {
161
161
  if (axios.isAxiosError(err) && err.response) {
162
162
  const res = err.response;
163
163
  if (res.status == 401) {
164
- throw new Error('Not logged in');
164
+ throw new Error('NotLoggedIn');
165
165
  }
166
166
  else if (res.status == 413) {
167
- throw new Error('Post too long');
167
+ throw new Error('PostTooLong');
168
168
  }
169
169
  else {
170
- throw new Error('Error writing post');
170
+ throw new Error();
171
171
  }
172
172
  }
173
173
  else {
@@ -193,16 +193,16 @@ export class Client {
193
193
  if (axios.isAxiosError(err) && err.response) {
194
194
  const res = err.response;
195
195
  if (res.status == 401) {
196
- throw new Error('Not logged in');
196
+ throw new Error('NotLoggedIn');
197
197
  }
198
198
  else if (res.status == 403) {
199
- throw new Error('Private account');
199
+ throw new Error('PrivateAccount');
200
200
  }
201
201
  else if (res.status == 404) {
202
- throw new Error('Post not found');
202
+ throw new Error('PostNotFound');
203
203
  }
204
204
  else {
205
- throw new Error('Error writing post');
205
+ throw new Error();
206
206
  }
207
207
  }
208
208
  else {
@@ -232,16 +232,16 @@ export class Client {
232
232
  if (axios.isAxiosError(err) && err.response) {
233
233
  const res = err.response;
234
234
  if (res.status == 401) {
235
- throw new Error('Not logged in');
235
+ throw new Error('NotLoggedIn');
236
236
  }
237
237
  else if (res.status == 403) {
238
- throw new Error('Private account');
238
+ throw new Error('PrivateAccount');
239
239
  }
240
240
  else if (res.status == 404) {
241
- throw new Error('User not found');
241
+ throw new Error('UserNotFound');
242
242
  }
243
243
  else {
244
- throw new Error('Error fetching posts');
244
+ throw new Error();
245
245
  }
246
246
  }
247
247
  else {
@@ -1,4 +1,5 @@
1
1
  import type { Profile, Settings, Relations, Tastes } from "./types/profiles";
2
+ import type { Inbox } from "./types/inbox";
2
3
  export declare class Session {
3
4
  readonly id: string;
4
5
  readonly token: string | null;
@@ -7,14 +8,14 @@ export declare class Session {
7
8
  settings: Settings;
8
9
  relations: Relations;
9
10
  tastes: Tastes;
10
- inbox: {};
11
+ inbox: Inbox;
11
12
  constructor(id: string, token: string | null);
12
13
  __load(url: string, data: {
13
14
  profile?: Profile;
14
15
  avatar?: string;
15
16
  settings?: Settings;
16
17
  relations?: Relations;
17
- tastes: Tastes;
18
- inbox?: {};
18
+ tastes?: Tastes;
19
+ inbox?: Inbox;
19
20
  }): void;
20
21
  }
@@ -56,16 +56,16 @@ export class Post {
56
56
  if (axios.isAxiosError(err) && err.response) {
57
57
  const res = err.response;
58
58
  if (res.status == 401) {
59
- throw new Error('Not logged in');
59
+ throw new Error('NotLoggedIn');
60
60
  }
61
61
  else if (res.status == 403) {
62
- throw new Error('Private account');
62
+ throw new Error('PrivatePost');
63
63
  }
64
64
  else if (res.status == 404) {
65
- throw new Error('Post not found');
65
+ throw new Error('PostNotFound');
66
66
  }
67
67
  else {
68
- throw new Error('Error liking post');
68
+ throw new Error('Error');
69
69
  }
70
70
  }
71
71
  else {
@@ -90,16 +90,16 @@ export class Post {
90
90
  if (axios.isAxiosError(err) && err.response) {
91
91
  const res = err.response;
92
92
  if (res.status == 401) {
93
- throw new Error('Not logged in');
93
+ throw new Error('NotLoggedIn');
94
94
  }
95
95
  else if (res.status == 403) {
96
- throw new Error('Private account');
96
+ throw new Error('PrivatePost');
97
97
  }
98
98
  else if (res.status == 404) {
99
- throw new Error('Post not found');
99
+ throw new Error('PostNotFound');
100
100
  }
101
101
  else {
102
- throw new Error('Error unliking post');
102
+ throw new Error('Error');
103
103
  }
104
104
  }
105
105
  else {
@@ -137,16 +137,16 @@ export class Post {
137
137
  if (axios.isAxiosError(err) && err.response) {
138
138
  const res = err.response;
139
139
  if (res.status == 401) {
140
- throw new Error('Not logged in');
140
+ throw new Error('NotLoggedIn');
141
141
  }
142
142
  else if (res.status == 403) {
143
- throw new Error('Not your post');
143
+ throw new Error('NotYourPost');
144
144
  }
145
145
  else if (res.status == 404) {
146
- throw new Error('Post not found');
146
+ throw new Error('PostNotFound');
147
147
  }
148
148
  else {
149
- throw new Error('Error deleting post');
149
+ throw new Error('Error');
150
150
  }
151
151
  }
152
152
  else {
@@ -0,0 +1,32 @@
1
+ export interface NotificationBase {
2
+ id: string;
3
+ date: Date;
4
+ type: string;
5
+ isGroupable: boolean;
6
+ read: boolean;
7
+ }
8
+ export interface NotificationGroup extends NotificationBase {
9
+ authors: string[];
10
+ target: string;
11
+ }
12
+ export interface NotificationSingle extends NotificationBase {
13
+ author: string;
14
+ }
15
+ export interface NotificationWarn extends NotificationBase {
16
+ reason: string;
17
+ }
18
+ export interface NotificationBan extends NotificationBase {
19
+ soft: boolean;
20
+ until: Date;
21
+ reason: string;
22
+ }
23
+ export type Notification = NotificationGroup | NotificationSingle | NotificationWarn | NotificationBan;
24
+ export type Inbox = {
25
+ id: string;
26
+ requests: {
27
+ children: string[];
28
+ following: string[];
29
+ followers: string[];
30
+ };
31
+ other: Notification[];
32
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -28,11 +28,6 @@ export type Settings = {
28
28
  export type Relations = {
29
29
  id: string;
30
30
  blocklist: string[];
31
- pending: {
32
- children: string[];
33
- followers: string[];
34
- following: string[];
35
- };
36
31
  following: string[];
37
32
  followers: string[];
38
33
  friends: string[];
@@ -22,6 +22,7 @@ export declare class User {
22
22
  __load(data: Profile, __session?: Session, __url?: string): void;
23
23
  follow(): Promise<void>;
24
24
  unfollow(): Promise<void>;
25
+ accept(request?: "follow" | "child"): Promise<void>;
25
26
  block(): Promise<void>;
26
27
  unblock(): Promise<void>;
27
28
  }
@@ -56,7 +56,7 @@ export class User {
56
56
  this.followers += 1;
57
57
  }
58
58
  else if (res.status == 206) {
59
- (_a = this.__session) === null || _a === void 0 ? void 0 : _a.relations.pending.following.push(this.id);
59
+ (_a = this.__session) === null || _a === void 0 ? void 0 : _a.inbox.requests.following.push(this.id);
60
60
  }
61
61
  return;
62
62
  }
@@ -64,16 +64,16 @@ export class User {
64
64
  if (axios.isAxiosError(err) && err.response) {
65
65
  const res = err.response;
66
66
  if (res.status == 401) {
67
- throw new Error('Not logged in');
67
+ throw new Error('NotLoggedIn');
68
68
  }
69
69
  else if (res.status == 403) {
70
- throw new Error('Private account');
70
+ throw new Error('PrivateAccount');
71
71
  }
72
72
  else if (res.status == 404) {
73
- throw new Error('User not found');
73
+ throw new Error('UserNotFound');
74
74
  }
75
75
  else {
76
- throw new Error('Error following user');
76
+ throw new Error('Error');
77
77
  }
78
78
  }
79
79
  else {
@@ -97,16 +97,55 @@ export class User {
97
97
  if (axios.isAxiosError(err) && err.response) {
98
98
  const res = err.response;
99
99
  if (res.status == 401) {
100
- throw new Error('Not logged in');
100
+ throw new Error('NotLoggedIn');
101
101
  }
102
102
  else if (res.status == 403) {
103
- throw new Error('Private account');
103
+ throw new Error('PrivateAccount');
104
104
  }
105
105
  else if (res.status == 404) {
106
- throw new Error('User not found');
106
+ throw new Error('UserNotFound');
107
107
  }
108
108
  else {
109
- throw new Error('Error unfollowing user');
109
+ throw new Error('Error');
110
+ }
111
+ }
112
+ else {
113
+ throw err;
114
+ }
115
+ }
116
+ });
117
+ }
118
+ accept() {
119
+ return __awaiter(this, arguments, void 0, function* (request = "follow") {
120
+ var _a;
121
+ try {
122
+ const res = yield axios.post(this.__url + `/accept/${request}`, {}, {
123
+ headers: {
124
+ Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
125
+ }
126
+ });
127
+ if (res.status == 200) {
128
+ this.followers += 1;
129
+ }
130
+ else if (res.status == 206) {
131
+ (_a = this.__session) === null || _a === void 0 ? void 0 : _a.inbox.requests.following.push(this.id);
132
+ }
133
+ return;
134
+ }
135
+ catch (err) {
136
+ if (axios.isAxiosError(err) && err.response) {
137
+ const res = err.response;
138
+ if (res.status == 401) {
139
+ throw new Error('NotLoggedIn');
140
+ }
141
+ else if (res.status == 403) {
142
+ throw new Error('PrivateAccount');
143
+ }
144
+ else if (res.status == 404) {
145
+ throw new Error('UserNotFound');
146
+ }
147
+ else {
148
+ throw new Error('Error');
110
149
  }
111
150
  }
112
151
  else {
@@ -131,13 +170,13 @@ export class User {
131
170
  if (axios.isAxiosError(err) && err.response) {
132
171
  const res = err.response;
133
172
  if (res.status == 401) {
134
- throw new Error('Not logged in');
173
+ throw new Error('NotLoggedIn');
135
174
  }
136
175
  else if (res.status == 404) {
137
- throw new Error('User not found');
176
+ throw new Error('UserNotFound');
138
177
  }
139
178
  else {
140
- throw new Error('Error block user');
179
+ throw new Error('Error');
141
180
  }
142
181
  }
143
182
  else {
@@ -163,13 +202,13 @@ export class User {
163
202
  if (axios.isAxiosError(err) && err.response) {
164
203
  const res = err.response;
165
204
  if (res.status == 401) {
166
- throw new Error('Not logged in');
205
+ throw new Error('NotLoggedIn');
167
206
  }
168
207
  else if (res.status == 404) {
169
- throw new Error('User not found');
208
+ throw new Error('UserNotFound');
170
209
  }
171
210
  else {
172
- throw new Error('Error unblocking user');
211
+ throw new Error('Error');
173
212
  }
174
213
  }
175
214
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beamsocial",
3
- "version": "0.7.4",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "API-wrapper pour Beam",
6
6
  "main": "index.js",