beamsocial 0.19.2 → 0.20.1

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/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export { Client } from 'lib/index.js';
2
+
3
+ export * from 'lib/models/auth.js';
2
4
  export * from 'lib/models/users.js';
3
- export * from 'lib/models/auth.js';
5
+ export * from 'lib/models/posts.js';
6
+ export * from 'lib/models/comments.js';
@@ -1,4 +1,5 @@
1
1
  import type { RawPost, RawComment, RawFile } from "./types/interactions";
2
+ import { Flag } from "./types/moderation";
2
3
  import { User } from "./users.js";
3
4
  import { Session } from "./auth.js";
4
5
  export declare class Post {
@@ -16,14 +17,14 @@ export declare class Post {
16
17
  comments: number;
17
18
  creation_date: Date;
18
19
  update_date: Date | null;
20
+ flags: Flag[];
19
21
  constructor(id: string);
20
22
  __load(data: RawPost, __session?: Session, __url?: string): void;
21
23
  like(): Promise<void>;
22
24
  unlike(): Promise<void>;
23
- repost(): Promise<void>;
24
- undo_repost(): Promise<void>;
25
25
  add_comment(content: string, visibility: RawComment["visibility"]): Promise<void>;
26
26
  remove_comment(id: string): Promise<void>;
27
27
  report(): Promise<void>;
28
28
  delete(): Promise<void>;
29
+ edit_flags(flags: Flag[] | Record<Flag, boolean>): Promise<void>;
29
30
  }
@@ -21,6 +21,7 @@ export class Post {
21
21
  this.comments = 0;
22
22
  this.creation_date = new Date();
23
23
  this.update_date = null;
24
+ this.flags = [];
24
25
  this.id = id;
25
26
  }
26
27
  __load(data, __session, __url) {
@@ -38,6 +39,7 @@ export class Post {
38
39
  this.comments = data.comments;
39
40
  this.creation_date = new Date(data.creation_date),
40
41
  this.update_date = data.update_date ? new Date(data.update_date) : null;
42
+ this.flags = data.flags;
41
43
  }
42
44
  like() {
43
45
  return __awaiter(this, void 0, void 0, function* () {
@@ -54,10 +56,10 @@ export class Post {
54
56
  if (axios.isAxiosError(err) && err.response) {
55
57
  const res = err.response;
56
58
  if (res.status == 401) {
57
- throw new Error('NotLoggedIn');
59
+ throw new Error('Unauthorized');
58
60
  }
59
61
  else if (res.status == 403) {
60
- throw new Error('PrivatePost');
62
+ throw new Error('Forbidden');
61
63
  }
62
64
  else if (res.status == 404) {
63
65
  throw new Error('PostNotFound');
@@ -86,10 +88,10 @@ export class Post {
86
88
  if (axios.isAxiosError(err) && err.response) {
87
89
  const res = err.response;
88
90
  if (res.status == 401) {
89
- throw new Error('NotLoggedIn');
91
+ throw new Error('Unauthorized');
90
92
  }
91
93
  else if (res.status == 403) {
92
- throw new Error('PrivatePost');
94
+ throw new Error('Forbidden');
93
95
  }
94
96
  else if (res.status == 404) {
95
97
  throw new Error('PostNotFound');
@@ -104,12 +106,6 @@ export class Post {
104
106
  }
105
107
  });
106
108
  }
107
- repost() {
108
- return __awaiter(this, void 0, void 0, function* () { });
109
- }
110
- undo_repost() {
111
- return __awaiter(this, void 0, void 0, function* () { });
112
- }
113
109
  add_comment(content, visibility) {
114
110
  return __awaiter(this, void 0, void 0, function* () {
115
111
  var _a;
@@ -128,10 +124,10 @@ export class Post {
128
124
  if (axios.isAxiosError(err) && err.response) {
129
125
  const res = err.response;
130
126
  if (res.status == 401) {
131
- throw new Error('NotLoggedIn');
127
+ throw new Error('Unauthorized');
132
128
  }
133
129
  else if (res.status == 403) {
134
- throw new Error('PrivatePost');
130
+ throw new Error('Forbidden');
135
131
  }
136
132
  else if (res.status == 404) {
137
133
  throw new Error('PostNotFound');
@@ -164,10 +160,42 @@ export class Post {
164
160
  if (axios.isAxiosError(err) && err.response) {
165
161
  const res = err.response;
166
162
  if (res.status == 401) {
167
- throw new Error('NotLoggedIn');
163
+ throw new Error('Unauthorized');
164
+ }
165
+ else if (res.status == 403) {
166
+ throw new Error('Forbidden');
167
+ }
168
+ else if (res.status == 404) {
169
+ throw new Error('PostNotFound');
170
+ }
171
+ else {
172
+ throw new Error('Error');
173
+ }
174
+ }
175
+ else {
176
+ throw err;
177
+ }
178
+ }
179
+ });
180
+ }
181
+ edit_flags(flags) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ try {
184
+ const res = yield axios.put(this.__url + '/edit_flags', {
185
+ flags: flags
186
+ }, {
187
+ withCredentials: true,
188
+ });
189
+ return;
190
+ }
191
+ catch (err) {
192
+ if (axios.isAxiosError(err) && err.response) {
193
+ const res = err.response;
194
+ if (res.status == 401) {
195
+ throw new Error('Unauthorized');
168
196
  }
169
197
  else if (res.status == 403) {
170
- throw new Error('NotYourPost');
198
+ throw new Error('Forbidden');
171
199
  }
172
200
  else if (res.status == 404) {
173
201
  throw new Error('PostNotFound');
@@ -1,4 +1,5 @@
1
1
  import { Profile } from "./profiles";
2
+ import { Flag } from "./moderation";
2
3
  export type RawFile = {
3
4
  id: string;
4
5
  author_id: string;
@@ -18,6 +19,7 @@ export type RawComment = {
18
19
  answers: number;
19
20
  creation_date: string;
20
21
  update_date: string | null;
22
+ flags: Flag[];
21
23
  };
22
24
  export type RawPost = {
23
25
  id: string;
@@ -31,4 +33,5 @@ export type RawPost = {
31
33
  comments: number;
32
34
  creation_date: string;
33
35
  update_date: string | null;
36
+ flags: Flag[];
34
37
  };
@@ -0,0 +1 @@
1
+ export type Flag = 'NFE' | 'spam' | 'harassment' | 'suspicious' | 'suicide';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beamsocial",
3
- "version": "0.19.2",
3
+ "version": "0.20.1",
4
4
  "type": "module",
5
5
  "description": "API-wrapper pour Beam",
6
6
  "main": "index.js",