tweaselORG / parse-tunes

Library for fetching select data on iOS apps from the Apple App Store via undocumented internal iTunes APIs.
MIT License
10 stars 1 forks source link

Top charts: `selectedChart` can be `null` #9

Open baltpeter opened 1 year ago

baltpeter commented 1 year ago

I got this error:

/home/benni/coding/JS/tweasel/experiments/monkey-july-2023/node_modules/parse-tunes/dist/src/top-charts.ts:72
}
^

TypeError: Cannot read properties of null (reading 'adamIds')
    at $9b29393ae56a7950$export$91a6a7f4f6f8ec4f (/home/benni/coding/JS/tweasel/experiments/monkey-july-2023/node_modules/parse-tunes/dist/src/top-charts.ts:72:1)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 25)
    at <anonymous> (/home/benni/coding/JS/tweasel/experiments/monkey-july-2023/app-list.ts:29:9)

Node.js v18.16.1

when running this code:

import { fetchTopApps, charts, countries, genres } from 'parse-tunes';

(async () => {
    const iosEntries = (
        await Promise.all(
            Object.values(genres).map((genre) =>
                fetchTopApps({
                    genre,
                    chart: charts.topFreeIphone,
                    country: countries.DE,
                })
            )
        )
    )
        .map((l) => l.slice(0, 30))
        .flat();
})();

The problem is that selectedChart can be null. Here's what res.pageData.segmentedControl.segments[0].pageData looks like for the failing chart:

{
  metricsBase: {
    pageType: 'TopChartsPage',
    pageId: '6025',
    pageDetails: 'Stickers',
    page: 'TopChartsPage_6025',
    serverInstance: '3311305',
    storeFrontHeader: '143443,29',
    language: '4',
    storeFront: '143443'
  },
  topCharts: [],
  selectedChart: null,
  pageTitle: 'Charts',
  genre: {
    name: 'Sticker',
    id: '6025',
    url: 'https://itunes.apple.com/de/genre?id=6025'
  },
  categoryList: {
    url: 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?cc=de&genreId=36&popId=27',
    chartUrl: 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?cc=de&genreId=36&popId=30',
    name: 'App Store',
    shortName: 'App Store',
    buttonName: 'Kategorien',
    genreId: '36',
    art: {
      token: 'Purple126/v4/a3/b9/c4/a3b9c469-999c-af3f-c609-cdda97635cc8/AppIcon-1x_U007emarketing-0-7-0-85-220.png',
      pft: 'LargeApplicationIcon'
    },
    artwork: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    kind: 'iosSoftware',
    parentCategoryLabel: 'Alle Kategorien',
    children: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object]
    ]
  },
  componentName: 'top_charts_page',
  metrics: { config: {}, fields: {} }
}