@mikoto_zero/minigame-open-mcp 1.0.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/README.md +235 -0
- package/bin/minigame-open-mcp +34 -0
- package/dist/data/leaderboardDocs.d.ts +37 -0
- package/dist/data/leaderboardDocs.d.ts.map +1 -0
- package/dist/data/leaderboardDocs.js +576 -0
- package/dist/data/leaderboardDocs.js.map +1 -0
- package/dist/network/httpClient.d.ts +80 -0
- package/dist/network/httpClient.d.ts.map +1 -0
- package/dist/network/httpClient.js +244 -0
- package/dist/network/httpClient.js.map +1 -0
- package/dist/network/leaderboardApi.d.ts +174 -0
- package/dist/network/leaderboardApi.d.ts.map +1 -0
- package/dist/network/leaderboardApi.js +219 -0
- package/dist/network/leaderboardApi.js.map +1 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +538 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/leaderboardTools.d.ts +56 -0
- package/dist/tools/leaderboardTools.d.ts.map +1 -0
- package/dist/tools/leaderboardTools.js +120 -0
- package/dist/tools/leaderboardTools.js.map +1 -0
- package/dist/utils/cache.d.ts +36 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +90 -0
- package/dist/utils/cache.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client for TapTap API Requests
|
|
3
|
+
* Handles authentication, request signing, headers, and error responses
|
|
4
|
+
*/
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import cryptoJS from 'crypto-js';
|
|
7
|
+
/**
|
|
8
|
+
* Environment configuration
|
|
9
|
+
*/
|
|
10
|
+
export class ApiConfig {
|
|
11
|
+
constructor() {
|
|
12
|
+
// Required environment variables
|
|
13
|
+
this.userToken = process.env.TAPTAP_USER_TOKEN || '';
|
|
14
|
+
this.clientId = process.env.TAPTAP_CLIENT_ID || '';
|
|
15
|
+
this.clientSecret = process.env.TAPTAP_CLIENT_SECRET || '';
|
|
16
|
+
// Optional: default to production
|
|
17
|
+
this.environment = (process.env.TAPTAP_ENV === 'rnd') ? 'rnd' : 'production';
|
|
18
|
+
// Set API base URL based on environment
|
|
19
|
+
this.apiBaseUrl = this.environment === 'production'
|
|
20
|
+
? 'https://agent.tapapis.cn'
|
|
21
|
+
: 'https://agent.api.xdrnd.cn';
|
|
22
|
+
// Validate required environment variables
|
|
23
|
+
this.validateConfig();
|
|
24
|
+
}
|
|
25
|
+
validateConfig() {
|
|
26
|
+
const missing = [];
|
|
27
|
+
if (!this.userToken) {
|
|
28
|
+
missing.push('TAPTAP_USER_TOKEN');
|
|
29
|
+
}
|
|
30
|
+
if (!this.clientId) {
|
|
31
|
+
missing.push('TAPTAP_CLIENT_ID');
|
|
32
|
+
}
|
|
33
|
+
if (!this.clientSecret) {
|
|
34
|
+
missing.push('TAPTAP_CLIENT_SECRET');
|
|
35
|
+
}
|
|
36
|
+
if (missing.length > 0) {
|
|
37
|
+
process.stderr.write(`❌ Missing required environment variables: ${missing.join(', ')}\n`);
|
|
38
|
+
process.stderr.write('Please configure these variables in your MCP server settings.\n');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static getInstance() {
|
|
43
|
+
if (!ApiConfig.instance) {
|
|
44
|
+
ApiConfig.instance = new ApiConfig();
|
|
45
|
+
}
|
|
46
|
+
return ApiConfig.instance;
|
|
47
|
+
}
|
|
48
|
+
isConfigured() {
|
|
49
|
+
return !!(this.userToken && this.clientId && this.clientSecret);
|
|
50
|
+
}
|
|
51
|
+
getConfigStatus() {
|
|
52
|
+
return {
|
|
53
|
+
'TAPTAP_USER_TOKEN': this.userToken ? '✅ 已配置' : '❌ 未配置',
|
|
54
|
+
'TAPTAP_CLIENT_ID': this.clientId ? '✅ 已配置' : '❌ 未配置',
|
|
55
|
+
'TAPTAP_CLIENT_SECRET': this.clientSecret ? '✅ 已配置' : '❌ 未配置',
|
|
56
|
+
'TAPTAP_ENV': `${this.environment} (${this.apiBaseUrl})`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generic HTTP Client for TapTap API
|
|
62
|
+
*/
|
|
63
|
+
export class HttpClient {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.config = ApiConfig.getInstance();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Make a GET request
|
|
69
|
+
*/
|
|
70
|
+
async get(path, options = {}) {
|
|
71
|
+
return this.request('GET', path, options);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Make a POST request
|
|
75
|
+
*/
|
|
76
|
+
async post(path, options = {}) {
|
|
77
|
+
return this.request('POST', path, options);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generic request method with signature
|
|
81
|
+
*/
|
|
82
|
+
async request(method, path, options = {}) {
|
|
83
|
+
// Build full URL with query parameters
|
|
84
|
+
let fullUrl = `${this.config.apiBaseUrl}${path}`;
|
|
85
|
+
let signUrl = new URL(fullUrl).pathname;
|
|
86
|
+
// Add client_id to query params
|
|
87
|
+
const queryParams = new URLSearchParams();
|
|
88
|
+
queryParams.append('client_id', this.config.clientId);
|
|
89
|
+
if (options.params) {
|
|
90
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
91
|
+
queryParams.append(key, value);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
fullUrl += '?' + queryParams.toString();
|
|
95
|
+
signUrl += '?' + queryParams.toString();
|
|
96
|
+
// Prepare request body
|
|
97
|
+
let bodyString = method === 'POST' ? '{}' : '';
|
|
98
|
+
const headers = {
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
'Authorization': `Bearer ${this.config.userToken}`,
|
|
101
|
+
...(options.headers || {})
|
|
102
|
+
};
|
|
103
|
+
if (options.body) {
|
|
104
|
+
if (headers['Content-Type'] === 'application/x-www-form-urlencoded') {
|
|
105
|
+
// Form-encoded body
|
|
106
|
+
const formData = new URLSearchParams();
|
|
107
|
+
Object.entries(options.body).forEach(([key, value]) => {
|
|
108
|
+
if (value !== undefined && value !== null) {
|
|
109
|
+
formData.append(key, String(value));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
bodyString = formData.toString();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// JSON body
|
|
116
|
+
bodyString = JSON.stringify(options.body);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Add timestamp and nonce headers
|
|
120
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
121
|
+
const nonce = this.generateRandomString(8);
|
|
122
|
+
headers['X-Tap-Ts'] = timestamp;
|
|
123
|
+
headers['X-Tap-Nonce'] = nonce;
|
|
124
|
+
// Calculate signature using CLIENT_SECRET
|
|
125
|
+
const signature = this.generateSignature(method, signUrl, headers, bodyString);
|
|
126
|
+
headers['X-Tap-Sign'] = signature;
|
|
127
|
+
// Set up timeout
|
|
128
|
+
const controller = new AbortController();
|
|
129
|
+
const timeout = options.timeout || 30000;
|
|
130
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
131
|
+
try {
|
|
132
|
+
// @ts-ignore - fetch is available in Node.js 18+
|
|
133
|
+
const response = await fetch(fullUrl, {
|
|
134
|
+
method,
|
|
135
|
+
headers,
|
|
136
|
+
body: bodyString || undefined,
|
|
137
|
+
signal: controller.signal
|
|
138
|
+
});
|
|
139
|
+
clearTimeout(timeoutId);
|
|
140
|
+
// Handle non-OK responses
|
|
141
|
+
if (!response.ok) {
|
|
142
|
+
const contentType = response.headers.get('content-type');
|
|
143
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
144
|
+
if (contentType?.includes('application/json')) {
|
|
145
|
+
const errorData = await response.json();
|
|
146
|
+
errorMessage += ` - ${errorData.message || errorData.error || JSON.stringify(errorData)}`;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const errorText = await response.text();
|
|
150
|
+
errorMessage += ` - ${errorText}`;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(errorMessage);
|
|
153
|
+
}
|
|
154
|
+
// Parse response
|
|
155
|
+
const contentType = response.headers.get('content-type');
|
|
156
|
+
if (contentType?.includes('application/json')) {
|
|
157
|
+
const jsonData = await response.json();
|
|
158
|
+
// Handle API response format
|
|
159
|
+
if (jsonData.success === false) {
|
|
160
|
+
throw new Error(jsonData.message || jsonData.error || 'API request failed');
|
|
161
|
+
}
|
|
162
|
+
// Return data field if available, otherwise return full response
|
|
163
|
+
return (jsonData.data !== undefined ? jsonData.data : jsonData);
|
|
164
|
+
}
|
|
165
|
+
// If not JSON, return text
|
|
166
|
+
const text = await response.text();
|
|
167
|
+
return text;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
clearTimeout(timeoutId);
|
|
171
|
+
if (error instanceof Error) {
|
|
172
|
+
if (error.name === 'AbortError') {
|
|
173
|
+
throw new Error(`Request timeout after ${timeout}ms`);
|
|
174
|
+
}
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
throw new Error(`Request failed: ${String(error)}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Generate request signature
|
|
182
|
+
* Format: HMAC-SHA256(method + url + headers + body, CLIENT_SECRET)
|
|
183
|
+
*/
|
|
184
|
+
generateSignature(method, url, headers, body) {
|
|
185
|
+
try {
|
|
186
|
+
const methodPart = method;
|
|
187
|
+
const urlPart = url;
|
|
188
|
+
const headersPart = this.getHeadersPart(headers);
|
|
189
|
+
const bodyPart = body;
|
|
190
|
+
const signParts = `${methodPart}\n${urlPart}\n${headersPart}\n${bodyPart}\n`;
|
|
191
|
+
const hmacResult = cryptoJS.HmacSHA256(signParts, this.config.clientSecret);
|
|
192
|
+
const signatureBase64 = cryptoJS.enc.Base64.stringify(hmacResult);
|
|
193
|
+
return signatureBase64;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw new Error(`Failed to generate signature: ${error instanceof Error ? error.message : String(error)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get headers part for signature
|
|
201
|
+
* Only includes X-Tap-* headers (excluding X-Tap-Sign)
|
|
202
|
+
*/
|
|
203
|
+
getHeadersPart(headers) {
|
|
204
|
+
const headerKeys = [];
|
|
205
|
+
const headerValues = {};
|
|
206
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
207
|
+
const k = key.toLowerCase();
|
|
208
|
+
if (!k.startsWith('x-tap-') || k === 'x-tap-sign') {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
headerKeys.push(k);
|
|
212
|
+
headerValues[k] = value;
|
|
213
|
+
}
|
|
214
|
+
headerKeys.sort();
|
|
215
|
+
const formattedHeaders = headerKeys.map((k) => {
|
|
216
|
+
return `${k}:${headerValues[k]}`;
|
|
217
|
+
});
|
|
218
|
+
return formattedHeaders.join('\n');
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generate random string
|
|
222
|
+
*/
|
|
223
|
+
generateRandomString(length) {
|
|
224
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
225
|
+
let result = '';
|
|
226
|
+
for (let i = 0; i < length; i++) {
|
|
227
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get current environment
|
|
233
|
+
*/
|
|
234
|
+
getEnvironment() {
|
|
235
|
+
return this.config.environment;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get API base URL
|
|
239
|
+
*/
|
|
240
|
+
getBaseUrl() {
|
|
241
|
+
return this.config.apiBaseUrl;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=http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CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACK,oBAAoB,CAAC,MAAc;QACzC,MAAM,KAAK,GAAG,gEAAgE,CAAC;QAC/E,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TapTap Leaderboard Management API
|
|
3
|
+
* Server-side leaderboard operations
|
|
4
|
+
*/
|
|
5
|
+
import { AppCacheInfo } from '../utils/cache.js';
|
|
6
|
+
/**
|
|
7
|
+
* Period types for leaderboard
|
|
8
|
+
*/
|
|
9
|
+
export declare enum PeriodType {
|
|
10
|
+
DAILY = 0,
|
|
11
|
+
WEEKLY = 1,
|
|
12
|
+
MONTHLY = 2,
|
|
13
|
+
ALWAYS = 3,
|
|
14
|
+
CUSTOM = 4
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Score types
|
|
18
|
+
*/
|
|
19
|
+
export declare enum ScoreType {
|
|
20
|
+
INTEGER = 0,
|
|
21
|
+
FLOAT = 1,
|
|
22
|
+
TIME = 2
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Score order
|
|
26
|
+
*/
|
|
27
|
+
export declare enum ScoreOrder {
|
|
28
|
+
ASCENDING = 0,
|
|
29
|
+
DESCENDING = 1,
|
|
30
|
+
NONE = 2
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Calculation types
|
|
34
|
+
*/
|
|
35
|
+
export declare enum CalcType {
|
|
36
|
+
BEST = 0,
|
|
37
|
+
LATEST = 1,
|
|
38
|
+
SUM = 2,
|
|
39
|
+
FIRST = 3
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create leaderboard parameters
|
|
43
|
+
*/
|
|
44
|
+
export interface CreateLeaderboardParams {
|
|
45
|
+
developer_id: number;
|
|
46
|
+
app_id: number;
|
|
47
|
+
title: string;
|
|
48
|
+
period_type: PeriodType;
|
|
49
|
+
score_type: ScoreType;
|
|
50
|
+
score_order: ScoreOrder;
|
|
51
|
+
calc_type: CalcType;
|
|
52
|
+
display_limit?: number;
|
|
53
|
+
period_time?: string;
|
|
54
|
+
score_unit?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create leaderboard response
|
|
58
|
+
*/
|
|
59
|
+
export interface CreateLeaderboardResponse {
|
|
60
|
+
leaderboard_id: string;
|
|
61
|
+
open_id: string;
|
|
62
|
+
title: string;
|
|
63
|
+
default_status: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new leaderboard
|
|
67
|
+
* @param params - Leaderboard creation parameters
|
|
68
|
+
* @returns Created leaderboard information
|
|
69
|
+
*/
|
|
70
|
+
export declare function createLeaderboard(params: CreateLeaderboardParams): Promise<CreateLeaderboardResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* Craft/App item in developer list
|
|
73
|
+
*/
|
|
74
|
+
export interface CraftItem {
|
|
75
|
+
app_id: number;
|
|
76
|
+
app_title: string;
|
|
77
|
+
category?: string;
|
|
78
|
+
is_published?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Developer with crafts list
|
|
82
|
+
*/
|
|
83
|
+
export interface DeveloperCraftList {
|
|
84
|
+
developer_id: number;
|
|
85
|
+
developer_name: string;
|
|
86
|
+
crafts: CraftItem[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Level list response
|
|
90
|
+
*/
|
|
91
|
+
export interface LevelListResponse {
|
|
92
|
+
list: DeveloperCraftList[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get app/level list information for current user
|
|
96
|
+
* Returns all developers and their apps/games
|
|
97
|
+
* @param projectPath - Optional project path for cache lookup
|
|
98
|
+
* @returns App information including developer_id and app_id
|
|
99
|
+
*/
|
|
100
|
+
export declare function getAppInfo(projectPath?: string): Promise<AppCacheInfo>;
|
|
101
|
+
/**
|
|
102
|
+
* Get or fetch app information with automatic caching
|
|
103
|
+
* @param projectPath - Optional project path
|
|
104
|
+
* @returns App information from cache or API
|
|
105
|
+
*/
|
|
106
|
+
export declare function ensureAppInfo(projectPath?: string): Promise<AppCacheInfo>;
|
|
107
|
+
/**
|
|
108
|
+
* Get all developers and apps for selection
|
|
109
|
+
* @returns List of all developers and their apps
|
|
110
|
+
*/
|
|
111
|
+
export declare function getAllDevelopersAndApps(): Promise<LevelListResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Leaderboard item in list
|
|
114
|
+
*/
|
|
115
|
+
export interface LeaderboardItem {
|
|
116
|
+
id: number;
|
|
117
|
+
leaderboard_open_id: string;
|
|
118
|
+
title: string;
|
|
119
|
+
is_default: boolean;
|
|
120
|
+
period: string;
|
|
121
|
+
whitelist_only: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Leaderboard list response
|
|
125
|
+
*/
|
|
126
|
+
export interface LeaderboardListResponse {
|
|
127
|
+
list: LeaderboardItem[];
|
|
128
|
+
total: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* List leaderboards query parameters
|
|
132
|
+
*/
|
|
133
|
+
export interface ListLeaderboardsParams {
|
|
134
|
+
developer_id?: number;
|
|
135
|
+
app_id?: number;
|
|
136
|
+
page?: number;
|
|
137
|
+
page_size?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* List all leaderboards for a specific app
|
|
141
|
+
* @param params - Query parameters (developer_id and app_id will be auto-filled if not provided)
|
|
142
|
+
* @param projectPath - Optional project path for cache lookup
|
|
143
|
+
* @returns List of leaderboards and total count
|
|
144
|
+
*/
|
|
145
|
+
export declare function listLeaderboards(params?: ListLeaderboardsParams, projectPath?: string): Promise<LeaderboardListResponse>;
|
|
146
|
+
/**
|
|
147
|
+
* Get enum descriptions for user-friendly display
|
|
148
|
+
*/
|
|
149
|
+
export declare const EnumDescriptions: {
|
|
150
|
+
PeriodType: {
|
|
151
|
+
0: string;
|
|
152
|
+
1: string;
|
|
153
|
+
2: string;
|
|
154
|
+
3: string;
|
|
155
|
+
4: string;
|
|
156
|
+
};
|
|
157
|
+
ScoreType: {
|
|
158
|
+
0: string;
|
|
159
|
+
1: string;
|
|
160
|
+
2: string;
|
|
161
|
+
};
|
|
162
|
+
ScoreOrder: {
|
|
163
|
+
0: string;
|
|
164
|
+
1: string;
|
|
165
|
+
2: string;
|
|
166
|
+
};
|
|
167
|
+
CalcType: {
|
|
168
|
+
0: string;
|
|
169
|
+
1: string;
|
|
170
|
+
2: string;
|
|
171
|
+
3: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=leaderboardApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaderboardApi.d.ts","sourceRoot":"","sources":["../../src/network/leaderboardApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA8B,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE7E;;GAEG;AACH,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,MAAM,IAAI;IACV,OAAO,IAAI;IACX,MAAM,IAAI;IACV,MAAM,IAAI;CACX;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,OAAO,IAAI;IACX,KAAK,IAAI;IACT,IAAI,IAAI;CACT;AAED;;G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sB,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA0C5E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAU/E;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAY1E;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,GAAE,sBAA2B,EACnC,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAkClC;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;CAwB5B,CAAC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TapTap Leaderboard Management API
|
|
3
|
+
* Server-side leaderboard operations
|
|
4
|
+
*/
|
|
5
|
+
import { HttpClient } from './httpClient.js';
|
|
6
|
+
import { readAppCache, saveAppCache } from '../utils/cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* Period types for leaderboard
|
|
9
|
+
*/
|
|
10
|
+
export var PeriodType;
|
|
11
|
+
(function (PeriodType) {
|
|
12
|
+
PeriodType[PeriodType["DAILY"] = 0] = "DAILY";
|
|
13
|
+
PeriodType[PeriodType["WEEKLY"] = 1] = "WEEKLY";
|
|
14
|
+
PeriodType[PeriodType["MONTHLY"] = 2] = "MONTHLY";
|
|
15
|
+
PeriodType[PeriodType["ALWAYS"] = 3] = "ALWAYS";
|
|
16
|
+
PeriodType[PeriodType["CUSTOM"] = 4] = "CUSTOM";
|
|
17
|
+
})(PeriodType || (PeriodType = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Score types
|
|
20
|
+
*/
|
|
21
|
+
export var ScoreType;
|
|
22
|
+
(function (ScoreType) {
|
|
23
|
+
ScoreType[ScoreType["INTEGER"] = 0] = "INTEGER";
|
|
24
|
+
ScoreType[ScoreType["FLOAT"] = 1] = "FLOAT";
|
|
25
|
+
ScoreType[ScoreType["TIME"] = 2] = "TIME";
|
|
26
|
+
})(ScoreType || (ScoreType = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Score order
|
|
29
|
+
*/
|
|
30
|
+
export var ScoreOrder;
|
|
31
|
+
(function (ScoreOrder) {
|
|
32
|
+
ScoreOrder[ScoreOrder["ASCENDING"] = 0] = "ASCENDING";
|
|
33
|
+
ScoreOrder[ScoreOrder["DESCENDING"] = 1] = "DESCENDING";
|
|
34
|
+
ScoreOrder[ScoreOrder["NONE"] = 2] = "NONE";
|
|
35
|
+
})(ScoreOrder || (ScoreOrder = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Calculation types
|
|
38
|
+
*/
|
|
39
|
+
export var CalcType;
|
|
40
|
+
(function (CalcType) {
|
|
41
|
+
CalcType[CalcType["BEST"] = 0] = "BEST";
|
|
42
|
+
CalcType[CalcType["LATEST"] = 1] = "LATEST";
|
|
43
|
+
CalcType[CalcType["SUM"] = 2] = "SUM";
|
|
44
|
+
CalcType[CalcType["FIRST"] = 3] = "FIRST";
|
|
45
|
+
})(CalcType || (CalcType = {}));
|
|
46
|
+
/**
|
|
47
|
+
* Create a new leaderboard
|
|
48
|
+
* @param params - Leaderboard creation parameters
|
|
49
|
+
* @returns Created leaderboard information
|
|
50
|
+
*/
|
|
51
|
+
export async function createLeaderboard(params) {
|
|
52
|
+
const client = new HttpClient();
|
|
53
|
+
try {
|
|
54
|
+
const result = await client.post('/open/leaderboard/v1/create', {
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
57
|
+
},
|
|
58
|
+
body: {
|
|
59
|
+
developer_id: params.developer_id,
|
|
60
|
+
app_id: params.app_id,
|
|
61
|
+
title: params.title,
|
|
62
|
+
period_type: params.period_type,
|
|
63
|
+
score_type: params.score_type,
|
|
64
|
+
score_order: params.score_order,
|
|
65
|
+
calc_type: params.calc_type,
|
|
66
|
+
display_limit: params.display_limit,
|
|
67
|
+
period_time: params.period_time,
|
|
68
|
+
score_unit: params.score_unit
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof Error) {
|
|
75
|
+
throw new Error(`Failed to create leaderboard: ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Failed to create leaderboard: ${String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get app/level list information for current user
|
|
82
|
+
* Returns all developers and their apps/games
|
|
83
|
+
* @param projectPath - Optional project path for cache lookup
|
|
84
|
+
* @returns App information including developer_id and app_id
|
|
85
|
+
*/
|
|
86
|
+
export async function getAppInfo(projectPath) {
|
|
87
|
+
const client = new HttpClient();
|
|
88
|
+
try {
|
|
89
|
+
const response = await client.get('/level/v1/list');
|
|
90
|
+
// Get first developer and first app by default
|
|
91
|
+
if (!response.list || response.list.length === 0) {
|
|
92
|
+
throw new Error('No developers or apps found for current user');
|
|
93
|
+
}
|
|
94
|
+
const firstDeveloper = response.list[0];
|
|
95
|
+
if (!firstDeveloper.crafts || firstDeveloper.crafts.length === 0) {
|
|
96
|
+
throw new Error(`Developer ${firstDeveloper.developer_name} has no apps/games`);
|
|
97
|
+
}
|
|
98
|
+
const firstApp = firstDeveloper.crafts[0];
|
|
99
|
+
const appInfo = {
|
|
100
|
+
developer_id: firstDeveloper.developer_id,
|
|
101
|
+
developer_name: firstDeveloper.developer_name,
|
|
102
|
+
app_id: firstApp.app_id,
|
|
103
|
+
app_title: firstApp.app_title
|
|
104
|
+
};
|
|
105
|
+
// Save to cache
|
|
106
|
+
saveAppCache(appInfo, projectPath);
|
|
107
|
+
return appInfo;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// If API fails, try to use cached data
|
|
111
|
+
const cached = readAppCache(projectPath);
|
|
112
|
+
if (cached?.developer_id && cached?.app_id) {
|
|
113
|
+
return cached;
|
|
114
|
+
}
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
throw new Error(`Failed to get app info: ${error.message}`);
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`Failed to get app info: ${String(error)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get or fetch app information with automatic caching
|
|
123
|
+
* @param projectPath - Optional project path
|
|
124
|
+
* @returns App information from cache or API
|
|
125
|
+
*/
|
|
126
|
+
export async function ensureAppInfo(projectPath) {
|
|
127
|
+
// Check cache first
|
|
128
|
+
const cached = readAppCache(projectPath);
|
|
129
|
+
if (cached?.developer_id && cached?.app_id) {
|
|
130
|
+
return cached;
|
|
131
|
+
}
|
|
132
|
+
// No cache, fetch from API
|
|
133
|
+
return await getAppInfo(projectPath);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get all developers and apps for selection
|
|
137
|
+
* @returns List of all developers and their apps
|
|
138
|
+
*/
|
|
139
|
+
export async function getAllDevelopersAndApps() {
|
|
140
|
+
const client = new HttpClient();
|
|
141
|
+
try {
|
|
142
|
+
const response = await client.get('/level/v1/list');
|
|
143
|
+
return response;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error instanceof Error) {
|
|
147
|
+
throw new Error(`Failed to get developers and apps list: ${error.message}`);
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`Failed to get developers and apps list: ${String(error)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* List all leaderboards for a specific app
|
|
154
|
+
* @param params - Query parameters (developer_id and app_id will be auto-filled if not provided)
|
|
155
|
+
* @param projectPath - Optional project path for cache lookup
|
|
156
|
+
* @returns List of leaderboards and total count
|
|
157
|
+
*/
|
|
158
|
+
export async function listLeaderboards(params = {}, projectPath) {
|
|
159
|
+
const client = new HttpClient();
|
|
160
|
+
try {
|
|
161
|
+
// Ensure developer_id and app_id are available
|
|
162
|
+
let developerId = params.developer_id;
|
|
163
|
+
let appId = params.app_id;
|
|
164
|
+
if (!developerId || !appId) {
|
|
165
|
+
const appInfo = await ensureAppInfo(projectPath);
|
|
166
|
+
if (!developerId)
|
|
167
|
+
developerId = appInfo.developer_id;
|
|
168
|
+
if (!appId)
|
|
169
|
+
appId = appInfo.app_id;
|
|
170
|
+
}
|
|
171
|
+
if (!developerId || !appId) {
|
|
172
|
+
throw new Error('developer_id and app_id are required');
|
|
173
|
+
}
|
|
174
|
+
const response = await client.get('/open/leaderboard/v1/list', {
|
|
175
|
+
params: {
|
|
176
|
+
developer_id: developerId.toString(),
|
|
177
|
+
app_id: appId.toString(),
|
|
178
|
+
page: (params.page || 1).toString(),
|
|
179
|
+
page_size: (params.page_size || 10).toString()
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return response;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof Error) {
|
|
186
|
+
throw new Error(`Failed to list leaderboards: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
throw new Error(`Failed to list leaderboards: ${String(error)}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get enum descriptions for user-friendly display
|
|
193
|
+
*/
|
|
194
|
+
export const EnumDescriptions = {
|
|
195
|
+
PeriodType: {
|
|
196
|
+
[PeriodType.DAILY]: 'Daily (resets every day)',
|
|
197
|
+
[PeriodType.WEEKLY]: 'Weekly (resets every week)',
|
|
198
|
+
[PeriodType.MONTHLY]: 'Monthly (resets every month)',
|
|
199
|
+
[PeriodType.ALWAYS]: 'Always (never resets)',
|
|
200
|
+
[PeriodType.CUSTOM]: 'Custom (custom reset schedule)'
|
|
201
|
+
},
|
|
202
|
+
ScoreType: {
|
|
203
|
+
[ScoreType.INTEGER]: 'Integer',
|
|
204
|
+
[ScoreType.FLOAT]: 'Float',
|
|
205
|
+
[ScoreType.TIME]: 'Time'
|
|
206
|
+
},
|
|
207
|
+
ScoreOrder: {
|
|
208
|
+
[ScoreOrder.ASCENDING]: 'Ascending (lower is better)',
|
|
209
|
+
[ScoreOrder.DESCENDING]: 'Descending (higher is better)',
|
|
210
|
+
[ScoreOrder.NONE]: 'None'
|
|
211
|
+
},
|
|
212
|
+
CalcType: {
|
|
213
|
+
[CalcType.BEST]: 'Best (keep best score)',
|
|
214
|
+
[CalcType.LATEST]: 'Latest (keep latest score)',
|
|
215
|
+
[CalcType.SUM]: 'Sum (sum all scores)',
|
|
216
|
+
[CalcType.FIRST]: 'First (keep first score)'
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=leaderboardApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaderboardApi.js","sourceRoot":"","sources":["../../src/network/leaderboardApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UA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