{"id":21554993,"url":"https://github.com/suspiciouslookingowl/saweria-api","last_synced_at":"2025-07-18T03:06:09.722Z","repository":{"id":49784366,"uuid":"295528621","full_name":"SuspiciousLookingOwl/saweria-api","owner":"SuspiciousLookingOwl","description":"Saweria API and WebSocket wrapper for Node.js","archived":false,"fork":false,"pushed_at":"2023-09-27T02:37:33.000Z","size":711,"stargazers_count":44,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"development","last_synced_at":"2025-03-24T09:02:58.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/saweria","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SuspiciousLookingOwl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-14T20:16:10.000Z","updated_at":"2025-01-09T06:29:36.000Z","dependencies_parsed_at":"2022-09-02T21:02:01.905Z","dependency_job_id":null,"html_url":"https://github.com/SuspiciousLookingOwl/saweria-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuspiciousLookingOwl%2Fsaweria-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuspiciousLookingOwl%2Fsaweria-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuspiciousLookingOwl%2Fsaweria-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuspiciousLookingOwl%2Fsaweria-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SuspiciousLookingOwl","download_url":"https://codeload.github.com/SuspiciousLookingOwl/saweria-api/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198890,"owners_count":21063628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T08:00:28.784Z","updated_at":"2025-04-10T10:10:21.629Z","avatar_url":"https://github.com/SuspiciousLookingOwl.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Saweria API\n\nNode.js API Wrapper for [Saweria.co](https://saweria.co/)\n\nCheck the [Changelog](https://github.com/SuspiciousLookingOwl/saweria-api/blob/master/CHANGELOG.md)\n\n## Installation\n\n```\nnpm i saweria\n```\n\n## Example\n\n```js\nconst { Client } = require(\"saweria\");\n// or\nimport { Client } from \"saweria\";\n\nconst client = new Client();\n\nclient.on(\"login\", (user) =\u003e {\n\tconsole.log(\"Logged in as: \", user.username);\n});\n\nclient.on(\"donations\", (donations) =\u003e {\n\tconsole.log(donations);\n});\n\nclient.login(\"email\", \"password\");\n// or with otp\nclient.login(\"email\", \"password\", \"otp\");\n```\n\nor only for donation event listener\n\n```js\nconst { Client } = require(\"saweria\");\n// or\nimport { Client } from \"saweria\";\n\nconst client = new Client();\n\nclient.setStreamKey(\"your-stream-key\");\n\nclient.on(\"donations\", (donations) =\u003e {\n\tconsole.log(donations);\n});\n```\n\n# Client API\n\n### `async login(jwt)`\n\n### `async login(email, password, otp = \"\")`\n\nLogin to Saweria using JWT or email and password. If the account has no 2FA enabled, `otp` will be ignored.\n\nThis will set the default header authorization value for the future requests with user's JWT\n\nLogin with JWT is useful if your account has 2FA enabled and don't want to get your 2FA token every time you login. JWT generated by Saweria lasts for 72 hours, so you have to get a new JWT for your account every 72 hours. You can get your JWT by:\n\n1. **Using this library**\n   1. Log in to your account using `client.login(username, password)`\n   2. Get the account JWT from `client.jwt`\n2. **Using the web client**\n   1. Go to [saweria.co](https://saweria.co/) and login to your account\n   2. Open browser developer console, and execute `console.log(JSON.parse(localStorage[\"saweria-user-info\"]).token);`\n3. **Sending a request to login endpoint**\n   1. Send a `POST` request to `https://api.saweria.co/auth/login` with these JSON body payload:\n   ```json\n   {\n   \t\"email\": \"example@email.com\",\n   \t\"password\": \"your-password\",\n   \t\"otp\": \"your otp code, optional if your account doesn't have 2FA enabled\"\n   }\n   ```\n   2. Get the JWT token from `Authorization` response header.\n\n---\n\n### `logout()`\n\nRemoves authorization header from HTTP client, preventing future requests.\n\n---\n\n### `async setStreamKey(streamKey)`\n\nSet the client's stream key, this can be used to listen to donation event without logging in.\n\n---\n\n### `async getStreamKey()`\n\nGet user's stream key\n\n---\n\n### `async getUser()`\n\nGet user profile information\n\n---\n\n### `async getBalance()`\n\nGet user's balance\n\n---\n\n### `async getAvailableBalance()`\n\nGet user's available balance to disburse\n\n---\n\n### `async getTransaction(page = 1, pageSize = 15)`\n\nGet user's transaction list. Accepts these parameters:\n\n- `page`: What page of transaction to get (Default = `1`)\n- `pageSize`: How many transactions per page (Default = `15`)\n\n---\n\n### `async getMilestoneProgress(fromDate)`\n\nGet milestone progress from passed date with `dd-mm-yyyy` format until now.\n\n---\n\n### `async getLeaderboard(period = \"all\")`\n\nGet donation leaderboard from given time period.\n\n`period` can be `\"all\"`, `\"year\"`, `\"month\"`, or `\"week\"` (Default = `\"all\"`)\n\n---\n\n### `async getVote()`\n\nGet currently active vote data\n\n---\n\n### `async sendFakeDonation()`\n\nSend a fake donation\n\n---\n\n### `on(eventName, callback)`\n\nListen to client [events](#Client-Events) and execute `callback` when emitted\n\n# Client Events\n\n### `login`\n\nEmitted when client successfully logged in. Callback accepts [`User`](src/types.ts) as the first parameter\n\nExample:\n\n```js\nclient.on(\"login\", (user) =\u003e {\n\tconsole.log(\"Logged in as: \", user.username);\n});\n```\n\n---\n\n### `donations`\n\nEmitted when client received a donation. Callback accepts array of [`EmittedDonation`](src/types.ts) or [`EmittedMedia`](src/types.ts) as the first parameter\n\nExample:\n\n```js\nclient.on(\"donations\", (donations) =\u003e {\n\tconsole.log(donations); // array of donations\n\n\tfor (const donation of donations) {\n\t\tif (donation.type === \"normal\") {\n\t\t\t// normal donation\n\t\t} else if (donation.type === \"media\") {\n\t\t\t// donation with media\n\t\t}\n\t}\n});\n```\n\nNormal Donation data example:\n\n```js\n[\n\t{\n\t\tamount: \"69420\",\n\t\tdonator: \"Someguy\",\n\t\tmedia: {\n\t\t\tsrc: [\n\t\t\t\t\"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.webp\",\n\t\t\t\t\"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.mp4\",\n\t\t\t\t\"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.gif\",\n\t\t\t],\n\t\t\ttag: \"picture\",\n\t\t},\n\t\tmessage: \"THIS IS A FAKE MESSAGE! HAVE A GOOD ONE\",\n\t\tsound: {\n\t\t\t\"1547679809default.ogg\":\n\t\t\t\t\"https://saweria-space.sgp1.cdn.digitaloceanspaces.com/prd/sound/836d7a85-dd70-4028-85fb-00fd785f0928-c527b4f6bd6282e21e78c85343d496fa.ogg\",\n\t\t},\n\t\ttts: \"...\",\n\t},\n];\n```\n\nMedia Donation data example:\n\n```js\n[\n\t{\n\t\tamount: \"69420\",\n\t\tdonator: \"Someguy\",\n\t\tmedia: { end: 10, id: \"RRKPkwBkz_0\", start: 0, type: \"yt\" },\n\t\tmessage: \"THIS IS A FAKE MESSAGE! HAVE A GOOD ONE\",\n\t\tsound: null,\n\t},\n];\n```\n\n### `donation`\n\nSimilar to `donations`, but emits donation one by one when donations are received\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuspiciouslookingowl%2Fsaweria-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuspiciouslookingowl%2Fsaweria-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuspiciouslookingowl%2Fsaweria-api/lists"}