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