beamsocial 0.0.3 → 0.1.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,113 +1 @@
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 axios from 'axios';
11
- import { User } from './models/users.js';
12
- import { Session } from './models/auth.js';
13
- export class Client {
14
- constructor(baseURL, token) {
15
- this.token = null;
16
- this.session = null;
17
- this.baseURL = baseURL;
18
- if (token)
19
- this.token = token;
20
- }
21
- login(username, password) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const res = yield axios.post(this.baseURL + '/auth/login', { username, password });
24
- if (res.status === 200) {
25
- this.token = res.data.token;
26
- }
27
- else if (res.status === 401) {
28
- throw new Error('Invalid credentials');
29
- }
30
- else {
31
- throw new Error('Error logging in');
32
- }
33
- yield this.refresh();
34
- return this.session;
35
- });
36
- }
37
- refresh(token) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (token)
40
- this.token = token;
41
- let session = yield this.me();
42
- this.session = session;
43
- });
44
- }
45
- me() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const res = yield axios.get(this.baseURL + '/me', {
48
- headers: {
49
- Authorization: `Bearer ${this.token}`,
50
- },
51
- });
52
- let session;
53
- if (res.status === 200) {
54
- session = new Session(res.data.id, this.token);
55
- session.__load(res.data);
56
- return session;
57
- }
58
- else if (res.status === 401) {
59
- throw new Error('Not logged in');
60
- }
61
- else {
62
- throw new Error('Error fetching session');
63
- }
64
- });
65
- }
66
- update_settings(settings) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const res = yield axios.post(this.baseURL + '/me/update_settings', {
69
- privacy: settings.preferences.privacy,
70
- appearence: settings.preferences.appearance
71
- }, {
72
- headers: {
73
- Authorization: `Bearer ${this.token}`,
74
- },
75
- });
76
- if (res.status == 200) {
77
- yield this.refresh();
78
- return;
79
- }
80
- else if (res.status == 401) {
81
- throw new Error('Not logged in');
82
- }
83
- else {
84
- throw new Error('Error updating settings');
85
- }
86
- });
87
- }
88
- /*************************************/
89
- getUser(name) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const res = yield axios.get(this.baseURL + '/users/' + name, {
92
- headers: {
93
- Authorization: `Bearer ${this.token}`,
94
- },
95
- });
96
- let user;
97
- if (res.status === 200) {
98
- user = new User(res.data.id, this.token, this.baseURL + '/users/' + name);
99
- user.__load(res.data);
100
- return user;
101
- }
102
- else if (res.status === 403) {
103
- throw new Error('User is private');
104
- }
105
- else if (res.status === 404) {
106
- throw new Error('User not found');
107
- }
108
- else {
109
- throw new Error('Error fetching user');
110
- }
111
- });
112
- }
113
- }
1
+ export { Client } from 'lib/index.js';
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { ProfileSettings } from './models/types/profiles.js';
2
+ import { User } from './models/users.js';
3
+ import { Session } from './models/auth.js';
4
+ export declare class Client {
5
+ private readonly baseURL;
6
+ private token;
7
+ private session;
8
+ constructor(baseURL: string, token?: string);
9
+ login(username: string, password: string): Promise<Session | null>;
10
+ refresh(token?: string): Promise<void>;
11
+ me(): Promise<Session>;
12
+ update_settings(settings: ProfileSettings): Promise<void>;
13
+ /*************************************/
14
+ getUser(name: string): Promise<User>;
15
+ }
package/lib/index.js ADDED
@@ -0,0 +1,113 @@
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 axios from 'axios';
11
+ import { User } from './models/users.js';
12
+ import { Session } from './models/auth.js';
13
+ export class Client {
14
+ constructor(baseURL, token) {
15
+ this.token = null;
16
+ this.session = null;
17
+ this.baseURL = baseURL;
18
+ if (token)
19
+ this.token = token;
20
+ }
21
+ login(username, password) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const res = yield axios.post(this.baseURL + '/auth/login', { username, password });
24
+ if (res.status === 200) {
25
+ this.token = res.data.token;
26
+ }
27
+ else if (res.status === 401) {
28
+ throw new Error('Invalid credentials');
29
+ }
30
+ else {
31
+ throw new Error('Error logging in');
32
+ }
33
+ yield this.refresh();
34
+ return this.session;
35
+ });
36
+ }
37
+ refresh(token) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (token)
40
+ this.token = token;
41
+ let session = yield this.me();
42
+ this.session = session;
43
+ });
44
+ }
45
+ me() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const res = yield axios.get(this.baseURL + '/me', {
48
+ headers: {
49
+ Authorization: `Bearer ${this.token}`,
50
+ },
51
+ });
52
+ let session;
53
+ if (res.status === 200) {
54
+ session = new Session(res.data.id, this.token);
55
+ session.__load(res.data);
56
+ return session;
57
+ }
58
+ else if (res.status === 401) {
59
+ throw new Error('Not logged in');
60
+ }
61
+ else {
62
+ throw new Error('Error fetching session');
63
+ }
64
+ });
65
+ }
66
+ update_settings(settings) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const res = yield axios.post(this.baseURL + '/me/update_settings', {
69
+ privacy: settings.preferences.privacy,
70
+ appearence: settings.preferences.appearance
71
+ }, {
72
+ headers: {
73
+ Authorization: `Bearer ${this.token}`,
74
+ },
75
+ });
76
+ if (res.status == 200) {
77
+ yield this.refresh();
78
+ return;
79
+ }
80
+ else if (res.status == 401) {
81
+ throw new Error('Not logged in');
82
+ }
83
+ else {
84
+ throw new Error('Error updating settings');
85
+ }
86
+ });
87
+ }
88
+ /*************************************/
89
+ getUser(name) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const res = yield axios.get(this.baseURL + '/users/' + name, {
92
+ headers: {
93
+ Authorization: `Bearer ${this.token}`,
94
+ },
95
+ });
96
+ let user;
97
+ if (res.status === 200) {
98
+ user = new User(res.data.id, this.token, this.baseURL + '/users/' + name);
99
+ user.__load(res.data);
100
+ return user;
101
+ }
102
+ else if (res.status === 403) {
103
+ throw new Error('User is private');
104
+ }
105
+ else if (res.status === 404) {
106
+ throw new Error('User not found');
107
+ }
108
+ else {
109
+ throw new Error('Error fetching user');
110
+ }
111
+ });
112
+ }
113
+ }
@@ -0,0 +1,14 @@
1
+ import type { Profile, ProfileSettings } from "./types/profiles";
2
+ export declare class Session {
3
+ readonly id: string;
4
+ readonly token: string;
5
+ profile: Profile;
6
+ settings: ProfileSettings;
7
+ inbox: {};
8
+ constructor(id: string, token: string);
9
+ __load(data: {
10
+ profile?: Profile;
11
+ settings?: ProfileSettings;
12
+ inbox?: {};
13
+ }): void;
14
+ }
@@ -0,0 +1,18 @@
1
+ export class Session {
2
+ constructor(id, token) {
3
+ this.profile = {};
4
+ this.settings = {};
5
+ this.inbox = {};
6
+ this.id = id;
7
+ this.token = token;
8
+ }
9
+ __load(data) {
10
+ if (data.profile)
11
+ this.profile = data.profile;
12
+ if (data.settings)
13
+ this.settings = data.settings;
14
+ if (data.inbox)
15
+ this.inbox = data.inbox;
16
+ }
17
+ }
18
+ ;
@@ -0,0 +1,19 @@
1
+ export type Post = {
2
+ id: string;
3
+ author_id: string;
4
+ content: string;
5
+ attachements: string[];
6
+ visibility: number;
7
+ likes: string[];
8
+ reposts: string[];
9
+ comments: string[];
10
+ };
11
+ export type Comment = {
12
+ id: string;
13
+ author_id: string;
14
+ parent_id: string;
15
+ post_id: string;
16
+ content: string;
17
+ visibility: number;
18
+ likes: string[];
19
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ export type Profile = {
2
+ id: string;
3
+ name: string;
4
+ display_name: string | null;
5
+ creation_date: string;
6
+ update_date: string;
7
+ followers: string[];
8
+ following: string[];
9
+ status: string | null;
10
+ birthday: string | null;
11
+ pronouns: string | null;
12
+ account_type: string | null;
13
+ level: number;
14
+ };
15
+ export type Settings = {
16
+ id: string;
17
+ privacy: {
18
+ profile_visibility: string;
19
+ birthday_visibility: string;
20
+ status_visibility: string;
21
+ dms: string;
22
+ };
23
+ appearance: {
24
+ global_theme: string;
25
+ };
26
+ };
27
+ export type ProfileSettings = {
28
+ id: string;
29
+ blocklist: string[];
30
+ pending: {
31
+ children: string[];
32
+ followers: string[];
33
+ };
34
+ friends: string[];
35
+ children: string[];
36
+ parent: string | null;
37
+ preferences: Settings;
38
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { Profile } from "./types/profiles";
2
+ export declare class User {
3
+ private readonly __token?;
4
+ private readonly __url?;
5
+ id: string;
6
+ name: string;
7
+ display_name: string | null;
8
+ creation_date: string;
9
+ update_date: string;
10
+ followers: string[];
11
+ following: string[];
12
+ status: string | null;
13
+ birthday: string | null;
14
+ pronouns: string | null;
15
+ account_type: string | null;
16
+ level: number;
17
+ constructor(id: string, __token?: string, __url?: string);
18
+ __load(data: Profile): void;
19
+ follow(): Promise<void>;
20
+ unfollow(): Promise<void>;
21
+ block(): Promise<void>;
22
+ unblock(): Promise<void>;
23
+ }
@@ -0,0 +1,128 @@
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 axios from "axios";
11
+ export class User {
12
+ constructor(id, __token, __url) {
13
+ this.name = '';
14
+ this.display_name = null;
15
+ this.creation_date = '1970-01-01T00:00:00Z';
16
+ this.update_date = '1970-01-01T00:00:00Z';
17
+ this.followers = [];
18
+ this.following = [];
19
+ this.status = null;
20
+ this.birthday = null;
21
+ this.pronouns = null;
22
+ this.account_type = null;
23
+ this.level = 0;
24
+ this.id = id;
25
+ this.__token = __token;
26
+ this.__url = __url;
27
+ }
28
+ __load(data) {
29
+ this.name = data.name;
30
+ this.display_name = data.display_name;
31
+ this.creation_date = data.creation_date;
32
+ this.update_date = data.update_date;
33
+ this.followers = data.followers;
34
+ this.following = data.following;
35
+ this.status = data.status;
36
+ this.birthday = data.birthday;
37
+ this.pronouns = data.pronouns;
38
+ this.account_type = data.account_type;
39
+ this.level = data.level;
40
+ }
41
+ follow() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const res = yield axios.post(this.__url + `/follow`, {}, {
44
+ headers: {
45
+ Authorization: `Bearer ${this.__token}`,
46
+ },
47
+ });
48
+ if (res.status == 200 || res.status == 202 || res.status == 204) {
49
+ return;
50
+ }
51
+ else if (res.status == 401) {
52
+ throw new Error('Not logged in');
53
+ }
54
+ else if (res.status == 403) {
55
+ throw new Error('Private account');
56
+ }
57
+ else if (res.status == 404) {
58
+ throw new Error('User not found');
59
+ }
60
+ else {
61
+ throw new Error('Error following user');
62
+ }
63
+ });
64
+ }
65
+ unfollow() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const res = yield axios.post(this.__url + `/unfollow`, {}, {
68
+ headers: {
69
+ Authorization: `Bearer ${this.__token}`,
70
+ },
71
+ });
72
+ if (res.status == 200 || res.status == 204) {
73
+ return;
74
+ }
75
+ else if (res.status == 401) {
76
+ throw new Error('Not logged in');
77
+ }
78
+ else if (res.status == 404) {
79
+ throw new Error('User not found');
80
+ }
81
+ else {
82
+ throw new Error('Error unfollowing user');
83
+ }
84
+ });
85
+ }
86
+ block() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const res = yield axios.post(this.__url + `/block`, {}, {
89
+ headers: {
90
+ Authorization: `Bearer ${this.__token}`,
91
+ },
92
+ });
93
+ if (res.status == 200 || res.status == 204) {
94
+ return;
95
+ }
96
+ else if (res.status == 401) {
97
+ throw new Error('Not logged in');
98
+ }
99
+ else if (res.status == 404) {
100
+ throw new Error('User not found');
101
+ }
102
+ else {
103
+ throw new Error('Error blocking user');
104
+ }
105
+ });
106
+ }
107
+ unblock() {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const res = yield axios.post(this.__url + `/unblock`, {}, {
110
+ headers: {
111
+ Authorization: `Bearer ${this.__token}`,
112
+ },
113
+ });
114
+ if (res.status == 200 || res.status == 204) {
115
+ return;
116
+ }
117
+ else if (res.status == 401) {
118
+ throw new Error('Not logged in');
119
+ }
120
+ else if (res.status == 404) {
121
+ throw new Error('User not found');
122
+ }
123
+ else {
124
+ throw new Error('Error blocking user');
125
+ }
126
+ });
127
+ }
128
+ }
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "beamsocial",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "API-wrapper pour Beam",
6
6
  "main": "index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./lib/index.js"
10
+ }
11
+ },
7
12
  "scripts": {
8
- "clean": "rm -rf ./dist",
9
- "build": "tsc && cp package.json dist/ && cp README.md dist/ && cp LICENSE dist/"
13
+ "clean": "rm -rf ./lib",
14
+ "build": "tsc "
10
15
  },
11
16
  "files": [
12
- "dist"
17
+ "lib"
13
18
  ],
14
19
  "repository": {
15
20
  "type": "git",