mtg-playerinfo 1.5.1 → 1.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtg-playerinfo",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "A simple NPM module and CLI tool to pull Magic: The Gathering player data from various sources",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -8,9 +8,13 @@ class TopdeckFetcher {
8
8
  const url = `https://topdeck.gg/profile/${cleanHandle}`
9
9
  try {
10
10
  const { data } = await httpClient.request(url)
11
+ const htmlStr = typeof data === 'string' ? data : ''
11
12
  const playerInfo = this.parseHtml(data, url, cleanHandle)
12
13
 
13
- const internalIdMatch = data.match(/https:\/\/topdeck\.gg\/profile\/([a-zA-Z0-9]+)\/stats/) || data.match(/const playerId = "([a-zA-Z0-9]+)";/)
14
+ const internalIdMatch = htmlStr.match(/https:\/\/topdeck\.gg\/profile\/([a-zA-Z0-9]+)\/stats/) ||
15
+ htmlStr.match(/const playerId = "([a-zA-Z0-9]+)";/) ||
16
+ htmlStr.match(/window\.PROFILE_PLAYER_ID\s*=\s*"([a-zA-Z0-9]+)"/) ||
17
+ htmlStr.match(/<meta name="player-id" content="([a-zA-Z0-9]+)"/)
14
18
  const internalId = internalIdMatch ? internalIdMatch[1] : null
15
19
 
16
20
  if (internalId) {
@@ -22,6 +22,28 @@ test('TopdeckFetcher: parseHtml extracts info from fixture', () => {
22
22
  assert.match(result.record, /^\d+-\d+-\d+|–$/)
23
23
  })
24
24
 
25
+ test('TopdeckFetcher: extracts internalId from meta-tag', async (t) => {
26
+ const fetcher = new TopdeckFetcher()
27
+ const mockRequest = t.mock.method(httpClient, 'request')
28
+
29
+ const html = '<meta name="player-id" content="metaID123"/><html></html>'
30
+ const expectedId = 'metaID123'
31
+
32
+ mockRequest.mock.mockImplementation(async (url) => {
33
+ if (url.includes('/stats')) {
34
+ return { data: {}, status: 200 }
35
+ }
36
+ return { data: html, status: 200 }
37
+ })
38
+
39
+ await fetcher.fetchById('test')
40
+ const statsCall = mockRequest.mock.calls.find(call => call.arguments[0].includes('/stats'))
41
+ assert.ok(statsCall, 'Should have called fetchStats')
42
+ assert.ok(statsCall.arguments[0].includes(expectedId), `URL should contain ${expectedId}`)
43
+
44
+ mockRequest.mock.restore()
45
+ })
46
+
25
47
  test('TopdeckFetcher: parseHtml handles missing stats and different DOM shapes', () => {
26
48
  const fetcher = new TopdeckFetcher()
27
49
  const html = `