@dracoonghost/trndup-sdk 1.3.25 → 1.4.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/dist/index.d.mts +280 -1
- package/dist/index.d.ts +280 -1
- package/dist/index.js +184 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -81,19 +81,27 @@ var TrndUpClient = class {
|
|
|
81
81
|
() => controller.abort(),
|
|
82
82
|
timeout ?? this.config.timeout
|
|
83
83
|
);
|
|
84
|
+
const startTime = Date.now();
|
|
84
85
|
try {
|
|
85
86
|
if (this.config.debug) {
|
|
86
|
-
|
|
87
|
+
this.logRequest(method, url, body);
|
|
87
88
|
}
|
|
88
89
|
const response = await fetch(url, {
|
|
89
90
|
...init,
|
|
90
91
|
signal: signal ?? controller.signal
|
|
91
92
|
});
|
|
92
93
|
clearTimeout(timeoutId);
|
|
93
|
-
|
|
94
|
+
const result = await this.handleResponse(response, path);
|
|
95
|
+
if (this.config.debug) {
|
|
96
|
+
this.logResponse(method, path, response.status, result, startTime);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
94
99
|
} catch (error) {
|
|
95
100
|
clearTimeout(timeoutId);
|
|
96
101
|
if (error instanceof TrndUpApiError) {
|
|
102
|
+
if (this.config.debug) {
|
|
103
|
+
this.logError(method, path, error, startTime);
|
|
104
|
+
}
|
|
97
105
|
throw error;
|
|
98
106
|
}
|
|
99
107
|
const networkError = new TrndUpNetworkError(
|
|
@@ -101,11 +109,56 @@ var TrndUpClient = class {
|
|
|
101
109
|
path
|
|
102
110
|
);
|
|
103
111
|
if (this.config.debug) {
|
|
104
|
-
|
|
112
|
+
this.logError(method, path, networkError, startTime);
|
|
105
113
|
}
|
|
106
114
|
throw networkError;
|
|
107
115
|
}
|
|
108
116
|
}
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// LOGGING HELPERS
|
|
119
|
+
// =============================================================================
|
|
120
|
+
logRequest(method, url, body) {
|
|
121
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
122
|
+
const bodyPreview = body ? this.truncateObject(body, 200) : void 0;
|
|
123
|
+
console.log(
|
|
124
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[33m\u2192 ${method}\x1B[0m ${url}` + (bodyPreview ? `
|
|
125
|
+
\x1B[90mbody:\x1B[0m ${bodyPreview}` : "")
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
logResponse(method, path, status, data, startTime) {
|
|
129
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
130
|
+
const duration = Date.now() - startTime;
|
|
131
|
+
const statusColor = status >= 200 && status < 300 ? "\x1B[32m" : "\x1B[31m";
|
|
132
|
+
const dataPreview = this.truncateObject(data, 300);
|
|
133
|
+
console.log(
|
|
134
|
+
`\x1B[36m[${timestamp}]\x1B[0m ${statusColor}\u2190 ${status}\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
135
|
+
\x1B[90mdata:\x1B[0m ${dataPreview}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
logError(method, path, error, startTime) {
|
|
139
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
140
|
+
const duration = Date.now() - startTime;
|
|
141
|
+
if (error instanceof TrndUpApiError) {
|
|
142
|
+
console.log(
|
|
143
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[31m\u2715 ${error.status}\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
144
|
+
\x1B[31merror:\x1B[0m ${error.code || "UNKNOWN"} - ${error.message}`
|
|
145
|
+
);
|
|
146
|
+
} else {
|
|
147
|
+
console.log(
|
|
148
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[31m\u2715 NETWORK\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
149
|
+
\x1B[31merror:\x1B[0m ${error.message}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
truncateObject(obj, maxLength) {
|
|
154
|
+
try {
|
|
155
|
+
const str = JSON.stringify(obj);
|
|
156
|
+
if (str.length <= maxLength) return str;
|
|
157
|
+
return str.slice(0, maxLength) + "...";
|
|
158
|
+
} catch {
|
|
159
|
+
return "[Unable to serialize]";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
109
162
|
buildUrl(path, params) {
|
|
110
163
|
const url = new URL(`${this.config.baseUrl}${path}`);
|
|
111
164
|
if (params) {
|
|
@@ -162,9 +215,6 @@ var TrndUpClient = class {
|
|
|
162
215
|
if (apiError.isAuthError() && this.config.onAuthFailure) {
|
|
163
216
|
await this.config.onAuthFailure();
|
|
164
217
|
}
|
|
165
|
-
if (this.config.debug) {
|
|
166
|
-
console.error("[TrndUp SDK] API error:", apiError);
|
|
167
|
-
}
|
|
168
218
|
throw apiError;
|
|
169
219
|
}
|
|
170
220
|
if (isJson) {
|
|
@@ -1166,6 +1216,133 @@ var ActivityModule = class {
|
|
|
1166
1216
|
}
|
|
1167
1217
|
};
|
|
1168
1218
|
|
|
1219
|
+
// modules/trends.ts
|
|
1220
|
+
var TrendsModule = class {
|
|
1221
|
+
constructor(client) {
|
|
1222
|
+
this.client = client;
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* List trending topics with optional filters
|
|
1226
|
+
*
|
|
1227
|
+
* @param params - Filter and pagination options
|
|
1228
|
+
* @returns Paginated list of trends sorted by relevance
|
|
1229
|
+
*
|
|
1230
|
+
* @example
|
|
1231
|
+
* ```typescript
|
|
1232
|
+
* // Get top trends
|
|
1233
|
+
* const trends = await sdk.trends.list();
|
|
1234
|
+
*
|
|
1235
|
+
* // Filter by category
|
|
1236
|
+
* const sportsTrends = await sdk.trends.list({ category: 'SPORTS' });
|
|
1237
|
+
*
|
|
1238
|
+
* // Filter by velocity
|
|
1239
|
+
* const viralTrends = await sdk.trends.list({ velocity: 'VIRAL' });
|
|
1240
|
+
*
|
|
1241
|
+
* // Paginate
|
|
1242
|
+
* const page2 = await sdk.trends.list({ limit: 20, offset: 20 });
|
|
1243
|
+
* ```
|
|
1244
|
+
*/
|
|
1245
|
+
async list(params = {}) {
|
|
1246
|
+
const queryParams = {};
|
|
1247
|
+
if (params.category) queryParams.category = params.category;
|
|
1248
|
+
if (params.velocity) queryParams.velocity = params.velocity;
|
|
1249
|
+
if (params.status) queryParams.status = params.status;
|
|
1250
|
+
if (params.platform) queryParams.platform = params.platform;
|
|
1251
|
+
if (params.limit) queryParams.limit = params.limit;
|
|
1252
|
+
if (params.offset) queryParams.offset = params.offset;
|
|
1253
|
+
return this.client.get("/v1/trends", queryParams);
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Get full details of a specific trend
|
|
1257
|
+
*
|
|
1258
|
+
* @param trendId - The unique trend ID
|
|
1259
|
+
* @returns Full trend details including content ideas and examples
|
|
1260
|
+
*
|
|
1261
|
+
* @example
|
|
1262
|
+
* ```typescript
|
|
1263
|
+
* const trend = await sdk.trends.getById('trend_123');
|
|
1264
|
+
* console.log(trend.contentIdeas);
|
|
1265
|
+
* console.log(trend.topExamples);
|
|
1266
|
+
* ```
|
|
1267
|
+
*/
|
|
1268
|
+
async getById(trendId) {
|
|
1269
|
+
return this.client.get(`/v1/trends/${trendId}`);
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Get all categories with trend counts
|
|
1273
|
+
*
|
|
1274
|
+
* @returns List of categories and their trend counts
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```typescript
|
|
1278
|
+
* const categories = await sdk.trends.getCategories();
|
|
1279
|
+
* // [{ category: 'SPORTS', count: 15 }, { category: 'TECH', count: 12 }, ...]
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
1282
|
+
async getCategories() {
|
|
1283
|
+
return this.client.get("/v1/trends/meta/categories");
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get all platforms with trend counts
|
|
1287
|
+
*
|
|
1288
|
+
* @returns List of platforms and their trend counts
|
|
1289
|
+
*
|
|
1290
|
+
* @example
|
|
1291
|
+
* ```typescript
|
|
1292
|
+
* const platforms = await sdk.trends.getPlatforms();
|
|
1293
|
+
* // [{ platform: 'YouTube', count: 25 }, { platform: 'Instagram', count: 18 }, ...]
|
|
1294
|
+
* ```
|
|
1295
|
+
*/
|
|
1296
|
+
async getPlatforms() {
|
|
1297
|
+
return this.client.get("/v1/trends/meta/platforms");
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Get sync status information
|
|
1301
|
+
*
|
|
1302
|
+
* @returns Current sync status and statistics
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```typescript
|
|
1306
|
+
* const status = await sdk.trends.getSyncStatus();
|
|
1307
|
+
* console.log(status.lastSyncedAt);
|
|
1308
|
+
* console.log(status.totalTrends);
|
|
1309
|
+
* ```
|
|
1310
|
+
*/
|
|
1311
|
+
async getSyncStatus() {
|
|
1312
|
+
return this.client.get("/v1/trends/meta/sync-status");
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Get viral trends (velocity = VIRAL)
|
|
1316
|
+
* Convenience method for filtering viral trends
|
|
1317
|
+
*
|
|
1318
|
+
* @param limit - Max results (default: 10)
|
|
1319
|
+
* @returns List of viral trends
|
|
1320
|
+
*/
|
|
1321
|
+
async getViral(limit = 10) {
|
|
1322
|
+
return this.list({ velocity: "VIRAL", limit });
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Get peaking trends (status = PEAKING)
|
|
1326
|
+
* Convenience method for filtering trends at peak
|
|
1327
|
+
*
|
|
1328
|
+
* @param limit - Max results (default: 10)
|
|
1329
|
+
* @returns List of peaking trends
|
|
1330
|
+
*/
|
|
1331
|
+
async getPeaking(limit = 10) {
|
|
1332
|
+
return this.list({ status: "PEAKING", limit });
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Get trends for a specific platform
|
|
1336
|
+
*
|
|
1337
|
+
* @param platform - Platform name (e.g., 'YouTube', 'Instagram')
|
|
1338
|
+
* @param limit - Max results (default: 20)
|
|
1339
|
+
* @returns List of trends for the platform
|
|
1340
|
+
*/
|
|
1341
|
+
async getByPlatform(platform, limit = 20) {
|
|
1342
|
+
return this.list({ platform, limit });
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1169
1346
|
// types.ts
|
|
1170
1347
|
var YOUTUBE_SCOPES = [
|
|
1171
1348
|
"openid",
|
|
@@ -1193,6 +1370,7 @@ var TrndUpSDK = class extends TrndUpClient {
|
|
|
1193
1370
|
this.social = new SocialModule(this);
|
|
1194
1371
|
this.insights = new InsightsModule(this);
|
|
1195
1372
|
this.activity = new ActivityModule(this);
|
|
1373
|
+
this.trends = new TrendsModule(this);
|
|
1196
1374
|
}
|
|
1197
1375
|
};
|
|
1198
1376
|
var SDK_VERSION = "1.0.0";
|