@crosspost/sdk 0.2.8 → 0.2.9

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.cjs CHANGED
@@ -371,23 +371,24 @@ async function makeRequest(method, path, options, data, query) {
371
371
  // src/api/activity.ts
372
372
  function createFilterQuery(query) {
373
373
  if (!query) return {};
374
- const queryObj = query;
375
374
  const result = {};
376
- Object.keys(queryObj).forEach((key) => {
377
- if (key !== "filter") {
378
- result[key] = queryObj[key];
379
- }
380
- });
381
- if (queryObj.filter) {
382
- const filter = queryObj.filter;
383
- if (filter.platforms && Array.isArray(filter.platforms)) {
384
- result.platforms = filter.platforms.join(",");
385
- }
386
- if (filter.types && Array.isArray(filter.types)) {
387
- result.types = filter.types.join(",");
388
- }
389
- if (filter.timeframe) {
390
- result.timeframe = filter.timeframe;
375
+ if (query.limit !== void 0) {
376
+ result.limit = query.limit;
377
+ }
378
+ if (query.offset !== void 0) {
379
+ result.offset = query.offset;
380
+ }
381
+ if (query.filter) {
382
+ const filterParams = query.filter;
383
+ for (const filterKey in filterParams) {
384
+ if (Object.prototype.hasOwnProperty.call(filterParams, filterKey) && filterParams[filterKey] !== void 0) {
385
+ const value = filterParams[filterKey];
386
+ if (Array.isArray(value)) {
387
+ result[`filter[${filterKey}]`] = value.join(",");
388
+ } else {
389
+ result[`filter[${filterKey}]`] = String(value);
390
+ }
391
+ }
391
392
  }
392
393
  }
393
394
  return result;
package/dist/index.js CHANGED
@@ -328,23 +328,24 @@ async function makeRequest(method, path, options, data, query) {
328
328
  // src/api/activity.ts
329
329
  function createFilterQuery(query) {
330
330
  if (!query) return {};
331
- const queryObj = query;
332
331
  const result = {};
333
- Object.keys(queryObj).forEach((key) => {
334
- if (key !== "filter") {
335
- result[key] = queryObj[key];
336
- }
337
- });
338
- if (queryObj.filter) {
339
- const filter = queryObj.filter;
340
- if (filter.platforms && Array.isArray(filter.platforms)) {
341
- result.platforms = filter.platforms.join(",");
342
- }
343
- if (filter.types && Array.isArray(filter.types)) {
344
- result.types = filter.types.join(",");
345
- }
346
- if (filter.timeframe) {
347
- result.timeframe = filter.timeframe;
332
+ if (query.limit !== void 0) {
333
+ result.limit = query.limit;
334
+ }
335
+ if (query.offset !== void 0) {
336
+ result.offset = query.offset;
337
+ }
338
+ if (query.filter) {
339
+ const filterParams = query.filter;
340
+ for (const filterKey in filterParams) {
341
+ if (Object.prototype.hasOwnProperty.call(filterParams, filterKey) && filterParams[filterKey] !== void 0) {
342
+ const value = filterParams[filterKey];
343
+ if (Array.isArray(value)) {
344
+ result[`filter[${filterKey}]`] = value.join(",");
345
+ } else {
346
+ result[`filter[${filterKey}]`] = String(value);
347
+ }
348
+ }
348
349
  }
349
350
  }
350
351
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crosspost/sdk",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "SDK for interacting with the Crosspost API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -10,40 +10,44 @@ import type {
10
10
  import { makeRequest, type RequestOptions } from '../core/request.ts';
11
11
 
12
12
  /**
13
- * Creates a modified query object with filter properties flattened
13
+ * Creates a modified query object with filter properties
14
14
  * @param query The original query object
15
- * @returns A new query object with filter properties flattened
15
+ * @returns A new query object with filter properties formatted as filter[key]=value.
16
16
  */
17
- function createFilterQuery<T>(query?: T): Record<string, unknown> {
17
+ function createFilterQuery<
18
+ T extends { filter?: Record<string, any>; limit?: number; offset?: number },
19
+ >(
20
+ query?: T,
21
+ ): Record<string, string | number | boolean> {
18
22
  if (!query) return {};
19
23
 
20
- const queryObj = query as Record<string, any>;
21
- const result: Record<string, unknown> = {};
24
+ const result: Record<string, string | number | boolean> = {};
22
25
 
23
- // Copy non-filter properties
24
- Object.keys(queryObj).forEach((key) => {
25
- if (key !== 'filter') {
26
- result[key] = queryObj[key];
27
- }
28
- });
29
-
30
- // Extract and flatten filter properties if they exist
31
- if (queryObj.filter) {
32
- const filter = queryObj.filter;
33
-
34
- if (filter.platforms && Array.isArray(filter.platforms)) {
35
- result.platforms = filter.platforms.join(',');
36
- }
37
-
38
- if (filter.types && Array.isArray(filter.types)) {
39
- result.types = filter.types.join(',');
40
- }
26
+ if (query.limit !== undefined) {
27
+ result.limit = query.limit;
28
+ }
29
+ if (query.offset !== undefined) {
30
+ result.offset = query.offset;
31
+ }
41
32
 
42
- if (filter.timeframe) {
43
- result.timeframe = filter.timeframe;
33
+ // e.g., query.filter = { timeframe: 'month', platforms: ['twitter'] }
34
+ // becomes result['filter[timeframe]'] = 'month', result['filter[platforms]'] = 'twitter'
35
+ if (query.filter) {
36
+ const filterParams = query.filter;
37
+ for (const filterKey in filterParams) {
38
+ if (
39
+ Object.prototype.hasOwnProperty.call(filterParams, filterKey) &&
40
+ filterParams[filterKey] !== undefined
41
+ ) {
42
+ const value = filterParams[filterKey];
43
+ if (Array.isArray(value)) {
44
+ result[`filter[${filterKey}]`] = value.join(',');
45
+ } else {
46
+ result[`filter[${filterKey}]`] = String(value);
47
+ }
48
+ }
44
49
  }
45
50
  }
46
-
47
51
  return result;
48
52
  }
49
53