@shaivpidadi/trends-js 0.0.0-beta.7 → 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.
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GoogleTrendsApi = void 0;
4
- const enums_1 = require("../types/enums");
5
- const request_1 = require("./request");
6
- const format_1 = require("./format");
7
- const constants_1 = require("../constants");
8
- const GoogleTrendsError_1 = require("../errors/GoogleTrendsError");
4
+ const enums_js_1 = require("../types/enums.js");
5
+ const request_js_1 = require("./request.js");
6
+ const format_js_1 = require("./format.js");
7
+ const constants_js_1 = require("../constants.js");
8
+ const GoogleTrendsError_js_1 = require("../errors/GoogleTrendsError.js");
9
9
  class GoogleTrendsApi {
10
10
  /**
11
11
  * Get autocomplete suggestions for a keyword
@@ -18,14 +18,14 @@ class GoogleTrendsApi {
18
18
  return { data: [] };
19
19
  }
20
20
  const options = {
21
- ...constants_1.GOOGLE_TRENDS_MAPPER[enums_1.GoogleTrendsEndpoints.autocomplete],
21
+ ...constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.autocomplete],
22
22
  qs: {
23
23
  hl,
24
24
  tz: '240',
25
25
  },
26
26
  };
27
27
  try {
28
- const response = await (0, request_1.request)(`${options.url}/${encodeURIComponent(keyword)}`, options);
28
+ const response = await (0, request_js_1.request)(`${options.url}/${encodeURIComponent(keyword)}`, options);
29
29
  const text = await response.text();
30
30
  // Remove the first 5 characters (JSONP wrapper) and parse
31
31
  const data = JSON.parse(text.slice(5));
@@ -33,9 +33,9 @@ class GoogleTrendsApi {
33
33
  }
34
34
  catch (error) {
35
35
  if (error instanceof Error) {
36
- return { error: new GoogleTrendsError_1.NetworkError(error.message) };
36
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
37
37
  }
38
- return { error: new GoogleTrendsError_1.UnknownError() };
38
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
39
39
  }
40
40
  }
41
41
  /**
@@ -44,7 +44,7 @@ class GoogleTrendsApi {
44
44
  * @returns Promise with trending topics data
45
45
  */
46
46
  async dailyTrends({ geo = 'US', lang = 'en' }) {
47
- const defaultOptions = constants_1.GOOGLE_TRENDS_MAPPER[enums_1.GoogleTrendsEndpoints.dailyTrends];
47
+ const defaultOptions = constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.dailyTrends];
48
48
  const options = {
49
49
  ...defaultOptions,
50
50
  body: new URLSearchParams({
@@ -53,19 +53,19 @@ class GoogleTrendsApi {
53
53
  contentType: 'form'
54
54
  };
55
55
  try {
56
- const response = await (0, request_1.request)(options.url, options);
56
+ const response = await (0, request_js_1.request)(options.url, options);
57
57
  const text = await response.text();
58
- const trendingTopics = (0, format_1.extractJsonFromResponse)(text);
58
+ const trendingTopics = (0, format_js_1.extractJsonFromResponse)(text);
59
59
  if (!trendingTopics) {
60
- return { error: new GoogleTrendsError_1.ParseError() };
60
+ return { error: new GoogleTrendsError_js_1.ParseError() };
61
61
  }
62
62
  return { data: trendingTopics };
63
63
  }
64
64
  catch (error) {
65
65
  if (error instanceof Error) {
66
- return { error: new GoogleTrendsError_1.NetworkError(error.message) };
66
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
67
67
  }
68
- return { error: new GoogleTrendsError_1.UnknownError() };
68
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
69
69
  }
70
70
  }
71
71
  /**
@@ -74,7 +74,7 @@ class GoogleTrendsApi {
74
74
  * @returns Promise with trending topics data
75
75
  */
76
76
  async realTimeTrends({ geo = 'US', trendingHours = 4 }) {
77
- const defaultOptions = constants_1.GOOGLE_TRENDS_MAPPER[enums_1.GoogleTrendsEndpoints.dailyTrends];
77
+ const defaultOptions = constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.dailyTrends];
78
78
  const options = {
79
79
  ...defaultOptions,
80
80
  body: new URLSearchParams({
@@ -83,24 +83,24 @@ class GoogleTrendsApi {
83
83
  contentType: 'form'
84
84
  };
85
85
  try {
86
- const response = await (0, request_1.request)(options.url, options);
86
+ const response = await (0, request_js_1.request)(options.url, options);
87
87
  const text = await response.text();
88
- const trendingTopics = (0, format_1.extractJsonFromResponse)(text);
88
+ const trendingTopics = (0, format_js_1.extractJsonFromResponse)(text);
89
89
  if (!trendingTopics) {
90
- return { error: new GoogleTrendsError_1.ParseError() };
90
+ return { error: new GoogleTrendsError_js_1.ParseError() };
91
91
  }
92
92
  return { data: trendingTopics };
93
93
  }
94
94
  catch (error) {
95
95
  if (error instanceof Error) {
96
- return { error: new GoogleTrendsError_1.NetworkError(error.message) };
96
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
97
97
  }
98
- return { error: new GoogleTrendsError_1.UnknownError() };
98
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
99
99
  }
100
100
  }
101
101
  async explore({ keyword, geo = 'US', time = 'now 1-d', category = 0, property = '', hl = 'en-US', }) {
102
102
  const options = {
103
- ...constants_1.GOOGLE_TRENDS_MAPPER[enums_1.GoogleTrendsEndpoints.explore],
103
+ ...constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.explore],
104
104
  qs: {
105
105
  hl,
106
106
  tz: '240',
@@ -119,15 +119,35 @@ class GoogleTrendsApi {
119
119
  contentType: 'form'
120
120
  };
121
121
  try {
122
- const response = await (0, request_1.request)(options.url, options);
122
+ const response = await (0, request_js_1.request)(options.url, options);
123
123
  const text = await response.text();
124
- // Remove the first 5 characters (JSONP wrapper) and parse
125
- const data = JSON.parse(text.slice(5));
126
- return data;
124
+ // Check if response is HTML (error page)
125
+ if (text.includes('<html') || text.includes('<!DOCTYPE')) {
126
+ return { error: new GoogleTrendsError_js_1.ParseError('Explore request returned HTML instead of JSON') };
127
+ }
128
+ // Try to parse as JSON
129
+ try {
130
+ // Remove the first 5 characters (JSONP wrapper) and parse
131
+ const data = JSON.parse(text.slice(5));
132
+ // Extract widgets from the response
133
+ if (data && Array.isArray(data) && data.length > 0) {
134
+ const widgets = data[0] || [];
135
+ return { widgets };
136
+ }
137
+ return { widgets: [] };
138
+ }
139
+ catch (parseError) {
140
+ if (parseError instanceof Error) {
141
+ return { error: new GoogleTrendsError_js_1.ParseError(`Failed to parse explore response as JSON: ${parseError.message}`) };
142
+ }
143
+ return { error: new GoogleTrendsError_js_1.ParseError('Failed to parse explore response as JSON') };
144
+ }
127
145
  }
128
146
  catch (error) {
129
- console.error('Explore request failed:', error);
130
- return { widgets: [] };
147
+ if (error instanceof Error) {
148
+ return { error: new GoogleTrendsError_js_1.NetworkError(`Explore request failed: ${error.message}`) };
149
+ }
150
+ return { error: new GoogleTrendsError_js_1.UnknownError('Explore request failed') };
131
151
  }
132
152
  }
133
153
  //
@@ -159,12 +179,15 @@ class GoogleTrendsApi {
159
179
  category,
160
180
  hl
161
181
  });
182
+ if ('error' in exploreResponse) {
183
+ return { error: exploreResponse.error };
184
+ }
162
185
  const widget = exploreResponse.widgets.find(w => w.id === 'GEO_MAP');
163
186
  if (!widget) {
164
- return { default: { geoMapData: [] } };
187
+ return { error: new GoogleTrendsError_js_1.ParseError('No GEO_MAP widget found in explore response') };
165
188
  }
166
189
  const options = {
167
- ...constants_1.GOOGLE_TRENDS_MAPPER[enums_1.GoogleTrendsEndpoints.interestByRegion],
190
+ ...constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.interestByRegion],
168
191
  qs: {
169
192
  hl,
170
193
  tz: timezone.toString(),
@@ -176,7 +199,7 @@ class GoogleTrendsApi {
176
199
  time: `${formatDate(startTime)} ${formatDate(endTime)}`,
177
200
  complexKeywordsRestriction: {
178
201
  keyword: [{
179
- type: 'BROAD',
202
+ type: 'BROAD', //'ENTITY',
180
203
  value: Array.isArray(keyword) ? keyword[0] : keyword
181
204
  }]
182
205
  }
@@ -185,7 +208,7 @@ class GoogleTrendsApi {
185
208
  locale: hl,
186
209
  requestOptions: {
187
210
  property: '',
188
- backend: 'CM',
211
+ backend: 'CM', //'IZG',
189
212
  category
190
213
  },
191
214
  userConfig: {
@@ -196,14 +219,186 @@ class GoogleTrendsApi {
196
219
  }
197
220
  };
198
221
  try {
199
- const response = await (0, request_1.request)(options.url, options);
222
+ const response = await (0, request_js_1.request)(options.url, options);
200
223
  const text = await response.text();
201
224
  // Remove the first 5 characters (JSONP wrapper) and parse
202
225
  const data = JSON.parse(text.slice(5));
203
226
  return data;
204
227
  }
205
228
  catch (error) {
206
- return { default: { geoMapData: [] } };
229
+ if (error instanceof Error) {
230
+ return { error: new GoogleTrendsError_js_1.ParseError(`Failed to parse interest by region response: ${error.message}`) };
231
+ }
232
+ return { error: new GoogleTrendsError_js_1.ParseError('Failed to parse interest by region response') };
233
+ }
234
+ }
235
+ async relatedTopics({ keyword, geo = 'US', time = 'now 1-d', category = 0, property = '', hl = 'en-US', }) {
236
+ try {
237
+ // Validate keyword
238
+ if (!keyword || keyword.trim() === '') {
239
+ return { error: new GoogleTrendsError_js_1.InvalidRequestError('Keyword is required') };
240
+ }
241
+ // Step 1: Call explore to get widget data and token
242
+ const exploreResponse = await this.explore({
243
+ keyword,
244
+ geo,
245
+ time,
246
+ category,
247
+ property,
248
+ hl
249
+ });
250
+ if ('error' in exploreResponse) {
251
+ return { error: exploreResponse.error };
252
+ }
253
+ if (!exploreResponse.widgets || exploreResponse.widgets.length === 0) {
254
+ return { error: new GoogleTrendsError_js_1.ParseError('No widgets found in explore response. This might be due to Google blocking the request, invalid parameters, or network issues.') };
255
+ }
256
+ // Step 2: Find the related topics widget or use any available widget
257
+ const relatedTopicsWidget = exploreResponse.widgets.find(widget => widget.id === 'RELATED_TOPICS' ||
258
+ widget.request?.restriction?.complexKeywordsRestriction?.keyword?.[0]?.value === keyword) || exploreResponse.widgets[0]; // Fallback to first widget if no specific one found
259
+ if (!relatedTopicsWidget) {
260
+ return { error: new GoogleTrendsError_js_1.ParseError('No related topics widget found in explore response') };
261
+ }
262
+ // Step 3: Call the related topics API with or without token
263
+ const options = {
264
+ ...constants_js_1.GOOGLE_TRENDS_MAPPER[enums_js_1.GoogleTrendsEndpoints.relatedTopics],
265
+ qs: {
266
+ hl,
267
+ tz: '240',
268
+ req: JSON.stringify({
269
+ restriction: {
270
+ geo: { country: geo },
271
+ time: time,
272
+ originalTimeRangeForExploreUrl: time,
273
+ complexKeywordsRestriction: {
274
+ keyword: [{
275
+ type: 'BROAD',
276
+ value: keyword
277
+ }]
278
+ }
279
+ },
280
+ keywordType: 'ENTITY',
281
+ metric: ['TOP', 'RISING'],
282
+ trendinessSettings: {
283
+ compareTime: time
284
+ },
285
+ requestOptions: {
286
+ property: property,
287
+ backend: 'CM',
288
+ category: category
289
+ },
290
+ language: hl.split('-')[0],
291
+ userCountryCode: geo,
292
+ userConfig: {
293
+ userType: 'USER_TYPE_LEGIT_USER'
294
+ }
295
+ }),
296
+ ...(relatedTopicsWidget.token && { token: relatedTopicsWidget.token })
297
+ }
298
+ };
299
+ const response = await (0, request_js_1.request)(options.url, options);
300
+ const text = await response.text();
301
+ // Parse the response
302
+ try {
303
+ const data = JSON.parse(text.slice(5));
304
+ // Return the data in the expected format
305
+ return {
306
+ data: {
307
+ default: {
308
+ rankedList: data.default?.rankedList || []
309
+ }
310
+ }
311
+ };
312
+ }
313
+ catch (parseError) {
314
+ if (parseError instanceof Error) {
315
+ return { error: new GoogleTrendsError_js_1.ParseError(`Failed to parse related topics response: ${parseError.message}`) };
316
+ }
317
+ return { error: new GoogleTrendsError_js_1.ParseError('Failed to parse related topics response') };
318
+ }
319
+ }
320
+ catch (error) {
321
+ if (error instanceof Error) {
322
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
323
+ }
324
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
325
+ }
326
+ }
327
+ async relatedQueries({ keyword, geo = 'US', time = 'now 1-d', category = 0, property = '', hl = 'en-US', }) {
328
+ try {
329
+ // Validate keyword
330
+ if (!keyword || keyword.trim() === '') {
331
+ return { error: new GoogleTrendsError_js_1.ParseError() };
332
+ }
333
+ const autocompleteResult = await this.autocomplete(keyword, hl);
334
+ if (autocompleteResult.error) {
335
+ return { error: autocompleteResult.error };
336
+ }
337
+ const relatedQueries = autocompleteResult.data?.slice(0, 10).map((suggestion, index) => ({
338
+ query: suggestion,
339
+ value: 100 - index * 10,
340
+ formattedValue: (100 - index * 10).toString(),
341
+ hasData: true,
342
+ link: `/trends/explore?q=${encodeURIComponent(suggestion)}&date=${time}&geo=${geo}`
343
+ })) || [];
344
+ return {
345
+ data: {
346
+ default: {
347
+ rankedList: [{
348
+ rankedKeyword: relatedQueries
349
+ }]
350
+ }
351
+ }
352
+ };
353
+ }
354
+ catch (error) {
355
+ if (error instanceof Error) {
356
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
357
+ }
358
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
359
+ }
360
+ }
361
+ async relatedData({ keyword, geo = 'US', time = 'now 1-d', category = 0, property = '', hl = 'en-US', }) {
362
+ try {
363
+ // Validate keyword
364
+ if (!keyword || keyword.trim() === '') {
365
+ return { error: new GoogleTrendsError_js_1.ParseError() };
366
+ }
367
+ const autocompleteResult = await this.autocomplete(keyword, hl);
368
+ if (autocompleteResult.error) {
369
+ return { error: autocompleteResult.error };
370
+ }
371
+ const suggestions = autocompleteResult.data?.slice(0, 10) || [];
372
+ const topics = suggestions.map((suggestion, index) => ({
373
+ topic: {
374
+ mid: `/m/${index}`,
375
+ title: suggestion,
376
+ type: 'Topic'
377
+ },
378
+ value: 100 - index * 10,
379
+ formattedValue: (100 - index * 10).toString(),
380
+ hasData: true,
381
+ link: `/trends/explore?q=${encodeURIComponent(suggestion)}&date=${time}&geo=${geo}`
382
+ }));
383
+ const queries = suggestions.map((suggestion, index) => ({
384
+ query: suggestion,
385
+ value: 100 - index * 10,
386
+ formattedValue: (100 - index * 10).toString(),
387
+ hasData: true,
388
+ link: `/trends/explore?q=${encodeURIComponent(suggestion)}&date=${time}&geo=${geo}`
389
+ }));
390
+ return {
391
+ data: {
392
+ topics,
393
+ queries
394
+ }
395
+ };
396
+ }
397
+ catch (error) {
398
+ if (error instanceof Error) {
399
+ return { error: new GoogleTrendsError_js_1.NetworkError(error.message) };
400
+ }
401
+ return { error: new GoogleTrendsError_js_1.UnknownError() };
207
402
  }
208
403
  }
209
404
  }
@@ -3,7 +3,7 @@ export declare const request: (url: string, options: {
3
3
  qs?: Record<string, any>;
4
4
  body?: string | Record<string, any>;
5
5
  headers?: Record<string, string>;
6
- contentType?: 'json' | 'form';
6
+ contentType?: "json" | "form";
7
7
  }) => Promise<{
8
8
  text: () => Promise<string>;
9
9
  }>;
@@ -1,9 +1,29 @@
1
- export declare const dailyTrends: ({ geo, lang }: import("./types").DailyTrendingTopicsOptions) => Promise<import("./types").GoogleTrendsResponse<import("./types").DailyTrendingTopics>>;
2
- export declare const realTimeTrends: ({ geo, trendingHours }: import("./types").RealTimeTrendsOptions) => Promise<import("./types").GoogleTrendsResponse<import("./types").DailyTrendingTopics>>;
3
- export declare const autocomplete: (keyword: string, hl?: string) => Promise<import("./types").GoogleTrendsResponse<string[]>>;
1
+ import { GoogleTrendsApi } from './helpers/googleTrendsAPI.js';
2
+ export declare const dailyTrends: ({ geo, lang }: import("./types/index.js").DailyTrendingTopicsOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").DailyTrendingTopics>>;
3
+ export declare const realTimeTrends: ({ geo, trendingHours }: import("./types/index.js").RealTimeTrendsOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").DailyTrendingTopics>>;
4
+ export declare const autocomplete: (keyword: string, hl?: string) => Promise<import("./types/index.js").GoogleTrendsResponse<string[]>>;
5
+ export declare const explore: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").ExploreResponse | {
6
+ error: import("./types/index.js").GoogleTrendsError;
7
+ }>;
8
+ export declare const interestByRegion: ({ keyword, startTime, endTime, geo, resolution, hl, timezone, category }: import("./types/index.js").InterestByRegionOptions) => Promise<import("./types/index.js").InterestByRegionResponse | {
9
+ error: import("./types/index.js").GoogleTrendsError;
10
+ }>;
11
+ export declare const relatedTopics: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedTopicsResponse>>;
12
+ export declare const relatedQueries: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedQueriesResponse>>;
13
+ export declare const relatedData: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedData>>;
14
+ export { GoogleTrendsApi };
4
15
  declare const _default: {
5
- dailyTrends: ({ geo, lang }: import("./types").DailyTrendingTopicsOptions) => Promise<import("./types").GoogleTrendsResponse<import("./types").DailyTrendingTopics>>;
6
- realTimeTrends: ({ geo, trendingHours }: import("./types").RealTimeTrendsOptions) => Promise<import("./types").GoogleTrendsResponse<import("./types").DailyTrendingTopics>>;
7
- autocomplete: (keyword: string, hl?: string) => Promise<import("./types").GoogleTrendsResponse<string[]>>;
16
+ dailyTrends: ({ geo, lang }: import("./types/index.js").DailyTrendingTopicsOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").DailyTrendingTopics>>;
17
+ realTimeTrends: ({ geo, trendingHours }: import("./types/index.js").RealTimeTrendsOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").DailyTrendingTopics>>;
18
+ autocomplete: (keyword: string, hl?: string) => Promise<import("./types/index.js").GoogleTrendsResponse<string[]>>;
19
+ explore: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").ExploreResponse | {
20
+ error: import("./types/index.js").GoogleTrendsError;
21
+ }>;
22
+ interestByRegion: ({ keyword, startTime, endTime, geo, resolution, hl, timezone, category }: import("./types/index.js").InterestByRegionOptions) => Promise<import("./types/index.js").InterestByRegionResponse | {
23
+ error: import("./types/index.js").GoogleTrendsError;
24
+ }>;
25
+ relatedTopics: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedTopicsResponse>>;
26
+ relatedQueries: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedQueriesResponse>>;
27
+ relatedData: ({ keyword, geo, time, category, property, hl, }: import("./types/index.js").ExploreOptions) => Promise<import("./types/index.js").GoogleTrendsResponse<import("./types/index.js").RelatedData>>;
8
28
  };
9
29
  export default _default;
package/dist/cjs/index.js CHANGED
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.autocomplete = exports.realTimeTrends = exports.dailyTrends = void 0;
4
- const googleTrendsAPI_1 = require("./helpers/googleTrendsAPI");
5
- const api = new googleTrendsAPI_1.GoogleTrendsApi();
3
+ exports.GoogleTrendsApi = exports.relatedData = exports.relatedQueries = exports.relatedTopics = exports.interestByRegion = exports.explore = exports.autocomplete = exports.realTimeTrends = exports.dailyTrends = void 0;
4
+ const googleTrendsAPI_js_1 = require("./helpers/googleTrendsAPI.js");
5
+ Object.defineProperty(exports, "GoogleTrendsApi", { enumerable: true, get: function () { return googleTrendsAPI_js_1.GoogleTrendsApi; } });
6
+ const api = new googleTrendsAPI_js_1.GoogleTrendsApi();
6
7
  exports.dailyTrends = api.dailyTrends.bind(api);
7
8
  exports.realTimeTrends = api.realTimeTrends.bind(api);
8
9
  exports.autocomplete = api.autocomplete.bind(api);
10
+ exports.explore = api.explore.bind(api);
11
+ exports.interestByRegion = api.interestByRegion.bind(api);
12
+ exports.relatedTopics = api.relatedTopics.bind(api);
13
+ exports.relatedQueries = api.relatedQueries.bind(api);
14
+ exports.relatedData = api.relatedData.bind(api);
9
15
  // Default export for CommonJS compatibility
10
16
  exports.default = {
11
17
  dailyTrends: exports.dailyTrends,
12
18
  realTimeTrends: exports.realTimeTrends,
13
- autocomplete: exports.autocomplete
19
+ autocomplete: exports.autocomplete,
20
+ explore: exports.explore,
21
+ interestByRegion: exports.interestByRegion,
22
+ relatedTopics: exports.relatedTopics,
23
+ relatedQueries: exports.relatedQueries,
24
+ relatedData: exports.relatedData
14
25
  };
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -2,7 +2,9 @@ export declare enum GoogleTrendsEndpoints {
2
2
  dailyTrends = "dailyTrends",
3
3
  autocomplete = "autocomplete",
4
4
  explore = "explore",
5
- interestByRegion = "interestByRegion"
5
+ interestByRegion = "interestByRegion",
6
+ relatedTopics = "relatedTopics",
7
+ relatedQueries = "relatedQueries"
6
8
  }
7
9
  export declare enum GoogleTrendsTrendingHours {
8
10
  fourHrs = 4,
@@ -7,11 +7,13 @@ var GoogleTrendsEndpoints;
7
7
  GoogleTrendsEndpoints["autocomplete"] = "autocomplete";
8
8
  GoogleTrendsEndpoints["explore"] = "explore";
9
9
  GoogleTrendsEndpoints["interestByRegion"] = "interestByRegion";
10
- })(GoogleTrendsEndpoints = exports.GoogleTrendsEndpoints || (exports.GoogleTrendsEndpoints = {}));
10
+ GoogleTrendsEndpoints["relatedTopics"] = "relatedTopics";
11
+ GoogleTrendsEndpoints["relatedQueries"] = "relatedQueries";
12
+ })(GoogleTrendsEndpoints || (exports.GoogleTrendsEndpoints = GoogleTrendsEndpoints = {}));
11
13
  var GoogleTrendsTrendingHours;
12
14
  (function (GoogleTrendsTrendingHours) {
13
15
  GoogleTrendsTrendingHours[GoogleTrendsTrendingHours["fourHrs"] = 4] = "fourHrs";
14
16
  GoogleTrendsTrendingHours[GoogleTrendsTrendingHours["oneDay"] = 24] = "oneDay";
15
17
  GoogleTrendsTrendingHours[GoogleTrendsTrendingHours["twoDays"] = 48] = "twoDays";
16
18
  GoogleTrendsTrendingHours[GoogleTrendsTrendingHours["sevenDays"] = 168] = "sevenDays";
17
- })(GoogleTrendsTrendingHours = exports.GoogleTrendsTrendingHours || (exports.GoogleTrendsTrendingHours = {}));
19
+ })(GoogleTrendsTrendingHours || (exports.GoogleTrendsTrendingHours = GoogleTrendsTrendingHours = {}));
@@ -1,3 +1,3 @@
1
- import { GoogleTrendsEndpoints } from './types/enums';
2
- import { GoogleTrendsMapper } from './types';
1
+ import { GoogleTrendsEndpoints } from './types/enums.js';
2
+ import { GoogleTrendsMapper } from './types/index.js';
3
3
  export declare const GOOGLE_TRENDS_MAPPER: Record<GoogleTrendsEndpoints, GoogleTrendsMapper>;
@@ -1,4 +1,4 @@
1
- import { GoogleTrendsEndpoints } from './types/enums';
1
+ import { GoogleTrendsEndpoints } from './types/enums.js';
2
2
  const GOOGLE_TRENDS_BASE_URL = 'trends.google.com';
3
3
  export const GOOGLE_TRENDS_MAPPER = {
4
4
  [GoogleTrendsEndpoints.dailyTrends]: {
@@ -33,4 +33,18 @@ export const GOOGLE_TRENDS_MAPPER = {
33
33
  url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/comparedgeo`,
34
34
  headers: {},
35
35
  },
36
+ [GoogleTrendsEndpoints.relatedTopics]: {
37
+ path: '/trends/api/widgetdata/relatedtopics',
38
+ method: 'GET',
39
+ host: GOOGLE_TRENDS_BASE_URL,
40
+ url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/relatedtopics`,
41
+ headers: {},
42
+ },
43
+ [GoogleTrendsEndpoints.relatedQueries]: {
44
+ path: '/trends/api/widgetdata/relatedqueries',
45
+ method: 'GET',
46
+ host: GOOGLE_TRENDS_BASE_URL,
47
+ url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/relatedqueries`,
48
+ headers: {},
49
+ },
36
50
  };
@@ -1,4 +1,4 @@
1
- import { GoogleTrendsError } from '../types';
1
+ import { GoogleTrendsError } from '../types/index.js';
2
2
  export declare class RateLimitError extends Error implements GoogleTrendsError {
3
3
  code: string;
4
4
  statusCode: number;
@@ -1,2 +1,2 @@
1
- import { DailyTrendingTopics } from '../types';
1
+ import { DailyTrendingTopics } from '../types/index.js';
2
2
  export declare const extractJsonFromResponse: (text: string) => DailyTrendingTopics | null;
@@ -1,4 +1,4 @@
1
- import { ParseError } from '../errors/GoogleTrendsError';
1
+ import { ParseError } from '../errors/GoogleTrendsError.js';
2
2
  // For future refrence and update: from google trends page rpc call response,
3
3
  // 0 "twitter down" The main trending search term.
4
4
  // 1 null Unused (reserved for future Google Trends data).
@@ -1,4 +1,4 @@
1
- import { DailyTrendingTopics, DailyTrendingTopicsOptions, RealTimeTrendsOptions, ExploreOptions, ExploreResponse, InterestByRegionOptions, InterestByRegionResponse, GoogleTrendsResponse } from '../types/index';
1
+ import { DailyTrendingTopics, DailyTrendingTopicsOptions, RealTimeTrendsOptions, ExploreOptions, ExploreResponse, InterestByRegionOptions, InterestByRegionResponse, GoogleTrendsResponse, GoogleTrendsError, RelatedTopicsResponse, RelatedQueriesResponse, RelatedData } from '../types/index.js';
2
2
  export declare class GoogleTrendsApi {
3
3
  /**
4
4
  * Get autocomplete suggestions for a keyword
@@ -19,8 +19,15 @@ export declare class GoogleTrendsApi {
19
19
  * @returns Promise with trending topics data
20
20
  */
21
21
  realTimeTrends({ geo, trendingHours }: RealTimeTrendsOptions): Promise<GoogleTrendsResponse<DailyTrendingTopics>>;
22
- explore({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<ExploreResponse>;
23
- interestByRegion({ keyword, startTime, endTime, geo, resolution, hl, timezone, category }: InterestByRegionOptions): Promise<InterestByRegionResponse>;
22
+ explore({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<ExploreResponse | {
23
+ error: GoogleTrendsError;
24
+ }>;
25
+ interestByRegion({ keyword, startTime, endTime, geo, resolution, hl, timezone, category }: InterestByRegionOptions): Promise<InterestByRegionResponse | {
26
+ error: GoogleTrendsError;
27
+ }>;
28
+ relatedTopics({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedTopicsResponse>>;
29
+ relatedQueries({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedQueriesResponse>>;
30
+ relatedData({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedData>>;
24
31
  }
25
32
  declare const _default: GoogleTrendsApi;
26
33
  export default _default;