### Basic PnWKit Setup and Nation Query (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Demonstrates the basic setup of the PnWKit library by setting an API key and performing a simple nation query to retrieve the nation's name. ```typescript import pnwkit from 'pnwkit'; // Set your API key pnwkit.setKey('your-api-key-here'); // Query a nation by ID const nations = await pnwkit.nationQuery( { id: [100541], first: 1 }, 'nation_name' ); console.log(`Nation: ${nations[0].nation_name}`); ``` -------------------------------- ### Install PnWKit using NPM Source: https://bsnk-dev.github.io/pnwkit/index This command installs the PnWKit library as a project dependency using npm. Ensure you have Node.js and npm installed on your system. ```bash npm i --save pnwkit ``` -------------------------------- ### Install PnWKit using npm Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt This command installs the PnWKit library. It's a prerequisite for using the library in your project. ```bash npm install pnwkit ``` -------------------------------- ### Test Configuration File for PnWKit Source: https://bsnk-dev.github.io/pnwkit/index Provides an example of the `testconfig.json` file required for running PnWKit's tests. This file should contain your private API key, which is necessary for the tests to authenticate with the Politics and War API. Ensure this file is not committed to public repositories. ```json { "apiKey": "xxxxx" } ``` -------------------------------- ### Fetch Nation Data using CommonJS and PnWKit Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt This example shows how to use PnWKit with CommonJS modules to fetch nation data. It includes setting the API key, executing a nation query, and iterating through the results to display nation names and scores. ```javascript const pnwkit = require('pnwkit'); pnwkit.setKey('your-api-key'); async function getNations() { const nations = await pnwkit.nationQuery( { first: 10 }, 'nation_name score' ); nations.forEach(nation => { console.log(`${nation.nation_name}: ${nation.score}`); }); } getNations(); ``` -------------------------------- ### Basic PnWKit Usage with setKey and nationQuery (TypeScript) Source: https://bsnk-dev.github.io/pnwkit/index Demonstrates how to import the PnWKit library, set your API key, and perform a basic nation query. It fetches nation data asynchronously and logs the nation's name. This example assumes you are using TypeScript for enhanced type safety. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('xxxxx'); const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `nation_name`); console.log(`Nation name: ${nations[0].nation_name}`); ``` -------------------------------- ### PnWKit Alliance Query (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt An example of querying alliance data using PnWKit, including alliance name, acronym, score, member count, and a list of its nations with their respective scores. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Query alliance with member data const alliances = await pnwkit.allianceQuery( { id: [7452], first: 1 }, ` name acronym score members nations { nation_name score } ` ); const alliance = alliances[0]; console.log(`${alliance.name} (${alliance.acronym})`); console.log(`Total score: ${alliance.score}`); console.log(`Members: ${alliance.members}`); alliance.nations.slice(0, 5).forEach(nation => { console.log(` ${nation.nation_name}: ${nation.score}`); }); ``` -------------------------------- ### PnWKit Nation Query - Simple Fields (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt An example of querying specific, simple fields for a nation using PnWKit, including ID, name, leader, score, cities, color, and alliance ID. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Query specific nation fields const nations = await pnwkit.nationQuery( { id: [100541], first: 1 }, ` id nation_name leader_name score cities color alliance_id ` ); console.log(`${nations[0].leader_name} leads ${nations[0].nation_name}`); console.log(`Score: ${nations[0].score}, Cities: ${nations[0].cities}`); ``` -------------------------------- ### Implement Query Caching - TypeScript Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Demonstrates how to implement caching for API queries using the `pnwkit.cached` function. This example caches the results of `nationQuery` for a specified duration (5 minutes), reducing redundant API calls for identical queries within that timeframe. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Create a cached version of nationQuery const cachedNationQuery = pnwkit.cached( pnwkit.nationQuery, 5 // Cache for 5 minutes ); // First call hits the API const nations1 = await cachedNationQuery( { id: [100541], first: 1 }, 'nation_name score' ); // Second call within 5 minutes returns cached data const nations2 = await cachedNationQuery( { id: [100541], first: 1 }, 'nation_name score' ); // Different parameters create separate cache entries const nations3 = await cachedNationQuery( { id: [200000], first: 1 }, 'nation_name score' ); console.log('All queries completed, second was cached'); ``` -------------------------------- ### Get Bounties Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_bountyquery Retrieves a list of bounties based on specified parameters and a GraphQL query. Supports optional pagination. ```APIDOC ## GET /api/endpoints/BountyQuery ### Description Retrieves a list of bounties with customizable parameters and a GraphQL query. It can optionally return pagination information. ### Method GET ### Endpoint /api/endpoints/BountyQuery ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The GraphQL query to retrieve bounty information. - **paginator** (boolean) - Optional - If true, returns paginator info along with the bounty data. ### Request Example ```json { "params": { "param1": "value1" }, "query": "query { bounties { id title } }", "paginator": false } ``` ### Response #### Success Response (200) - **Bounty[]** - An array of Bounty objects if paginator is false. - **BountyPaginator** - An object containing bounty data and pagination info if paginator is true. #### Response Example (without pagination) ```json { "example": [ { "id": "1", "title": "Example Bounty" } ] } ``` #### Response Example (with pagination) ```json { "example": { "data": [ { "id": "1", "title": "Example Bounty" } ], "pageInfo": { "hasNextPage": true, "endCursor": "cursor123" } } } ``` ``` -------------------------------- ### GET /api/endpoints/NationQuery Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_nationquery Retrieves a list of nations based on provided query parameters and optional pagination. ```APIDOC ## GET /api/endpoints/NationQuery ### Description Gets a list of nations. This endpoint allows you to query nation data with customizable parameters and optional pagination. ### Method GET ### Endpoint /api/endpoints/NationQuery ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, delivers the data in a paginated format. ### Request Example ```json { "params": { ... }, "query": "{ id name }", "paginator": false } ``` ### Response #### Success Response (200) - **Nations** (Nation[]) - The nations queried. - **NationPaginator** (NationPaginator) - The nations queried in a paginated format. #### Response Example ```json { "nations": [ { "id": "123", "name": "Example Nation" } ] } ``` ```json { "nationPaginator": { "data": [ { "id": "123", "name": "Example Nation" } ], "hasNextPage": true, "endCursor": "abc" } } ``` ``` -------------------------------- ### GET /api/endpoints/WarQuery Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_warquery Retrieves a list of wars based on provided parameters and a GraphQL query. Supports optional pagination. ```APIDOC ## GET /api/endpoints/WarQuery ### Description Gets a list of wars. You can specify query parameters, a GraphQL query to select the fields, and optionally enable pagination. ### Method GET ### Endpoint /api/endpoints/WarQuery ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, it will return paginator info along with the results. ### Request Example ```json { "params": {}, "query": "{\n wars {\n id\n name\n }\n}", "paginator": false } ``` ### Response #### Success Response (200) - **War[]** (array) - An array of War objects if paginator is false or not provided. - **WarPaginator** (object) - An object containing War data and pagination information if paginator is true. #### Response Example (with paginator: false) ```json [ { "id": "1", "name": "War 1" }, { "id": "2", "name": "War 2" } ] ``` #### Response Example (with paginator: true) ```json { "data": [ { "id": "1", "name": "War 1" } ], "paginatorInfo": { "count": 10, "currentPage": 1, "firstItem": 1, "hasMorePages": true, "lastItem": 10, "lastPage": 1, "perPage": 10, "total": 10 } } ``` ``` -------------------------------- ### Advanced Filtering and Data Retrieval with PnWKit Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt This example showcases advanced filtering capabilities in PnWKit for nation queries. It includes multiple filter parameters such as alliance IDs, score ranges, city counts, color, and ordering, along with a GraphQL query for specific fields. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Complex nation query with multiple filters const nations = await pnwkit.nationQuery( { first: 100, alliance_id: [7452, 7453], min_score: 2000, max_score: 10000, min_cities: 10, max_cities: 25, color: 'aqua', vmode: false, orderBy: { column: 'SCORE', order: 'DESC' } }, ` nation_name leader_name score cities soldiers tanks aircraft ships alliance { name acronym } ` ); nations.forEach((nation, index) => { console.log(`${index + 1}. ${nation.nation_name} - Score: ${nation.score}`); console.log(` Military: ${nation.soldiers} soldiers, ${nation.tanks} tanks, ${nation.aircraft} aircraft`); }); ``` -------------------------------- ### TreasureQuery - Get Treasures Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_treasurequery Retrieves a list of treasures based on a provided GraphQL query. ```APIDOC ## POST /api/endpoints/TreasureQuery ### Description This endpoint allows you to search for treasures by sending a GraphQL query. ### Method POST ### Endpoint /api/endpoints/TreasureQuery ### Parameters #### Request Body - **query** (string) - Required - The GraphQL query to retrieve treasure information. ### Request Example ```json { "query": "{\n treasures {\n id\n name\n description\n }\n}" } ``` ### Response #### Success Response (200) - **Treasure[]** - An array of treasure objects matching the query criteria. #### Response Example ```json { "treasures": [ { "id": "123", "name": "Golden Chest", "description": "A chest filled with gold coins." }, { "id": "456", "name": "Ancient Map", "description": "A map leading to a hidden treasure." } ] } ``` ``` -------------------------------- ### Using Multiple PnWKit Instances (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Shows how to create and manage multiple independent PnWKit instances, each with its own API key, useful for handling different accounts or bots. ```typescript import { Kit } from 'pnwkit'; // Create separate instances with different keys const botAccount = new Kit(); botAccount.setKey('bot-api-key'); const userAccount = new Kit(); userAccount.setKey('user-api-key'); // Each instance maintains separate state const botNations = await botAccount.nationQuery( { first: 10 }, 'nation_name' ); ``` -------------------------------- ### PnWKit Trade Query (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Demonstrates querying active trade offers using PnWKit, filtering by resource, buy/sell status, and amount, and displaying details of each trade. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Query active trade offers const trades = await pnwkit.tradeQuery( { first: 10, accepted: false, offer_resource: 'food', buy_or_sell: 'buy' }, ` id date offer_resource offer_amount buy_or_sell price accepted ` ); trades.forEach(trade => { console.log( `Trade #${trade.id}: ${trade.buy_or_sell} ${trade.offer_amount} ${trade.offer_resource} @ $${trade.price}` ); }); ``` -------------------------------- ### GET /api/endpoints/BankRecordsQuery Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_bankrecordsquery Retrieves a list of bank records based on provided parameters and a GraphQL query. Supports optional pagination. ```APIDOC ## GET /api/endpoints/BankRecordsQuery ### Description Gets a list of bank records using a GraphQL query and optional parameters. The endpoint can return either a list of bank records or a paginated response. ### Method GET ### Endpoint /api/endpoints/BankRecordsQuery ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, it will return paginator info. Defaults to false. ### Request Example ```json { "params": { ... }, "query": "{ bankRecords { id name amount } }", "paginator": false } ``` ### Response #### Success Response (200) - **Bankrec[]**: An array of bank record objects if paginator is false. - **BankrecPaginator**: A paginator object if paginator is true. #### Response Example (paginator: false) ```json [ { "id": "123", "name": "Example Bank", "amount": 1000.50 } ] ``` #### Response Example (paginator: true) ```json { "data": [ { "id": "123", "name": "Example Bank", "amount": 1000.50 } ], "hasNextPage": true, "endCursor": "cursor123" } ``` ``` -------------------------------- ### GET /api/endpoints/WarAttackQuery Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_warattackquery Retrieves a list of war attacks. Supports custom GraphQL queries and pagination. ```APIDOC ## GET /api/endpoints/WarAttackQuery ### Description Gets a list of war attacks. You can specify custom GraphQL queries and pagination options. ### Method GET ### Endpoint /api/endpoints/WarAttackQuery ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, it will return paginator info. ### Request Example ```json { "params": { "warId": "someWarId", "attacker": "someAttacker" }, "query": "{ id name }", "paginator": false } ``` ### Response #### Success Response (200) - **WarAttack[]** (array) - An array of war attack objects if paginator is false. - **WarAttackPaginator** (object) - An object containing war attack data and pagination info if paginator is true. #### Response Example (paginator: false) ```json [ { "id": "attack1", "name": "First Attack" } ] ``` #### Response Example (paginator: true) ```json { "data": [ { "id": "attack1", "name": "First Attack" } ], "paginatorInfo": { "count": 1, "currentPage": 1, "hasMorePages": false, "lastPage": 1, "nextPageUrl": null, "perPage": 15, "previousPageUrl": null, "total": 1 } } ``` ``` -------------------------------- ### PnWKit Nation Query - With Pagination (TypeScript) Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Demonstrates how to enable and use pagination in PnWKit nation queries, retrieving paginator information and paginated data for nations matching specific score criteria. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Enable pagination by passing true as third parameter const result = await pnwkit.nationQuery( { first: 100, page: 1, min_score: 2000, max_score: 5000 }, ` nation_name score alliance { name } `, true // Enable pagination ); console.log(`Current page: ${result.paginatorInfo.currentPage}`); console.log(`Total pages: ${result.paginatorInfo.lastPage}`); console.log(`Total nations: ${result.paginatorInfo.total}`); result.data.forEach(nation => { console.log(`${nation.nation_name} - ${nation.alliance?.name || 'None'}`); }); ``` -------------------------------- ### Query Cities with Infrastructure - TypeScript Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Retrieves a list of cities, optionally filtering by minimum infrastructure, and includes detailed infrastructure and power generation information using `cityQuery`. An API key is required. The output provides city name, infrastructure count, and total power generated. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Query cities with infrastructure details const cities = await pnwkit.cityQuery( { first: 50, min_infrastructure: 1000 }, ` id name nation_id infrastructure land powered coal_power oil_power nuclear_power wind_power ` ); cities.forEach(city => { const totalPower = city.coal_power + city.oil_power + city.nuclear_power + city.wind_power; console.log(`${city.name}: ${city.infrastructure} infra, ${totalPower} power`); }); ``` -------------------------------- ### Using PnWKit Kit Class for Multiple Instances (TypeScript) Source: https://bsnk-dev.github.io/pnwkit/index Demonstrates how to use the `Kit` class export from PnWKit to manage multiple independent instances of the API client. This is useful if you need to run several PnWKit instances concurrently, potentially with different configurations or API keys. ```typescript import {Kit} from 'pnwkit'; const pnwkit = new Kit(); pnwkit.setKey('xxxx'); // queries... ``` -------------------------------- ### Get War List (TypeScript) Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_warquery Retrieves a list of wars with specified parameters and a GraphQL query. This function is designed for basic data retrieval and does not include pagination information. Ensure 'Parameters' and 'War' types are correctly defined. ```typescript import { Parameters, War } from "./types"; /** * Gets a list of wars. * @param params Query parameters to customize your results. * @param query The graphql query to get info with. * @param paginator If true, it will return paginator info (optional, defaults to false). * @returns Promise A promise that resolves to an array of War objects. */ async function getWarList(params: Parameters, query: string, paginator?: false): Promise { // Implementation details for fetching war list return []; // Placeholder } ``` -------------------------------- ### Kit Class Constructor in PNWKit Source: https://bsnk-dev.github.io/pnwkit/classes/index Initializes a new instance of the Kit class. This is the main application class for interacting with the PNWKit functionalities. ```typescript new Kit(): Kit /** * Initializes a new Kit instance * @returns Kit */ ``` -------------------------------- ### Querying Bounties Source: https://bsnk-dev.github.io/pnwkit/modules/interfaces_politicsandwargraphql Retrieve a list of bounties with options to filter by amount range and nation, sort results, and paginate. ```APIDOC ## GET /query/bounties ### Description Retrieves a list of bounties. Supports filtering by minimum and maximum bounty amounts, nation ID, sorting, and pagination. ### Method GET ### Endpoint /query/bounties ### Query Parameters - **first** (Int) - Optional - The maximum number of results to return. - **max_amount** (Float) - Optional - The maximum bounty amount to filter by. - **min_amount** (Float) - Optional - The minimum bounty amount to filter by. - **nation_id** (Int[]) - Optional - An array of nation IDs to filter the bounties by. - **orderBy** (QueryBountiesOrderByOrderByClause[]) - Optional - An array of objects specifying the sorting order for the results. - **page** (Int) - Optional - The page number to retrieve. ### Request Example ```json { "query": "{\n bounties(first: 10, min_amount: 100.0, nation_id: [5], orderBy: { column: AMOUNT, order: DESC }) {\n id\n amount\n nation { id name }\n }\n}" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **bounties** (Array) - A list of bounty objects. - **id** (Int) - The unique identifier for the bounty. - **amount** (Float) - The bounty amount. - **nation** (Object) - Details of the nation associated with the bounty. - **id** (Int) - The nation's ID. - **name** (String) - The nation's name. #### Response Example ```json { "data": { "bounties": [ { "id": 201, "amount": 150.50, "nation": {"id": 5, "name": "Nation X"} } ] } } ``` ``` -------------------------------- ### Set API Key Method Source: https://bsnk-dev.github.io/pnwkit/classes/index Sets the API key for the PNWKit instance. ```APIDOC ## POST /api/set-key ### Description Sets the API key for the PNWKit instance. This is typically used for authentication or authorization purposes. ### Method POST ### Endpoint /api/set-key ### Parameters #### Request Body - **key** (string) - Required - The API key to set. ### Request Example ```json { "key": "YOUR_API_KEY" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the key was set. #### Response Example ```json { "message": "API key set successfully." } ``` ``` -------------------------------- ### Querying Cities Source: https://bsnk-dev.github.io/pnwkit/modules/interfaces_politicsandwargraphql Retrieve a list of cities with options to filter by ID and nation, sort results, and paginate. ```APIDOC ## GET /query/cities ### Description Retrieves a list of cities. Supports filtering by city ID and nation ID, sorting, and pagination. ### Method GET ### Endpoint /query/cities ### Query Parameters - **first** (Int) - Optional - The maximum number of results to return. - **id** (Int[]) - Optional - An array of city IDs to filter by. - **nation_id** (Int[]) - Optional - An array of nation IDs to filter the cities by. - **orderBy** (QueryCitiesOrderByOrderByClause[]) - Optional - An array of objects specifying the sorting order for the results. - **page** (Int) - Optional - The page number to retrieve. ### Request Example ```json { "query": "{\n cities(first: 5, nation_id: [6], orderBy: { column: NAME, order: ASC }) {\n id\n name\n nation { id name }\n }\n}" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **cities** (Array) - A list of city objects. - **id** (Int) - The unique identifier for the city. - **name** (String) - The name of the city. - **nation** (Object) - Details of the nation the city belongs to. - **id** (Int) - The nation's ID. - **name** (String) - The nation's name. #### Response Example ```json { "data": { "cities": [ { "id": 301, "name": "City Alpha", "nation": {"id": 6, "name": "Nation Y"} } ] } } ``` ``` -------------------------------- ### Get Paginated War List (TypeScript) Source: https://bsnk-dev.github.io/pnwkit/modules/api_endpoints_warquery Retrieves a paginated list of wars, including pagination details. This function requires the 'paginator' option to be set to true. It returns a 'WarPaginator' object containing both the war data and pagination metadata. Ensure 'Parameters', 'WarPaginator' types are correctly defined. ```typescript import { Parameters, WarPaginator } from "./types"; /** * Gets a paginated list of wars with additional pagination information. * @param params Query parameters to customize your results. * @param query The graphql query to get info with. * @param paginator Set to true to enable pagination and return paginator info. * @returns Promise A promise that resolves to a WarPaginator object. */ async function getPaginatedWarList(params: Parameters, query: string, paginator: true): Promise { // Implementation details for fetching paginated war list return { wars: [], pageInfo: { hasNextPage: false, endCursor: null } }; // Placeholder } ``` -------------------------------- ### Alliance API Source: https://bsnk-dev.github.io/pnwkit/classes/index Retrieves a list of alliances with options for pagination and custom GraphQL queries. ```APIDOC ## GET /api/alliances ### Description Retrieves a list of alliances. Supports custom GraphQL queries and pagination. ### Method GET ### Endpoint /api/alliances ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to execute. - **paginator** (boolean) - Optional - If true, returns paginated results. ### Request Example ```json { "query": "{ id name }", "paginator": false } ``` ### Response #### Success Response (200) - **alliances** (Alliance[]) - A list of alliance objects. - **paginator** (AlliancePaginator) - Pagination information if paginator is true. #### Response Example ```json { "alliances": [ { "id": "123", "name": "Example Alliance" } ] } ``` ``` -------------------------------- ### setKey Method in PNWKit Source: https://bsnk-dev.github.io/pnwkit/classes/index This method is used to set the API key for authentication. It is a fundamental method for initializing the Kit instance's access. ```typescript setKey(apiKey: string): void /** * Sets the API key for the Kit instance * @param apiKey The API key to set */ ``` -------------------------------- ### Nations API Source: https://bsnk-dev.github.io/pnwkit/classes/index Retrieves a list of nations, with options for pagination. ```APIDOC ## GET /api/nations ### Description Retrieves a list of nations. Supports pagination. ### Method GET ### Endpoint /api/nations ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to fetch nation data. - **paginator** (boolean) - Optional - If true, returns paginated data. ### Request Example ```json { "query": "{ nations { id name leader } }" } ``` ### Response #### Success Response (200) - **nations** (Nation[]) - A list of nation objects. - **paginator** (NationPaginator) - Paginator information if requested. #### Response Example ```json { "nations": [ { "id": "1", "name": "Nation A", "leader": "Leader A" } ] } ``` ``` -------------------------------- ### Bounty API Source: https://bsnk-dev.github.io/pnwkit/classes/index Provides access to bounty information, allowing for custom queries and pagination. ```APIDOC ## GET /api/bounties ### Description Retrieves a list of bounties. Supports custom GraphQL queries and pagination. ### Method GET ### Endpoint /api/bounties ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to execute. - **paginator** (boolean) - Optional - If true, returns paginated results. ### Request Example ```json { "query": "{ id nationId amount }", "paginator": false } ``` ### Response #### Success Response (200) - **bounties** (Bounty[]) - A list of bounty objects. - **paginator** (BountyPaginator) - Pagination information if paginator is true. #### Response Example ```json { "bounties": [ { "id": "bounty1", "nationId": "nation123", "amount": 500 } ] } ``` ``` -------------------------------- ### Wars API Source: https://bsnk-dev.github.io/pnwkit/classes/index Retrieves a list of wars, with options for pagination. ```APIDOC ## GET /api/wars ### Description Retrieves a list of wars. Supports pagination. ### Method GET ### Endpoint /api/wars ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to fetch war data. - **paginator** (boolean) - Optional - If true, returns paginated data. ### Request Example ```json { "query": "{ wars { id attacker { name } defender { name } status } }" } ``` ### Response #### Success Response (200) - **wars** (War[]) - A list of war objects. - **paginator** (WarPaginator) - Paginator information if requested. #### Response Example ```json { "wars": [ { "id": "1", "attacker": { "name": "Attacking Nation" }, "defender": { "name": "Defending Nation" }, "status": "Ongoing" } ] } ``` ``` -------------------------------- ### Query Colors - TypeScript Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Fetches color trade bloc information, including the color name and its turn bonus percentage, using the `colorQuery` function. This query requires an API key. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Query color trade blocs const colors = await pnwkit.colorQuery(` color turn_bonus `); colors.forEach(color => { console.log(`${color.color} bloc: ${color.turn_bonus}% turn bonus`); }); ``` -------------------------------- ### Fetch Trade Prices - TypeScript Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt Retrieves current market prices for a list of specified resources using the `tradePricesQuery` function. It requires an API key and returns an object containing the prices for each resource. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Get current market prices const prices = await pnwkit.tradePricesQuery( { first: 50 }, ` food coal oil uranium iron bauxite lead gasoline munitions steel aluminum ` ); const currentPrices = prices[0]; console.log('Current Market Prices:'); console.log(`Food: $${currentPrices.food}`); console.log(`Oil: $${currentPrices.oil}`); console.log(`Uranium: $${currentPrices.uranium}`); console.log(`Steel: $${currentPrices.steel}`); ``` -------------------------------- ### PnwKit Usage with require() (JavaScript) Source: https://bsnk-dev.github.io/pnwkit/index Shows how to import and use the PnWKit library in a traditional CommonJS environment using `require()`. This is suitable for older Node.js projects or when not using ES module syntax. The functionality remains the same as with ES module imports. ```javascript const pnwkit = require('pnwkit'); pnwkit.setKey('xxxx'); // etc.. ``` -------------------------------- ### Track and Manage API Rate Limits with PnWKit Source: https://context7.com/context7/bsnk-dev_github_io_pnwkit/llms.txt This snippet demonstrates how to monitor and conditionally execute queries based on the API's rate limit status using PnWKit. It shows how to access limit, remaining requests, reset time, and seconds until reset. ```typescript import pnwkit from 'pnwkit'; pnwkit.setKey('your-api-key'); // Make a query await pnwkit.nationQuery({ first: 1 }, 'nation_name'); // Check rate limit status console.log(`Limit: ${pnwkit.rateLimit.limit}`); console.log(`Remaining: ${pnwkit.rateLimit.remaining}`); console.log(`Resets at: ${new Date(pnwkit.rateLimit.reset * 1000).toLocaleString()}`); console.log(`Resets in: ${pnwkit.rateLimit.resetAfterSeconds} seconds`); // Conditional query based on rate limit if (pnwkit.rateLimit.remaining > 10) { await pnwkit.nationQuery({ first: 100 }, 'nation_name score'); } else { console.log('Rate limit low, waiting...'); await new Promise(resolve => setTimeout(resolve, pnwkit.rateLimit.resetAfterSeconds * 1000) ); } ``` -------------------------------- ### Querying Baseball Games Source: https://bsnk-dev.github.io/pnwkit/modules/interfaces_politicsandwargraphql Retrieve a list of baseball games with options to filter by team, sort results, and paginate through the data. ```APIDOC ## GET /query/baseball_games ### Description Retrieves a list of baseball games. Supports filtering by team ID, sorting by various criteria, and pagination. ### Method GET ### Endpoint /query/baseball_games ### Query Parameters - **first** (Int) - Optional - The maximum number of results to return. - **orderBy** (QueryBaseballGamesOrderByOrderByClause[]) - Optional - An array of objects specifying the sorting order for the results. - **page** (Int) - Optional - The page number to retrieve. - **team_id** (Int[]) - Optional - An array of team IDs to filter the games by. ### Request Example ```json { "query": "{\n baseball_games(first: 10, team_id: [1, 2], orderBy: { column: SCORE, order: ASC }) {\n id\n home_team { id name }\n away_team { id name }\n score\n }\n}" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **baseball_games** (Array) - A list of baseball game objects. - **id** (Int) - The unique identifier for the game. - **home_team** (Object) - Details of the home team. - **id** (Int) - The team's ID. - **name** (String) - The team's name. - **away_team** (Object) - Details of the away team. - **id** (Int) - The team's ID. - **name** (String) - The team's name. - **score** (Int) - The score of the game. #### Response Example ```json { "data": { "baseball_games": [ { "id": 1, "home_team": {"id": 1, "name": "Team A"}, "away_team": {"id": 2, "name": "Team B"}, "score": 5 } ] } } ``` ``` -------------------------------- ### Trade Prices API Source: https://bsnk-dev.github.io/pnwkit/classes/index Retrieves a list of trade prices, with options for pagination. ```APIDOC ## GET /api/trade-prices ### Description Retrieves a list of trade prices. Supports pagination. ### Method GET ### Endpoint /api/trade-prices ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to fetch trade price data. - **paginator** (boolean) - Optional - If true, returns paginated data. ### Request Example ```json { "query": "{ tradePrices { id item { name } price } }" } ``` ### Response #### Success Response (200) - **tradePrices** (Tradeprice[]) - A list of trade price objects. - **paginator** (TradepricePaginator) - Paginator information if requested. #### Response Example ```json { "tradePrices": [ { "id": "1", "item": { "name": "Sword" }, "price": 1000 } ] } ``` ``` -------------------------------- ### Query Bounties with pnwkit Source: https://bsnk-dev.github.io/pnwkit/classes/api Fetches bounty data via the pnwkit. You can specify query parameters and a GraphQL query. The 'paginator' option allows for paginated retrieval of bounty information. ```typescript bountyQuery: { (params: Parameters, query: string, paginator?: false): Promise; (params: Parameters, query: string, paginator: true): Promise } = ... ``` -------------------------------- ### Bank Records API Source: https://bsnk-dev.github.io/pnwkit/classes/index Fetches bank records with support for custom queries and pagination. ```APIDOC ## GET /api/bankrecords ### Description Retrieves a list of bank records. Supports custom GraphQL queries and pagination. ### Method GET ### Endpoint /api/bankrecords ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to execute. - **paginator** (boolean) - Optional - If true, returns paginated results. ### Request Example ```json { "query": "{ id amount }", "paginator": false } ``` ### Response #### Success Response (200) - **bankRecords** (Bankrec[]) - A list of bank record objects. - **paginator** (BankrecPaginator) - Pagination information if paginator is true. #### Response Example ```json { "bankRecords": [ { "id": "rec1", "amount": 1000 } ] } ``` ``` -------------------------------- ### Bounty Query API Source: https://bsnk-dev.github.io/pnwkit/classes/api Retrieves a list of bounties. Supports filtering and pagination. ```APIDOC ## GET /api/bounties ### Description Retrieves a list of bounties. Supports filtering and pagination. ### Method GET ### Endpoint /api/bounties ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, returns data in a paginated format. ### Response #### Success Response (200) - **bounties** (Bounty[]) - A list of bounties. - **bountyPaginator** (BountyPaginator) - A paginated list of bounties. #### Response Example ```json { "bounties": [ { "id": "string", "targetNationId": "string", "amount": 5000 } ] } ``` OR ```json { "bountyPaginator": { "data": [ { "id": "string", "targetNationId": "string", "amount": 5000 } ], "paginatorInfo": { "count": 10, "currentPage": 1, "firstItem": 1, "hasMorePages": true, "lastItem": 10, "lastPage": 5, "nextPageUrl": "/api/bounties?page=2", "perPage": 10, "prevPageUrl": null, "total": 50 } } } ``` ``` -------------------------------- ### City API Source: https://bsnk-dev.github.io/pnwkit/classes/index Fetches city data with options for custom GraphQL queries and pagination. ```APIDOC ## GET /api/cities ### Description Retrieves a list of cities. Supports custom GraphQL queries and pagination. ### Method GET ### Endpoint /api/cities ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query to execute. - **paginator** (boolean) - Optional - If true, returns paginated results. ### Request Example ```json { "query": "{ id name population }", "paginator": false } ``` ### Response #### Success Response (200) - **cities** (City[]) - A list of city objects. - **paginator** (CityPaginator) - Pagination information if paginator is true. #### Response Example ```json { "cities": [ { "id": "city1", "name": "Metropolis", "population": 100000 } ] } ``` ``` -------------------------------- ### Query Alliances with pnwkit Source: https://bsnk-dev.github.io/pnwkit/classes/api Fetches a list of alliances using the pnwkit. It accepts query parameters and a GraphQL query string. The optional 'paginator' argument can be set to 'true' to receive paginated results. ```typescript allianceQuery: { (params: Parameters, query: string, paginator?: false): Promise; (params: Parameters, query: string, paginator: true): Promise } = ... ``` -------------------------------- ### Paginated PnWKit nationQuery (TypeScript) Source: https://bsnk-dev.github.io/pnwkit/index Shows how to perform a paginated query with PnWKit to retrieve more results than the default. It enables pagination and accesses the paginator information along with the nation data. This is useful for fetching large datasets. ```typescript const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `nation_name`, true); console.log(`Nation name: ${nations.data[0].nation_name} name}, current page: ${nations.paginatorInfo.currentPage}`); ``` -------------------------------- ### Alliance Query API Source: https://bsnk-dev.github.io/pnwkit/classes/api Retrieves a list of alliances. Supports filtering and pagination. ```APIDOC ## GET /api/alliances ### Description Retrieves a list of alliances. Supports filtering and pagination. ### Method GET ### Endpoint /api/alliances ### Parameters #### Query Parameters - **params** (Parameters) - Required - Query parameters to customize your results. - **query** (string) - Required - The graphql query to get info with. - **paginator** (boolean) - Optional - If true, returns data in a paginated format. ### Response #### Success Response (200) - **alliance** (Alliance[]) - A list of alliances. - **alliancePaginator** (AlliancePaginator) - A paginated list of alliances. #### Response Example ```json { "alliance": [ { "id": "string", "name": "string" } ] } ``` OR ```json { "alliancePaginator": { "data": [ { "id": "string", "name": "string" } ], "paginatorInfo": { "count": 10, "currentPage": 1, "firstItem": 1, "hasMorePages": true, "lastItem": 10, "lastPage": 5, "nextPageUrl": "/api/alliances?page=2", "perPage": 10, "prevPageUrl": null, "total": 50 } } } ``` ```