@armoyu/core 1.0.0 → 1.0.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.
Files changed (81) hide show
  1. package/dist/api/ApiClient.d.ts +49 -11
  2. package/dist/api/ApiClient.js +137 -33
  3. package/dist/api/ArmoyuApi.d.ts +38 -0
  4. package/dist/api/ArmoyuApi.js +66 -0
  5. package/dist/armoyu-core.bundle.js +1 -0
  6. package/dist/index.d.ts +11 -1
  7. package/dist/index.js +9 -2
  8. package/dist/models/auth/User.js +17 -22
  9. package/dist/models/core/Rule.d.ts +23 -0
  10. package/dist/models/core/Rule.js +39 -0
  11. package/dist/models/index.d.ts +1 -0
  12. package/dist/models/index.js +1 -0
  13. package/dist/models/social/Post.js +15 -15
  14. package/dist/services/AuthService.d.ts +11 -10
  15. package/dist/services/AuthService.js +56 -27
  16. package/dist/services/BaseService.d.ts +10 -0
  17. package/dist/services/BaseService.js +27 -0
  18. package/dist/services/BlogService.d.ts +16 -0
  19. package/dist/services/BlogService.js +54 -0
  20. package/dist/services/BotService.d.ts +28 -0
  21. package/dist/services/BotService.js +92 -0
  22. package/dist/services/ForumService.d.ts +19 -0
  23. package/dist/services/ForumService.js +64 -0
  24. package/dist/services/RuleService.d.ts +28 -0
  25. package/dist/services/RuleService.js +90 -0
  26. package/dist/services/ShopService.d.ts +20 -0
  27. package/dist/services/ShopService.js +53 -0
  28. package/dist/services/SocialService.d.ts +8 -7
  29. package/dist/services/SocialService.js +26 -21
  30. package/dist/services/SupportService.d.ts +16 -0
  31. package/dist/services/SupportService.js +54 -0
  32. package/dist/services/UserService.d.ts +12 -7
  33. package/dist/services/UserService.js +35 -18
  34. package/package.json +27 -21
  35. package/src/api/ApiClient.ts +0 -57
  36. package/src/index.ts +0 -24
  37. package/src/models/auth/Role.ts +0 -26
  38. package/src/models/auth/Session.ts +0 -50
  39. package/src/models/auth/User.ts +0 -111
  40. package/src/models/community/Classroom.ts +0 -34
  41. package/src/models/community/Event.ts +0 -32
  42. package/src/models/community/Faculty.ts +0 -30
  43. package/src/models/community/Forum.ts +0 -42
  44. package/src/models/community/Giveaway.ts +0 -39
  45. package/src/models/community/Group.ts +0 -78
  46. package/src/models/community/School.ts +0 -51
  47. package/src/models/community/SchoolTeam.ts +0 -49
  48. package/src/models/community/Station.ts +0 -145
  49. package/src/models/community/Survey.ts +0 -53
  50. package/src/models/community/SurveyAnswer.ts +0 -26
  51. package/src/models/community/Team.ts +0 -24
  52. package/src/models/community/Workplace.ts +0 -32
  53. package/src/models/content/Game.ts +0 -39
  54. package/src/models/content/Media.ts +0 -30
  55. package/src/models/content/Mod.ts +0 -38
  56. package/src/models/content/News.ts +0 -43
  57. package/src/models/content/Project.ts +0 -49
  58. package/src/models/core/PlatformStats.ts +0 -74
  59. package/src/models/core/SystemSettings.ts +0 -59
  60. package/src/models/index.ts +0 -37
  61. package/src/models/shop/CartItem.ts +0 -31
  62. package/src/models/shop/Order.ts +0 -48
  63. package/src/models/shop/Product.ts +0 -61
  64. package/src/models/social/Chat.ts +0 -47
  65. package/src/models/social/ChatMessage.ts +0 -30
  66. package/src/models/social/Comment.ts +0 -38
  67. package/src/models/social/Group.ts +0 -63
  68. package/src/models/social/Leaderboard.ts +0 -57
  69. package/src/models/social/Note.ts +0 -28
  70. package/src/models/social/Notification.ts +0 -99
  71. package/src/models/social/NotificationSender.ts +0 -36
  72. package/src/models/social/Post.ts +0 -75
  73. package/src/models/social/Story.ts +0 -30
  74. package/src/models/social/SupportTicket.ts +0 -38
  75. package/src/models/store/StoreItem.ts +0 -32
  76. package/src/services/AuthService.ts +0 -91
  77. package/src/services/SocialService.ts +0 -92
  78. package/src/services/SocketService.ts +0 -112
  79. package/src/services/UserService.ts +0 -69
  80. package/src/types/stats.ts +0 -17
  81. package/tsconfig.json +0 -16
