beamsocial 0.1.5 → 0.3.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 +3 -0
- package/lib/index.js +33 -0
- package/lib/models/posts.d.ts +23 -0
- package/lib/models/posts.js +56 -0
- package/lib/models/types/interactions.d.ts +17 -9
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ProfileSettings } from './models/types/profiles.js';
|
|
2
2
|
import { User } from './models/users.js';
|
|
3
3
|
import { Session } from './models/auth.js';
|
|
4
|
+
import { Post } from './models/posts.js';
|
|
4
5
|
export declare class Client {
|
|
5
6
|
private readonly baseURL;
|
|
6
7
|
private token;
|
|
@@ -12,6 +13,8 @@ export declare class Client {
|
|
|
12
13
|
update_settings(settings: ProfileSettings): Promise<void>;
|
|
13
14
|
/*************************************/
|
|
14
15
|
getUser(name: string): Promise<User | null>;
|
|
16
|
+
fetchUserPosts(name: string): Promise<Post[]>;
|
|
15
17
|
}
|
|
16
18
|
export { User } from './models/users.js';
|
|
17
19
|
export { Session } from './models/auth.js';
|
|
20
|
+
export { Post } from './models/posts.js';
|
package/lib/index.js
CHANGED
|
@@ -141,6 +141,39 @@ export class Client {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
fetchUserPosts(name) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
try {
|
|
147
|
+
const res = yield axios.get(this.baseURL + '/users/' + name + `/posts`, {
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: `Bearer ${this.token}`,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
return res.data;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
156
|
+
const res = err.response;
|
|
157
|
+
if (res.status == 401) {
|
|
158
|
+
throw new Error('Not logged in');
|
|
159
|
+
}
|
|
160
|
+
else if (res.status == 403) {
|
|
161
|
+
throw new Error('Private account');
|
|
162
|
+
}
|
|
163
|
+
else if (res.status == 404) {
|
|
164
|
+
throw new Error('User not found');
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error('Error fetching posts');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
144
176
|
}
|
|
145
177
|
export { User } from './models/users.js';
|
|
146
178
|
export { Session } from './models/auth.js';
|
|
179
|
+
export { Post } from './models/posts.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RawPost, RawComment, RawFile } from "./types/interactions";
|
|
2
|
+
export declare class Post {
|
|
3
|
+
private readonly __token?;
|
|
4
|
+
private readonly __url?;
|
|
5
|
+
id: string;
|
|
6
|
+
author_id: string;
|
|
7
|
+
content: string;
|
|
8
|
+
attachments: RawFile[];
|
|
9
|
+
visibility: "everyone" | "followers" | "friends" | "me";
|
|
10
|
+
likes: string[];
|
|
11
|
+
reposts: string[];
|
|
12
|
+
comments: RawComment[];
|
|
13
|
+
constructor(id: string, __token?: string, __url?: string);
|
|
14
|
+
__load(data: RawPost): void;
|
|
15
|
+
like(): Promise<void>;
|
|
16
|
+
unlike(): Promise<void>;
|
|
17
|
+
repost(): Promise<void>;
|
|
18
|
+
undo_repost(): Promise<void>;
|
|
19
|
+
add_comment(comment: RawComment): Promise<void>;
|
|
20
|
+
remove_comment(comment: RawComment): Promise<void>;
|
|
21
|
+
report(): Promise<void>;
|
|
22
|
+
delete(): Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
export class Post {
|
|
11
|
+
constructor(id, __token, __url) {
|
|
12
|
+
this.author_id = '';
|
|
13
|
+
this.content = '';
|
|
14
|
+
this.attachments = [];
|
|
15
|
+
this.visibility = "followers";
|
|
16
|
+
this.likes = [];
|
|
17
|
+
this.reposts = [];
|
|
18
|
+
this.comments = [];
|
|
19
|
+
this.id = id;
|
|
20
|
+
this.__token = __token;
|
|
21
|
+
this.__url = __url;
|
|
22
|
+
}
|
|
23
|
+
__load(data) {
|
|
24
|
+
this.author_id = data.author_id;
|
|
25
|
+
this.content = data.content;
|
|
26
|
+
this.attachments = data.attachements;
|
|
27
|
+
this.visibility = data.visibility;
|
|
28
|
+
this.likes = data.likes;
|
|
29
|
+
this.reposts = data.reposts;
|
|
30
|
+
this.comments = data.comments;
|
|
31
|
+
}
|
|
32
|
+
like() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
34
|
+
}
|
|
35
|
+
unlike() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
37
|
+
}
|
|
38
|
+
repost() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
40
|
+
}
|
|
41
|
+
undo_repost() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
43
|
+
}
|
|
44
|
+
add_comment(comment) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
46
|
+
}
|
|
47
|
+
remove_comment(comment) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
49
|
+
}
|
|
50
|
+
report() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
52
|
+
}
|
|
53
|
+
delete() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type RawFile = {
|
|
2
2
|
id: string;
|
|
3
3
|
author_id: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
reposts: string[];
|
|
9
|
-
comments: string[];
|
|
4
|
+
path: string;
|
|
5
|
+
type: string;
|
|
6
|
+
date: string;
|
|
7
|
+
hidden: boolean;
|
|
10
8
|
};
|
|
11
|
-
export type
|
|
9
|
+
export type RawComment = {
|
|
12
10
|
id: string;
|
|
13
11
|
author_id: string;
|
|
14
12
|
parent_id: string;
|
|
15
13
|
post_id: string;
|
|
16
14
|
content: string;
|
|
17
|
-
visibility:
|
|
15
|
+
visibility: "everyone" | "followers" | "friends" | "me";
|
|
18
16
|
likes: string[];
|
|
19
17
|
};
|
|
18
|
+
export type RawPost = {
|
|
19
|
+
id: string;
|
|
20
|
+
author_id: string;
|
|
21
|
+
content: string;
|
|
22
|
+
attachements: RawFile[];
|
|
23
|
+
visibility: "everyone" | "followers" | "friends" | "me";
|
|
24
|
+
likes: string[];
|
|
25
|
+
reposts: string[];
|
|
26
|
+
comments: RawComment[];
|
|
27
|
+
};
|