{"_id":"@artemisdigital/unitcommander-sdk","_rev":"3-a8ca38d4deb69e78f887327fc1cb516e","name":"@artemisdigital/unitcommander-sdk","dist-tags":{"latest":"0.3.0"},"versions":{"0.0.1":{"name":"@artemisdigital/unitcommander-sdk","version":"0.0.1","description":"UnitCommander Official Javascript SDK","keywords":[],"type":"module","private":false,"author":{"name":"Unit Commander Team"},"license":"","engines":{"node":"<16"},"main":"dist/index.js","module":"dist/index.modern.js","source":"src/index.tsx","devDependencies":{"@types/express":"^4.17.21","@typescript-eslint/eslint-plugin":"^6.13.1","eslint":"^8.54.0","prettier":"^3.1.0","typescript":"^5.3.2"},"dependencies":{"axios":"^1.6.2","express":"^4.18.2"},"types":"./dist/index.d.ts","_id":"@artemisdigital/unitcommander-sdk@0.0.1","_nodeVersion":"20.3.1","_npmVersion":"9.7.2","dist":{"integrity":"sha512-FVNdiop+KY2OCZugt/Wew6MII2aYENn3sXk/r1qmLr4Mx4nPMgr+luAjMP0oOJgoqHiCIjVGsU0kyLxhNuPrpA==","shasum":"536e75b8560f42e48c5f2ffb16f8719adfa88848","tarball":"https://registry.npmjs.org/@artemisdigital/unitcommander-sdk/-/unitcommander-sdk-0.0.1.tgz","fileCount":11,"unpackedSize":3930,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCa2sViie86oKRn9raXqydBqFdSoeZujcD4W2/52C/cXQIgRDjtty+vfJ4HYzCEfjg9ghQPCQtc4na5fIS0nKAKVWs="}]},"_npmUser":{"name":"danielth-uk","email":"thompson22email@gmail.com"},"directories":{},"maintainers":[{"name":"danielth-uk","email":"thompson22email@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unitcommander-sdk_0.0.1_1701300965603_0.13575518524881725"},"_hasShrinkwrap":false},"0.0.2":{"name":"@artemisdigital/unitcommander-sdk","version":"0.0.2","description":"UnitCommander Official Javascript SDK","keywords":["sdk","unitcommander"],"type":"module","private":false,"author":{"name":"Unit Commander Team"},"license":"","engines":{"node":"<16"},"main":"dist/index.js","module":"dist/index.modern.js","source":"src/index.tsx","devDependencies":{"@types/express":"^4.17.21","@typescript-eslint/eslint-plugin":"^6.13.1","eslint":"^8.54.0","prettier":"^3.1.0","typescript":"^5.3.2"},"dependencies":{"express":"^4.18.2"},"types":"./dist/index.d.ts","_id":"@artemisdigital/unitcommander-sdk@0.0.2","_nodeVersion":"20.3.1","_npmVersion":"9.7.2","dist":{"integrity":"sha512-lk9/5UY0UmRSDGd57BUxJAZ4VmdD83z/w0iZBEipGnxvyWSh0XsAqGswVeRIXqM6DBHqet5h6kudOtTTBw3MKQ==","shasum":"43c32aee5a3acfbf68cd83768e24b6988e55cfde","tarball":"https://registry.npmjs.org/@artemisdigital/unitcommander-sdk/-/unitcommander-sdk-0.0.2.tgz","fileCount":11,"unpackedSize":7085,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+e54oVeZrur6Yfr7a+2Y9n0+cfxVDINOITSOvFviWXAIhAK9m+ppdfkL3As/U99WTMipqE9yYb6w35H5pRZqeGaWo"}]},"_npmUser":{"name":"danielth-uk","email":"thompson22email@gmail.com"},"directories":{},"maintainers":[{"name":"danielth-uk","email":"thompson22email@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unitcommander-sdk_0.0.2_1701303042614_0.012393256640341521"},"_hasShrinkwrap":false},"0.2.1":{"name":"@artemisdigital/unitcommander-sdk","version":"0.2.1","description":"UnitCommander Official Javascript SDK","scripts":{"dev":"nodemon --exec 'tsc --project .\tsconfig.json' --watch ./src/* --ext ts,json,js","createVersion":"node createVersion.js"},"keywords":["sdk","unitcommander"],"repository":{"type":"git","url":"git+https://github.com/ArtemisDigital/UnitCommander-js-sdk.git"},"type":"module","private":false,"author":{"name":"Unit Commander Team"},"license":"","engines":{"node":"<16"},"main":"dist/index.js","module":"dist/index.modern.js","source":"src/index.tsx","devDependencies":{"@types/express":"^4.17.21","@typescript-eslint/eslint-plugin":"^6.13.1","eslint":"^8.54.0","prettier":"^3.1.0","typescript":"^5.3.2"},"dependencies":{"@types/http-errors":"^2.0.4","axios":"^1.6.2","express":"^4.18.2","form-data":"^4.0.0","formdata-node":"^6.0.3","http-errors":"^2.0.0"},"gitHead":"a14eb50d1b338a29df1ce4f35e8c7ab26d80523a","types":"./dist/index.d.ts","bugs":{"url":"https://github.com/ArtemisDigital/UnitCommander-js-sdk/issues"},"homepage":"https://github.com/ArtemisDigital/UnitCommander-js-sdk#readme","_id":"@artemisdigital/unitcommander-sdk@0.2.1","_nodeVersion":"20.3.1","_npmVersion":"9.7.2","dist":{"integrity":"sha512-De6b/Zvf7Zi8bxsoE876qIkwsvZJsp8mNwzMko9G1GR5dTqu0AshOD+4KJ+PPV5AEAHadvg7Hcj45GhfNjuJiA==","shasum":"efd08a194bb4cb19883dee3e3ad550934d39dd7d","tarball":"https://registry.npmjs.org/@artemisdigital/unitcommander-sdk/-/unitcommander-sdk-0.2.1.tgz","fileCount":35,"unpackedSize":48081,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA3SkH87KZHPUeRXDVPqhwnkI0z1CNvPBfUSpO1iBvErAiEA/431YRWCIkdyh3xmz7YY2fqd2okY6jhhpM83u+UU9GM="}]},"_npmUser":{"name":"danielth-uk","email":"thompson22email@gmail.com"},"directories":{},"maintainers":[{"name":"danielth-uk","email":"thompson22email@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unitcommander-sdk_0.2.1_1701627226473_0.24073328881563505"},"_hasShrinkwrap":false},"0.3.0":{"name":"@artemisdigital/unitcommander-sdk","version":"0.3.0","description":"UnitCommander Official Javascript SDK","scripts":{"dev":"nodemon --exec 'tsc --project .\tsconfig.json' --watch ./src/* --ext ts,json,js","createVersion":"node createVersion.js"},"keywords":["sdk","unitcommander"],"repository":{"type":"git","url":"git+https://github.com/ArtemisDigital/UnitCommander-js-sdk.git"},"type":"module","private":false,"author":{"name":"Unit Commander Team"},"license":"","engines":{"node":"<16"},"main":"dist/index.js","module":"dist/index.modern.js","source":"src/index.tsx","devDependencies":{"@types/express":"^4.17.21","@typescript-eslint/eslint-plugin":"^6.13.1","eslint":"^8.54.0","prettier":"^3.1.0","typescript":"^5.3.2"},"dependencies":{"@types/http-errors":"^2.0.4","axios":"^1.6.2","express":"^4.18.2","form-data":"^4.0.0","formdata-node":"^6.0.3","http-errors":"^2.0.0"},"gitHead":"2ff86e53d96dc8f99e486405f410dd5e12ae7c31","types":"./dist/index.d.ts","bugs":{"url":"https://github.com/ArtemisDigital/UnitCommander-js-sdk/issues"},"homepage":"https://github.com/ArtemisDigital/UnitCommander-js-sdk#readme","_id":"@artemisdigital/unitcommander-sdk@0.3.0","_nodeVersion":"20.3.1","_npmVersion":"9.7.2","dist":{"integrity":"sha512-W7Ge0/X2b9mQBAvhFRxFHhL3Z62ogncTSDFTqYk0K77E8G56TDnW6a5yxnfXDEKvhjEUECFsH9qtdVLc7XCNKw==","shasum":"1b6a4c99ad064316632996e7d0b844071a74afe0","tarball":"https://registry.npmjs.org/@artemisdigital/unitcommander-sdk/-/unitcommander-sdk-0.3.0.tgz","fileCount":41,"unpackedSize":60600,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDBiu6RrU1XKdGwfl9fKvLH864fBNBxjbrOlSUqjgmCdgIge3g5DuntDVQ4d+DuTjd4V5+nqRpFZoRRMlJowq7FSco="}]},"_npmUser":{"name":"danielth-uk","email":"thompson22email@gmail.com"},"directories":{},"maintainers":[{"name":"danielth-uk","email":"thompson22email@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unitcommander-sdk_0.3.0_1701628546911_0.14554375046126244"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-29T23:36:05.505Z","0.0.1":"2023-11-29T23:36:05.804Z","modified":"2023-12-03T18:35:47.361Z","0.0.2":"2023-11-30T00:10:42.792Z","0.2.1":"2023-12-03T18:13:46.647Z","0.3.0":"2023-12-03T18:35:47.114Z"},"maintainers":[{"name":"danielth-uk","email":"thompson22email@gmail.com"}],"description":"UnitCommander Official Javascript SDK","keywords":["sdk","unitcommander"],"author":{"name":"Unit Commander Team"},"readme":"\r\n# UnitCommander Basic SDK\r\n\r\nThis package is a very simple package to help you get started with webhooks. This documentation will be guided towards UnitCommander Webhook events.\r\n\r\n### Install\r\n\r\n```\r\nnpm i @artemisdigital/unitcommander-sdk\r\n```\r\n\r\n\r\n## Examples\r\n\r\n\r\n### Basic Webhook\r\n\r\nThis will launch a webhook listener \r\n\r\n```javascript\r\nimport { UnitCommanderWebhookService } from \"@artemisdigital/unitcommander-sdk\"\r\n\r\n// This will initilize the service\r\nconst uc = new UnitCommanderWebhookService();\r\n\r\n// Logs out the data from the webhook which is an object of `timestamp`, `data` and `type`\r\nfunction logData(data) {\r\n    console.log(\"Data from webhook: \", data);\r\n}\r\n\r\n// This will execute the function `logData` on a specific webhook type, you will need one of these for every event you would like to listen to see https://docs.unitcommander.co.uk/api/webhooks for more information\r\nuc.webhookAddAction('profile.updated', logData);\r\n\r\n// This will start the listener\r\nuc.webhookListen(3000);\r\n```\r\n\r\nTo run the above code, save it as `index.js` and run `node ./index.js` in the same directory as the file.\r\n\r\n\r\n### Implement into Discord\r\n\r\nIn the following example, when the webhook `profile.updated.rank` is recieved, the function `giveRankToPlayer` will be exectued which will then send an API request to discord and give the player a specific role.\r\n\r\n**Note the following code will NOT work, current API limitations will not let you get the discord ID of a user**\r\n\r\n```javascript\r\nimport { UnitCommanderWebhookService } from \"@artemisdigital/unitcommander-sdk\";\r\nimport { axios } from \"axios\";\r\n\r\nconst uc = new UnitCommanderWebhookService();\r\n\r\n// Don't store tokens in code, use environment variables or secrets\r\nconst discordBotToken = \"TOKEN\";\r\n\r\n// You will need an API token to interact with the unitcommander API (it will need permission to see discord ids)\r\nconst unitCommanderBotId = \"TOKEN\"\r\n\r\n// Your Discord GuildID\r\nconst guildID = \"ID\"\r\n\r\n// You will want to map the name or abbreviation of the value to the Discord Id of the role (or rank id)\r\nconst ranks = {\r\n    \"Private\": ROLE_ID_1,\r\n    \"Corporal\": ROLE_ID_2\r\n}\r\n\r\n// This function can be more generalised, however for this example, its specific to adding a discord role to a Discord user\r\nfunction giveRankToPlayer(data){\r\n    const profileRank = ranks[data.rank.name] ? ranks[data.rank.name] : \"GENERIC_ID\"\r\n    const playerId = data.id\r\n\r\n    axios.get(`https://api.unitcommander.co.uk/community/YOUR_COMMUNITY_ID/profiles/${data.id}`, {\r\n        \"Authorization\": `Bot ${unitCommanderBotId}`\r\n    }).then(response => {\r\n        response.json()\r\n    }).then(data => {\r\n\r\n        // Reference: https://discord.com/developers/docs/resources/guild#add-guild-member-role\r\n        // Not all users have Discord linked, therefore this may error\r\n        axios.put(`https://discord.com/api/10/guilds/${guildID}/members/${data.player.discord_id}/roles/${profileRank}`, {\r\n            \"Authorization\": `Bot ${discordBotToken}`\r\n        }).catch(error => {\r\n            console.log(error)\r\n        })\r\n    })\r\n};\r\n\r\nuc.webhookAddAction('profile.updated.rank', logData);\r\nuc.webhookListen(3000);\r\n```\r\n","readmeFilename":"README.md","homepage":"https://github.com/ArtemisDigital/UnitCommander-js-sdk#readme","repository":{"type":"git","url":"git+https://github.com/ArtemisDigital/UnitCommander-js-sdk.git"},"bugs":{"url":"https://github.com/ArtemisDigital/UnitCommander-js-sdk/issues"}}