@pinta365/blizzard_api 0.3.5 → 0.3.7

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/README.md CHANGED
@@ -1,10 +1,13 @@
1
- # BLIZZARD_API
1
+ # BLIZZARD API
2
2
 
3
3
  [![JSR Version](https://jsr.io/badges/@pinta365/blizzard-api)](https://jsr.io/@pinta365/blizzard-api)
4
4
 
5
5
  Start of what will cover the whole Blizzard Battle.net API when its done.
6
6
 
7
- Link to the module on [JSR](https://jsr.io/@pinta365/blizzard-api)
7
+ Available as:
8
+
9
+ - ESM module: [JSR](https://jsr.io/@pinta365/blizzard-api)
10
+ - CommonJS module: [NPM](https://www.npmjs.com/package/@pinta365/blizzard_api)
8
11
 
9
12
  ## WORK IN PROGRESS
10
13
 
@@ -19,6 +22,7 @@ to implement authorization code flow also.
19
22
  | **World of Warcraft:** Profile APIs | ✅ | |
20
23
  | | | |
21
24
  | **World of Warcraft Classic:** Game Data APIs | | |
25
+ | **World of Warcraft Classic:** Profile APIs | | |
22
26
  | | | |
23
27
  | **Diablo III:** Community APIs | ✅ | Missing profile endpoints |
24
28
  | **Diablo III:** Game Data APIs | ✅ | |
@@ -28,7 +32,25 @@ to implement authorization code flow also.
28
32
  | **StarCraft II:** Community APIs | | |
29
33
  | **StarCraft II:** Game Data APIs | ✅ | |
30
34
 
31
- ## Example
35
+ ## ⚡️ Quickstart
36
+
37
+ **Installation**
38
+
39
+ ```bash
40
+ # Deno
41
+ deno add @pinta365/blizzard-api
42
+
43
+ # Bun
44
+ bunx jsr add @pinta365/blizzard-api
45
+
46
+ # Node.js
47
+ npx jsr add @pinta365/blizzard-api
48
+
49
+ # NPM (CommonJS)
50
+ npm install @pinta365/blizzard_api --save
51
+ ```
52
+
53
+ **Basic Usage (ESM)**
32
54
 
33
55
  ```javascript
34
56
  import * as blizzardAPI from "@pinta365/blizzard-api";
@@ -43,12 +65,16 @@ blizzardAPI.setup({
43
65
  locale: "en_GB",
44
66
  });
45
67
 
46
- try {
47
- const sword = await blizzardAPI.wow.item(33791);
48
- console.log(sword);
49
- } catch (error) {
50
- console.log(error);
51
- }
68
+ const sword = await blizzardAPI.wow.item(33791);
69
+ console.log(sword);
70
+ ```
71
+
72
+ **Basic Usage (CommonJS)**
73
+
74
+ ```javascript
75
+ const blizzardAPI = require("@pinta365/blizzard_api");
76
+
77
+ // Use blizzardAPI the same way as in the previous example.
52
78
  ```
53
79
 
54
80
  ## Issues
package/esm/mod.d.ts CHANGED
@@ -2,4 +2,5 @@ import { authenticate, setup } from "./src/shared/index.js";
2
2
  import * as wow from "./src/wow/index.js";
3
3
  import * as hearthstone from "./src/hearthstone/index.js";
4
4
  import * as sc2 from "./src/starcraft2/index.js";
5
- export { authenticate, hearthstone, sc2, setup, wow };
5
+ import * as errors from "./src/shared/errors.js";
6
+ export { authenticate, errors, hearthstone, sc2, setup, wow };
package/esm/mod.js CHANGED
@@ -2,4 +2,5 @@ import { authenticate, setup } from "./src/shared/index.js";
2
2
  import * as wow from "./src/wow/index.js";
3
3
  import * as hearthstone from "./src/hearthstone/index.js";
4
4
  import * as sc2 from "./src/starcraft2/index.js";
5
- export { authenticate, hearthstone, sc2, setup, wow };
5
+ import * as errors from "./src/shared/errors.js";
6
+ export { authenticate, errors, hearthstone, sc2, setup, wow };
@@ -39,5 +39,8 @@ export async function request(requestOptions) {
39
39
  if (response.ok) {
40
40
  return await response.json();
41
41
  }
42
- throw new APIError("Problem fetching data from API", response.status, response.statusText);
42
+ const errorData = await response.json();
43
+ const statusCode = errorData.code || response.status;
44
+ const errorMessage = JSON.stringify(errorData) || "Problem fetching data from API";
45
+ throw new APIError(errorMessage, statusCode, response.statusText);
43
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinta365/blizzard_api",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "TS library to interact with the Blizzard Battle.net API. World of Warcraft, World of Warcraft Classic, StarCraft 2, Diablo 3, Hearthstone.",
5
5
  "keywords": [
6
6
  "blizzard",
package/script/mod.d.ts CHANGED
@@ -2,4 +2,5 @@ import { authenticate, setup } from "./src/shared/index.js";
2
2
  import * as wow from "./src/wow/index.js";
3
3
  import * as hearthstone from "./src/hearthstone/index.js";
4
4
  import * as sc2 from "./src/starcraft2/index.js";
5
- export { authenticate, hearthstone, sc2, setup, wow };
5
+ import * as errors from "./src/shared/errors.js";
6
+ export { authenticate, errors, hearthstone, sc2, setup, wow };
package/script/mod.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.wow = exports.setup = exports.sc2 = exports.hearthstone = exports.authenticate = void 0;
26
+ exports.wow = exports.setup = exports.sc2 = exports.hearthstone = exports.errors = exports.authenticate = void 0;
27
27
  const index_js_1 = require("./src/shared/index.js");
28
28
  Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return index_js_1.authenticate; } });
29
29
  Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return index_js_1.setup; } });
@@ -33,3 +33,5 @@ const hearthstone = __importStar(require("./src/hearthstone/index.js"));
33
33
  exports.hearthstone = hearthstone;
34
34
  const sc2 = __importStar(require("./src/starcraft2/index.js"));
35
35
  exports.sc2 = sc2;
36
+ const errors = __importStar(require("./src/shared/errors.js"));
37
+ exports.errors = errors;
@@ -42,6 +42,9 @@ async function request(requestOptions) {
42
42
  if (response.ok) {
43
43
  return await response.json();
44
44
  }
45
- throw new errors_js_1.APIError("Problem fetching data from API", response.status, response.statusText);
45
+ const errorData = await response.json();
46
+ const statusCode = errorData.code || response.status;
47
+ const errorMessage = JSON.stringify(errorData) || "Problem fetching data from API";
48
+ throw new errors_js_1.APIError(errorMessage, statusCode, response.statusText);
46
49
  }
47
50
  exports.request = request;