@@ -65,32 +65,27 @@ class User {
65
65
  */
66
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
67
  static fromJSON(json) {
68
+ const avatarData = json.avatar || {};
69
+ const bannerData = json.banner || {};
70
+ const detailInfo = json.detailInfo || {};
71
+ const userRole = json.userRole || {};
68
72
  return new User({
69
- id: json.id || json.id_user || '',
70
- username: json.username || '',
71
- displayName: json.displayName || json.name || json.username || '',
72
- avatar: json.avatar || json.avatar_url || '',
73
- banner: json.banner || json.banner_url || 'https://images.unsplash.com/photo-1614680376593-902f74cf0d41?q=80&w=2574&auto=format&fit=crop',
74
- bio: json.bio || '',
75
- role: json.role ? Role_1.Role.fromJSON(json.role) : null,
76
- verified: json.verified || false,
77
- level: json.level || json.user_level || 1,
78
- xp: json.xp || json.experience || 0,
79
- popScore: json.popScore || 0,
80
- groups: json.groups || [],
73
+ id: String(json.owner_ID || json.playerID || json.id || json.id_user || json.user_id || ''),
74
+ username: json.username || json.user_name || json.owner_username || json.oyuncu_ad || '',
75
+ displayName: json.displayname || json.owner_displayname || json.displayName || json.user_displayname || json.name || json.username || '',
76
+ avatar: typeof avatarData === 'object' ? (avatarData.media_URL || avatarData.media_minURL || avatarData.media_bigURL || '') : avatarData,
77
+ banner: typeof bannerData === 'object' ? (bannerData.media_URL || bannerData.media_bigURL || bannerData.media_minURL || '') : bannerData,
78
+ bio: detailInfo.about || json.bio || json.oyuncu_bio || '',
79
+ role: userRole.roleName ? Role_1.Role.fromJSON({ name: userRole.roleName, color: userRole.roleColor }) : (json.role ? Role_1.Role.fromJSON(json.role) : null),
80
+ verified: json.verified || (json.oyuncu_onay === 1) || false,
81
+ level: Number(json.level || json.oyuncu_seviye || 1),
82
+ xp: Number(json.levelXP || json.xp || json.user_xp || 0),
83
+ popScore: Number(json.popScore || json.user_popscore || 0),
84
+ groups: json.groups || json.user_groups || [],
81
85
  friends: Array.isArray(json.friends) ? json.friends.map((f) => {
82
- // Shallow conversion to avoid infinite recursion
83
86
  if (f instanceof User)
84
87
  return f;
85
- return new User({
86
- id: f.id || f.id_user || '',
87
- username: f.username || '',
88
- displayName: f.displayName || f.name || f.username || '',
89
- avatar: f.avatar || f.avatar_url || '',
90
- role: f.role ? Role_1.Role.fromJSON(f.role) : null,
91
- verified: f.verified || false,
92
- level: f.level || 1
93
- });
88
+ return User.fromJSON(f);
94
89
  }) : [],
95
90
  });
96
91
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Represents a Platform Rule (Kural).
3
+ */
4
+ export declare class Rule {
5
+ id: number;
6
+ text: string;
7
+ penalty: string;
8
+ createdAt: string;
9
+ subArticle: string | null;
10
+ constructor(data: Partial<Rule>);
11
+ /**
12
+ * Instantiates a Rule object from a JSON object.
13
+ * Handles both clean fields and raw ARMOYU API keys.
14
+ */
15
+ static fromJSON(json: any): Rule;
16
+ toJSON(): {
17
+ id: number;
18
+ text: string;
19
+ penalty: string;
20
+ createdAt: string;
21
+ subArticle: string | null;
22
+ };
23
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Rule = void 0;
4
+ /**
5
+ * Represents a Platform Rule (Kural).
6
+ */
7
+ class Rule {
8
+ constructor(data) {
9
+ this.id = 0;
10
+ this.text = '';
11
+ this.penalty = '';
12
+ this.createdAt = '';
13
+ this.subArticle = null;
14
+ Object.assign(this, data);
15
+ }
16
+ /**
17
+ * Instantiates a Rule object from a JSON object.
18
+ * Handles both clean fields and raw ARMOYU API keys.
19
+ */
20
+ static fromJSON(json) {
21
+ return new Rule({
22
+ id: json.id || json.kuralid || 0,
23
+ text: json.text || json.kuralicerik || '',
24
+ penalty: json.penalty || json.cezabaslangic || '',
25
+ createdAt: json.createdAt || json.cezakoyulmatarihi || '',
26
+ subArticle: json.subArticle || json.kuralaltmadde || null
27
+ });
28
+ }
29
+ toJSON() {
30
+ return {
31
+ id: this.id,
32
+ text: this.text,
33
+ penalty: this.penalty,
34
+ createdAt: this.createdAt,
35
+ subArticle: this.subArticle
36
+ };
37
+ }
38
+ }
39
+ exports.Rule = Rule;
@@ -29,6 +29,7 @@ export * from './shop/Order';
29
29
  export * from './shop/CartItem';
30
30
  export * from './core/PlatformStats';
31
31
  export * from './core/SystemSettings';
32
+ export * from './core/Rule';
32
33
  export * from './social/SupportTicket';
33
34
  export * from './content/Game';
34
35
  export * from './content/Media';
@@ -45,6 +45,7 @@ __exportStar(require("./shop/Order"), exports);
45
45
  __exportStar(require("./shop/CartItem"), exports);
46
46
  __exportStar(require("./core/PlatformStats"), exports);
47
47
  __exportStar(require("./core/SystemSettings"), exports);
48
+ __exportStar(require("./core/Rule"), exports);
48
49
  __exportStar(require("./social/SupportTicket"), exports);
49
50
  __exportStar(require("./content/Game"), exports);
50
51
  __exportStar(require("./content/Media"), exports);
@@ -27,24 +27,24 @@ class Post {
27
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
28
  static fromJSON(json) {
29
29
  return new Post({
30
- id: json.id || '',
31
- author: json.author ? User_1.User.fromJSON(json.author) : null,
32
- content: json.content || '',
33
- media: Array.isArray(json.media) ? json.media : (json.imageUrl ? [{ type: 'image', url: json.imageUrl }] : []),
34
- createdAt: json.createdAt || json.created_at || '',
35
- stats: json.stats || {
36
- likes: json.likeCount || 0,
37
- comments: json.commentCount || 0,
38
- reposts: json.repostCount || 0,
39
- shares: json.shareCount || 0,
30
+ id: String(json.postID || json.id || ''),
31
+ author: (json.owner || json.author) ? User_1.User.fromJSON(json.owner || json.author) : null,
32
+ content: json.paylasimicerik || json.content || '',
33
+ media: Array.isArray(json.paylasimfoto) ? json.paylasimfoto.map((f) => ({ type: 'image', url: f.fotourl || f.fotoufakurl })) : (Array.isArray(json.media) ? json.media : []),
34
+ createdAt: json.paylasimzaman || json.createdAt || json.created_at || '',
35
+ stats: {
36
+ likes: Number(json.begenisay || 0),
37
+ comments: Number(json.yorumsay || 0),
38
+ reposts: Number(json.repostsay || 0),
39
+ shares: Number(json.sikayetsay || 0),
40
40
  },
41
41
  hashtags: json.hashtags || [],
42
- likeList: Array.isArray(json.likeList) ? json.likeList.map(User_1.User.fromJSON) : [],
43
- repostList: Array.isArray(json.repostList) ? json.repostList.map(User_1.User.fromJSON) : [],
44
- commentList: Array.isArray(json.commentList) ? json.commentList.map((c) => ({
42
+ likeList: Array.isArray(json.paylasimilkucbegenen) ? json.paylasimilkucbegenen.map(User_1.User.fromJSON) : (Array.isArray(json.likeList) ? json.likeList.map(User_1.User.fromJSON) : []),
43
+ commentList: Array.isArray(json.ilkucyorum) ? json.ilkucyorum.map((c) => ({
45
44
  ...c,
46
- author: User_1.User.fromJSON(c.author),
47
- replies: Array.isArray(c.replies) ? c.replies.map((r) => ({ ...r, author: User_1.User.fromJSON(r.author) })) : []
45
+ author: User_1.User.fromJSON(c),
46
+ content: c.yorumcuicerik,
47
+ createdAt: c.yorumcuzaman
48
48
  })) : [],
49
49
  repostOf: json.repostOf ? Post.fromJSON(json.repostOf) : undefined
50
50
  });
@@ -1,30 +1,31 @@
1
1
  import { User } from '../models/auth/User';
2
2
  import { Session } from '../models/auth/Session';
3
- export declare class AuthService {
4
- private static currentUser;
5
- private static session;
3
+ import { BaseService } from './BaseService';
4
+ export declare class AuthService extends BaseService {
5
+ private currentUser;
6
+ private session;
6
7
  /**
7
8
  * Authenticate a user with username and password.
8
9
  */
9
- static login(username: string, password: string): Promise<{
10
+ login(username: string, password: string): Promise<{
10
11
  user: User;
11
12
  session: Session;
12
13
  }>;
13
14
  /**
14
15
  * Register a new user.
15
16
  */
16
- static register(data: any): Promise<{
17
+ register(data: any): Promise<{
17
18
  user: User;
18
19
  }>;
19
20
  /**
20
21
  * Logout the current user.
21
22
  */
22
- static logout(): Promise<void>;
23
+ logout(): Promise<void>;
23
24
  /**
24
25
  * Get the currently authenticated user's profile.
25
26
  */
26
- static me(): Promise<User | null>;
27
- static getCurrentUser(): User | null;
28
- static getSession(): Session | null;
29
- static isAuthenticated(): boolean;
27
+ me(): Promise<User | null>;
28
+ getCurrentUser(): User | null;
29
+ getSession(): Session | null;
30
+ isAuthenticated(): boolean;
30
31
  }
@@ -1,24 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuthService = void 0;
4
- const ApiClient_1 = require("../api/ApiClient");
5
4
  const User_1 = require("../models/auth/User");
6
5
  const Session_1 = require("../models/auth/Session");
7
- class AuthService {
6
+ const BaseService_1 = require("./BaseService");
7
+ class AuthService extends BaseService_1.BaseService {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.currentUser = null;
11
+ this.session = null;
12
+ }
8
13
  /**
9
14
  * Authenticate a user with username and password.
10
15
  */
11
- static async login(username, password) {
16
+ async login(username, password) {
12
17
  try {
13
- const response = await ApiClient_1.ApiClient.post('/auth/login', {
14
- username,
15
- password
18
+ const formData = new FormData();
19
+ formData.append('username', username);
20
+ formData.append('password', password);
21
+ const response = await this.client.post('/0/0/0', formData);
22
+ // Handle raw response if it's still a string (though ApiClient should have parsed it)
23
+ const data = typeof response === 'string' ? JSON.parse(response) : response;
24
+ const icerik = this.handleResponse(data);
25
+ // ARMOYU Login logic: Token is inside the 'aciklama' field (as a string or object)
26
+ let token = '';
27
+ if (typeof data.aciklama === 'string') {
28
+ // Only treat as token if it doesn't contain spaces/special characters (not a sentence like "Giriş Başarılı")
29
+ const isStrictToken = /^[a-zA-Z0-9.\-_=]+$/.test(data.aciklama);
30
+ if (isStrictToken) {
31
+ token = data.aciklama;
32
+ }
33
+ }
34
+ else if (data.aciklama && typeof data.aciklama === 'object') {
35
+ token = data.aciklama.token || data.aciklama.session_token || '';
36
+ }
37
+ this.currentUser = User_1.User.fromJSON(icerik);
38
+ this.session = new Session_1.Session({
39
+ user: this.currentUser,
40
+ token: token || (icerik === null || icerik === void 0 ? void 0 : icerik.token) || (icerik === null || icerik === void 0 ? void 0 : icerik.session_token) || null
16
41
  });
17
- this.currentUser = User_1.User.fromJSON(response.user);
18
- this.session = Session_1.Session.fromJSON(response.session);
19
- // Store token in localStorage if available
20
- if (typeof window !== 'undefined' && this.session.token) {
21
- localStorage.setItem('armoyu_token', this.session.token);
42
+ // Update client token for all subsequent requests
43
+ if (this.session.token) {
44
+ this.client.setToken(this.session.token);
45
+ // Store token in localStorage if available (standard browser behavior)
46
+ if (typeof window !== 'undefined') {
47
+ localStorage.setItem('armoyu_token', this.session.token);
48
+ }
22
49
  }
23
50
  return { user: this.currentUser, session: this.session };
24
51
  }
@@ -30,10 +57,11 @@ class AuthService {
30
57
  /**
31
58
  * Register a new user.
32
59
  */
33
- static async register(data) {
60
+ async register(data) {
34
61
  try {
35
- const response = await ApiClient_1.ApiClient.post('/auth/register', data);
36
- return { user: User_1.User.fromJSON(response.user) };
62
+ const response = await this.client.post('/auth/register', data);
63
+ const icerik = this.handleResponse(response);
64
+ return { user: User_1.User.fromJSON(icerik.user) };
37
65
  }
38
66
  catch (error) {
39
67
  console.error('[AuthService] Registration failed:', error);
@@ -43,9 +71,9 @@ class AuthService {
43
71
  /**
44
72
  * Logout the current user.
45
73
  */
46
- static async logout() {
74
+ async logout() {
47
75
  try {
48
- await ApiClient_1.ApiClient.post('/auth/logout', {});
76
+ await this.client.post('/auth/logout', {});
49
77
  }
50
78
  catch (error) {
51
79
  console.error('[AuthService] Logout API call failed:', error);
@@ -53,6 +81,7 @@ class AuthService {
53
81
  finally {
54
82
  this.currentUser = null;
55
83
  this.session = null;
84
+ this.client.setToken(null);
56
85
  if (typeof window !== 'undefined') {
57
86
  localStorage.removeItem('armoyu_token');
58
87
  }
@@ -61,28 +90,28 @@ class AuthService {
61
90
  /**
62
91
  * Get the currently authenticated user's profile.
63
92
  */
64
- static async me() {
93
+ async me() {
65
94
  try {
66
- if (this.currentUser)
67
- return this.currentUser;
68
- const response = await ApiClient_1.ApiClient.get('/auth/me');
69
- this.currentUser = User_1.User.fromJSON(response.user);
95
+ const response = await this.client.get('/auth/me');
96
+ const icerik = this.handleResponse(response);
97
+ // Robust mapping: handle direct user object or nested { user: {...} }
98
+ const userData = icerik && (icerik.user || icerik);
99
+ this.currentUser = userData ? User_1.User.fromJSON(userData) : null;
70
100
  return this.currentUser;
71
101
  }
72
102
  catch (error) {
103
+ this.currentUser = null;
73
104
  return null;
74
105
  }
75
106
  }
76
- static getCurrentUser() {
107
+ getCurrentUser() {
77
108
  return this.currentUser;
78
109
  }
79
- static getSession() {
110
+ getSession() {
80
111
  return this.session;
81
112
  }
82
- static isAuthenticated() {
83
- return !!this.currentUser;
113
+ isAuthenticated() {
114
+ return !!this.currentUser || !!this.client;
84
115
  }
85
116
  }
86
117
  exports.AuthService = AuthService;
87
- AuthService.currentUser = null;
88
- AuthService.session = null;
@@ -0,0 +1,10 @@
1
+ import { ApiClient } from '../api/ApiClient';
2
+ export declare abstract class BaseService {
3
+ protected client: ApiClient;
4
+ constructor(client: ApiClient);
5
+ /**
6
+ * Universal response handler for ARMOYU standard responses.
7
+ * Extracts 'icerik' if 'durum' is 1, otherwise throws error with 'aciklama'.
8
+ */
9
+ protected handleResponse<T>(response: any): T;
10
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseService = void 0;
4
+ class BaseService {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ /**
9
+ * Universal response handler for ARMOYU standard responses.
10
+ * Extracts 'icerik' if 'durum' is 1, otherwise throws error with 'aciklama'.
11
+ */
12
+ handleResponse(response) {
13
+ // If it's a standard response object
14
+ if (response && typeof response === 'object' && 'durum' in response) {
15
+ const standardResponse = response;
16
+ // Relaxed check: accept numeric or string "1" for success
17
+ if (Number(standardResponse.durum) === 1) {
18
+ return standardResponse.icerik;
19
+ }
20
+ // If durum is not 1, throw the API error message
21
+ throw new Error(standardResponse.aciklama || 'API Execution Error');
22
+ }
23
+ // Fallback for non-standard responses
24
+ return response;
25
+ }
26
+ }
27
+ exports.BaseService = BaseService;
@@ -0,0 +1,16 @@
1
+ import { News } from '../models/content/News';
2
+ import { BaseService } from './BaseService';
3
+ export declare class BlogService extends BaseService {
4
+ /**
5
+ * Get all news articles.
6
+ */
7
+ getNews(page?: number, limit?: number): Promise<News[]>;
8
+ /**
9
+ * Get a single news article by slug.
10
+ */
11
+ getNewsBySlug(slug: string): Promise<News | null>;
12
+ /**
13
+ * Search news articles.
14
+ */
15
+ searchNews(query: string): Promise<News[]>;
16
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlogService = void 0;
4
+ const News_1 = require("../models/content/News");
5
+ const BaseService_1 = require("./BaseService");
6
+ class BlogService extends BaseService_1.BaseService {
7
+ /**
8
+ * Get all news articles.
9
+ */
10
+ async getNews(page = 1, limit = 10) {
11
+ try {
12
+ const response = await this.client.get('/content/news', {
13
+ params: { page, limit }
14
+ });
15
+ const icerik = this.handleResponse(response);
16
+ return icerik.news.map(n => News_1.News.fromJSON(n));
17
+ }
18
+ catch (error) {
19
+ console.error('[BlogService] Failed to fetch news:', error);
20
+ return [];
21
+ }
22
+ }
23
+ /**
24
+ * Get a single news article by slug.
25
+ */
26
+ async getNewsBySlug(slug) {
27
+ try {
28
+ const response = await this.client.get(`/content/news/${slug}`);
29
+ const icerik = this.handleResponse(response);
30
+ return News_1.News.fromJSON(icerik);
31
+ }
32
+ catch (error) {
33
+ console.error(`[BlogService] Failed to fetch news article ${slug}:`, error);
34
+ return null;
35
+ }
36
+ }
37
+ /**
38
+ * Search news articles.
39
+ */
40
+ async searchNews(query) {
41
+ try {
42
+ const response = await this.client.get('/content/news/search', {
43
+ params: { q: query }
44
+ });
45
+ const icerik = this.handleResponse(response);
46
+ return icerik.news.map(n => News_1.News.fromJSON(n));
47
+ }
48
+ catch (error) {
49
+ console.error('[BlogService] News search failed:', error);
50
+ return [];
51
+ }
52
+ }
53
+ }
54
+ exports.BlogService = BlogService;
@@ -0,0 +1,28 @@
1
+ import { BaseService } from './BaseService';
2
+ import { Rule } from '../models/core/Rule';
3
+ import { HttpMethod } from '../api/ApiClient';
4
+ /**
5
+ * Service for handling ARMOYU Bot-related API interactions.
6
+ */
7
+ export declare class BotService extends BaseService {
8
+ /**
9
+ * Universal method to call bot endpoints with standardized prefix.
10
+ */
11
+ call<T>(path: string, method?: HttpMethod, body?: any): Promise<T>;
12
+ /**
13
+ * Fetches the list of rules for a specific bot.
14
+ */
15
+ getRules(botId?: string): Promise<Rule[]>;
16
+ /**
17
+ * Create a new rule for a specific bot.
18
+ */
19
+ createRule(botId: string | undefined, text: string, penalty?: string): Promise<Rule>;
20
+ /**
21
+ * Update an existing rule.
22
+ */
23
+ updateRule(botId: string | undefined, ruleId: number, data: Partial<Rule>): Promise<Rule>;
24
+ /**
25
+ * Delete a rule by its ID.
26
+ */
27
+ deleteRule(botId: string | undefined, ruleId: number): Promise<boolean>;
28
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BotService = void 0;
4
+ const BaseService_1 = require("./BaseService");
5
+ const Rule_1 = require("../models/core/Rule");
6
+ const ApiClient_1 = require("../api/ApiClient");
7
+ /**
8
+ * Service for handling ARMOYU Bot-related API interactions.
9
+ */
10
+ class BotService extends BaseService_1.BaseService {
11
+ /**
12
+ * Universal method to call bot endpoints with standardized prefix.
13
+ */
14
+ async call(path, method = ApiClient_1.HttpMethod.GET, body) {
15
+ const normalizedPath = path.startsWith('/') ? path : '/' + path;
16
+ // Prefix required for ARMOYU Bot API structure
17
+ const endpoint = `/botlar%apikey%/0/0${normalizedPath}`;
18
+ try {
19
+ switch (method) {
20
+ case ApiClient_1.HttpMethod.GET:
21
+ return await this.client.get(endpoint);
22
+ case ApiClient_1.HttpMethod.POST:
23
+ return await this.client.post(endpoint, body);
24
+ case ApiClient_1.HttpMethod.PUT:
25
+ return await this.client.put(endpoint, body);
26
+ case ApiClient_1.HttpMethod.PATCH:
27
+ return await this.client.patch(endpoint, body);
28
+ case ApiClient_1.HttpMethod.DELETE:
29
+ return await this.client.delete(endpoint);
30
+ default:
31
+ return await this.client.get(endpoint);
32
+ }
33
+ }
34
+ catch (error) {
35
+ console.error(`[BotService] Request to ${path} failed:`, error);
36
+ throw error;
37
+ }
38
+ }
39
+ /**
40
+ * Fetches the list of rules for a specific bot.
41
+ */
42
+ async getRules(botId = '0') {
43
+ try {
44
+ // The API expects a POST request for fetching rules in this context
45
+ const response = await this.call(`/kurallar/${botId}`, ApiClient_1.HttpMethod.POST);
46
+ const rulesData = this.handleResponse(response);
47
+ if (Array.isArray(rulesData)) {
48
+ return rulesData.map((r) => Rule_1.Rule.fromJSON(r));
49
+ }
50
+ return [];
51
+ }
52
+ catch (error) {
53
+ console.error('[BotService] getRules failed:', error);
54
+ return [];
55
+ }
56
+ }
57
+ /**
58
+ * Create a new rule for a specific bot.
59
+ */
60
+ async createRule(botId = '0', text, penalty = '') {
61
+ const body = {
62
+ kuralicerik: text,
63
+ cezabaslangic: penalty
64
+ };
65
+ const response = await this.call(`/kurallar/${botId}/ekle`, ApiClient_1.HttpMethod.POST, body);
66
+ const result = this.handleResponse(response);
67
+ return Rule_1.Rule.fromJSON(result);
68
+ }
69
+ /**
70
+ * Update an existing rule.
71
+ */
72
+ async updateRule(botId = '0', ruleId, data) {
73
+ const body = {};
74
+ if (data.text)
75
+ body.kuralicerik = data.text;
76
+ if (data.penalty)
77
+ body.cezabaslangic = data.penalty;
78
+ const response = await this.call(`/kurallar/${botId}/duzenle/${ruleId}`, ApiClient_1.HttpMethod.POST, body);
79
+ const result = this.handleResponse(response);
80
+ return Rule_1.Rule.fromJSON(result);
81
+ }
82
+ /**
83
+ * Delete a rule by its ID.
84
+ */
85
+ async deleteRule(botId = '0', ruleId) {
86
+ const response = await this.call(`/kurallar/${botId}/sil/${ruleId}`, ApiClient_1.HttpMethod.POST);
87
+ const result = this.handleResponse(response);
88
+ // Return true if operation was successful (handleResponse would throw otherwise)
89
+ return !!result;
90
+ }
91
+ }
92
+ exports.BotService = BotService;
@@ -0,0 +1,19 @@
1
+ import { BaseService } from './BaseService';
2
+ export declare class ForumService extends BaseService {
3
+ /**
4
+ * Get all forum categories.
5
+ */
6
+ getCategories(): Promise<any[]>;
7
+ /**
8
+ * Get topics for a specific category.
9
+ */
10
+ getTopics(categoryId: number, page?: number): Promise<any[]>;
11
+ /**
12
+ * Create a new topic in a category.
13
+ */
14
+ createTopic(categoryId: number, title: string, content: string): Promise<any>;
15
+ /**
16
+ * Delete a topic by its ID.
17
+ */
18
+ deleteTopic(topicId: number): Promise<void>;
19
+ }