beamsocial 0.5.4 → 0.6.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 +6 -6
- package/lib/models/posts.d.ts +3 -0
- package/lib/models/posts.js +42 -7
- package/lib/models/types/interactions.d.ts +6 -3
- package/lib/models/users.js +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -53,7 +53,7 @@ export class Client {
|
|
|
53
53
|
try {
|
|
54
54
|
const res = yield axios.get(this.baseURL + '/me', {
|
|
55
55
|
headers: {
|
|
56
|
-
Authorization: `Bearer ${this.token}
|
|
56
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
57
57
|
},
|
|
58
58
|
});
|
|
59
59
|
let session;
|
|
@@ -85,7 +85,7 @@ export class Client {
|
|
|
85
85
|
appearence: settings.appearance
|
|
86
86
|
}, {
|
|
87
87
|
headers: {
|
|
88
|
-
Authorization: `Bearer ${this.token}
|
|
88
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
89
89
|
},
|
|
90
90
|
});
|
|
91
91
|
yield this.refresh();
|
|
@@ -113,7 +113,7 @@ export class Client {
|
|
|
113
113
|
try {
|
|
114
114
|
const res = yield axios.get(this.baseURL + '/users/' + name, {
|
|
115
115
|
headers: {
|
|
116
|
-
Authorization: `Bearer ${this.token}
|
|
116
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
117
117
|
},
|
|
118
118
|
});
|
|
119
119
|
let user;
|
|
@@ -149,7 +149,7 @@ export class Client {
|
|
|
149
149
|
visibility: visibility
|
|
150
150
|
}, {
|
|
151
151
|
headers: {
|
|
152
|
-
Authorization: `Bearer ${this.token}
|
|
152
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
153
153
|
},
|
|
154
154
|
});
|
|
155
155
|
const data = res.data;
|
|
@@ -181,7 +181,7 @@ export class Client {
|
|
|
181
181
|
try {
|
|
182
182
|
const res = yield axios.get(this.baseURL + '/posts/' + id, {
|
|
183
183
|
headers: {
|
|
184
|
-
Authorization: `Bearer ${this.token}
|
|
184
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
185
185
|
},
|
|
186
186
|
});
|
|
187
187
|
const data = res.data;
|
|
@@ -216,7 +216,7 @@ export class Client {
|
|
|
216
216
|
try {
|
|
217
217
|
const res = yield axios.get(this.baseURL + '/users/' + name + `/posts`, {
|
|
218
218
|
headers: {
|
|
219
|
-
Authorization: `Bearer ${this.token}
|
|
219
|
+
Authorization: this.token ? `Bearer ${this.token}` : undefined,
|
|
220
220
|
},
|
|
221
221
|
});
|
|
222
222
|
const data = res.data;
|
package/lib/models/posts.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare class Post {
|
|
|
6
6
|
private __token?;
|
|
7
7
|
private __url?;
|
|
8
8
|
id: string;
|
|
9
|
+
parent_id: string | null;
|
|
9
10
|
author: User | null;
|
|
10
11
|
content: string;
|
|
11
12
|
attachments: RawFile[];
|
|
@@ -13,6 +14,8 @@ export declare class Post {
|
|
|
13
14
|
likes: number;
|
|
14
15
|
reposts: number;
|
|
15
16
|
comments: number;
|
|
17
|
+
creation_date: Date;
|
|
18
|
+
update_date: Date | null;
|
|
16
19
|
constructor(id: string);
|
|
17
20
|
__load(data: RawPost, __session?: Session, __url?: string): void;
|
|
18
21
|
like(): Promise<void>;
|
package/lib/models/posts.js
CHANGED
|
@@ -11,6 +11,7 @@ import axios from "axios";
|
|
|
11
11
|
import { User } from "./users.js";
|
|
12
12
|
export class Post {
|
|
13
13
|
constructor(id) {
|
|
14
|
+
this.parent_id = null;
|
|
14
15
|
this.author = null;
|
|
15
16
|
this.content = '';
|
|
16
17
|
this.attachments = [];
|
|
@@ -18,6 +19,8 @@ export class Post {
|
|
|
18
19
|
this.likes = 0;
|
|
19
20
|
this.reposts = 0;
|
|
20
21
|
this.comments = 0;
|
|
22
|
+
this.creation_date = new Date();
|
|
23
|
+
this.update_date = null;
|
|
21
24
|
this.id = id;
|
|
22
25
|
}
|
|
23
26
|
__load(data, __session, __url) {
|
|
@@ -26,12 +29,15 @@ export class Post {
|
|
|
26
29
|
this.__url = __url + '/posts/' + data.id;
|
|
27
30
|
this.author = new User(data.author.id);
|
|
28
31
|
this.author.__load(data.author, __session, __url);
|
|
32
|
+
this.parent_id = data.parent_id;
|
|
29
33
|
this.content = data.content;
|
|
30
34
|
this.attachments = data.attachments;
|
|
31
35
|
this.visibility = data.visibility;
|
|
32
36
|
this.likes = data.likes;
|
|
33
37
|
this.reposts = data.reposts;
|
|
34
38
|
this.comments = data.comments;
|
|
39
|
+
this.creation_date = new Date(data.creation_date),
|
|
40
|
+
this.update_date = data.update_date ? new Date(data.update_date) : null;
|
|
35
41
|
}
|
|
36
42
|
like() {
|
|
37
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -39,7 +45,7 @@ export class Post {
|
|
|
39
45
|
try {
|
|
40
46
|
const res = yield axios.post(this.__url + `/like`, {}, {
|
|
41
47
|
headers: {
|
|
42
|
-
Authorization: `Bearer ${this.__token}
|
|
48
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
43
49
|
},
|
|
44
50
|
});
|
|
45
51
|
this.likes += 1;
|
|
@@ -56,10 +62,10 @@ export class Post {
|
|
|
56
62
|
throw new Error('Private account');
|
|
57
63
|
}
|
|
58
64
|
else if (res.status == 404) {
|
|
59
|
-
throw new Error('
|
|
65
|
+
throw new Error('Post not found');
|
|
60
66
|
}
|
|
61
67
|
else {
|
|
62
|
-
throw new Error('Error
|
|
68
|
+
throw new Error('Error liking post');
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
else {
|
|
@@ -73,7 +79,7 @@ export class Post {
|
|
|
73
79
|
try {
|
|
74
80
|
const res = yield axios.delete(this.__url + `/like`, {
|
|
75
81
|
headers: {
|
|
76
|
-
Authorization: `Bearer ${this.__token}
|
|
82
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
77
83
|
},
|
|
78
84
|
});
|
|
79
85
|
this.likes -= 1;
|
|
@@ -90,10 +96,10 @@ export class Post {
|
|
|
90
96
|
throw new Error('Private account');
|
|
91
97
|
}
|
|
92
98
|
else if (res.status == 404) {
|
|
93
|
-
throw new Error('
|
|
99
|
+
throw new Error('Post not found');
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
96
|
-
throw new Error('Error
|
|
102
|
+
throw new Error('Error unliking post');
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
else {
|
|
@@ -118,6 +124,35 @@ export class Post {
|
|
|
118
124
|
return __awaiter(this, void 0, void 0, function* () { });
|
|
119
125
|
}
|
|
120
126
|
delete() {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
try {
|
|
129
|
+
const res = yield axios.delete(this.__url, {
|
|
130
|
+
headers: {
|
|
131
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
138
|
+
const res = err.response;
|
|
139
|
+
if (res.status == 401) {
|
|
140
|
+
throw new Error('Not logged in');
|
|
141
|
+
}
|
|
142
|
+
else if (res.status == 403) {
|
|
143
|
+
throw new Error('Not your post');
|
|
144
|
+
}
|
|
145
|
+
else if (res.status == 404) {
|
|
146
|
+
throw new Error('Post not found');
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new Error('Error deleting post');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
122
157
|
}
|
|
123
158
|
}
|
|
@@ -9,15 +9,16 @@ export type RawFile = {
|
|
|
9
9
|
};
|
|
10
10
|
export type RawComment = {
|
|
11
11
|
id: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
post: RawPost;
|
|
13
|
+
parent: RawComment | null;
|
|
14
|
+
author: Profile;
|
|
15
15
|
content: string;
|
|
16
16
|
visibility: "everyone" | "followers" | "friends" | "me";
|
|
17
17
|
likes: number;
|
|
18
18
|
};
|
|
19
19
|
export type RawPost = {
|
|
20
20
|
id: string;
|
|
21
|
+
parent_id: string | null;
|
|
21
22
|
author: Profile;
|
|
22
23
|
content: string;
|
|
23
24
|
attachments: RawFile[];
|
|
@@ -25,4 +26,6 @@ export type RawPost = {
|
|
|
25
26
|
likes: number;
|
|
26
27
|
reposts: number;
|
|
27
28
|
comments: number;
|
|
29
|
+
creation_date: string;
|
|
30
|
+
update_date: string | null;
|
|
28
31
|
};
|
package/lib/models/users.js
CHANGED
|
@@ -44,7 +44,7 @@ export class User {
|
|
|
44
44
|
try {
|
|
45
45
|
const res = yield axios.post(this.__url + `/follow`, {}, {
|
|
46
46
|
headers: {
|
|
47
|
-
Authorization: `Bearer ${this.__token}
|
|
47
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
this.followers += 1;
|
|
@@ -77,7 +77,7 @@ export class User {
|
|
|
77
77
|
try {
|
|
78
78
|
const res = yield axios.post(this.__url + `/unfollow`, {}, {
|
|
79
79
|
headers: {
|
|
80
|
-
Authorization: `Bearer ${this.__token}
|
|
80
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
83
|
this.followers -= 1;
|
|
@@ -111,7 +111,7 @@ export class User {
|
|
|
111
111
|
try {
|
|
112
112
|
const res = yield axios.post(this.__url + `/block`, {}, {
|
|
113
113
|
headers: {
|
|
114
|
-
Authorization: `Bearer ${this.__token}
|
|
114
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
115
115
|
},
|
|
116
116
|
});
|
|
117
117
|
(_a = this.__session) === null || _a === void 0 ? void 0 : _a.relations.blocklist.push(this.id);
|
|
@@ -141,7 +141,7 @@ export class User {
|
|
|
141
141
|
try {
|
|
142
142
|
const res = yield axios.post(this.__url + `/unblock`, {}, {
|
|
143
143
|
headers: {
|
|
144
|
-
Authorization: `Bearer ${this.__token}
|
|
144
|
+
Authorization: this.__token ? `Bearer ${this.__token}` : undefined,
|
|
145
145
|
},
|
|
146
146
|
});
|
|
147
147
|
if (this.__session && this.__session.relations) {
|