{"id":22267551,"url":"https://github.com/lakca/superagent-toolkit","last_synced_at":"2025-03-25T14:43:00.770Z","repository":{"id":57126167,"uuid":"283992602","full_name":"lakca/superagent-toolkit","owner":"lakca","description":"Superagent plugin, providing frequently used tools. Such as reporting message of current request, and then silence error, directly retrieving specific property of response etc.","archived":false,"fork":false,"pushed_at":"2020-08-12T04:55:46.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T04:05:06.477Z","etag":null,"topics":["superagent","superagent-toolkit"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lakca.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-31T09:12:50.000Z","updated_at":"2020-08-12T04:55:48.000Z","dependencies_parsed_at":"2022-08-24T14:59:36.496Z","dependency_job_id":null,"html_url":"https://github.com/lakca/superagent-toolkit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fsuperagent-toolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fsuperagent-toolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fsuperagent-toolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fsuperagent-toolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lakca","download_url":"https://codeload.github.com/lakca/superagent-toolkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245485306,"owners_count":20623229,"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":["superagent","superagent-toolkit"],"created_at":"2024-12-03T11:07:22.342Z","updated_at":"2025-03-25T14:43:00.742Z","avatar_url":"https://github.com/lakca.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# superagent-toolkit\n\n\u003e [Superagent][superagent] plugin, providing frequently used tools, like reporting message of current request, directly retrieving specific property of response, etc.\n\n[![Build Status](https://travis-ci.org/lakca/superagent-toolkit.svg?branch=master)](https://travis-ci.org/lakca/superagent-toolkit)\n[![codecov](https://codecov.io/gh/lakca/superagent-toolkit/branch/master/graph/badge.svg)](https://codecov.io/gh/lakca/superagent-toolkit)\n\n## Usage\n\n### Agent\n```js\nconst superagent = require('superagent')\nconst toolkit = require('@lakca/superagent-toolkit')\n\nconst agent = new superagent.Agent()\n\nagent.use(toolkit(options))\n\nagent\n  .get('/test')\n  .configure('...', '...') // change config\n```\n\n### General\n```js\nconst superagent = require('superagent')\nconst toolkit = require('@lakca/superagent-toolkit')\n\nsuperagent\n  .get('/test')\n  .use(toolkit(options))\n```\n\n## Options\n\n### `options.configure` {function}\n\nSet configure function, which can be called to change `config` later.\n\n### `options.report` {(error: Error, message: string, response: superagent.Response): void}\n\nFunction to receive message of request.\n\n**Note**: it will benefit from using this function for global notification of request status.\n\n### `options.clientError` {true|string|string[]|function}\n\nDealing with `4xx` except `401` http code. If value is:\n\n- `true`, report message retrieved using `config.messageProperty`;\n- `string`, report message using the string instead;\n- `string[]`, report message using ths first not nullable(`!= null`) property retrieving via the array element one by one, such as `['body.message', 'header.statusMessage']`;\n- `function`, report message using returned value if which is not void.\n\n### `options.serverError` {true|string|string[]|function}\n\nDealing with `5xx` http code. Similar as `config.clientError`.\n\n### `options.unauthorized` {true|string|string[]|function}\n\nDealing with `401` http code. If value is:\n\n- `true`, reload current window;\n- `string`, redirect using the string;\n- `string[]`, redirect using ths first not nullable(`!= null`) property retrieving via the array element one by one, such as `['body.location']`;\n- `function`, redirect using returned value if which is not void, **so you can provide your own redirection in the function without returning value.**\n\n### `options.messageProperty` {string=res.statusMessage}\n\nReport message property.\n\nwhen http code is `2xx`, using this to retrieve message.\n\nalso, this is the default message property for `true` value of `config.clientError` and `config.serverError`.\n\n**Note**: support descendant property, such as `body.message`\n\n### `options.returnProperty` {string}\n\nResponse property expected to be returned instead of the whole response object.\n\n**Note**: support descendant property, such as `body.data`\n\n### `options.swallowError` {boolean=false}\n\nSilence error, no request/response error will be thrown since [superagent][superagent] does that by default.\n\n**Note**: this is useful when we handle request status by general handler `config.report`, then focusing on handling business data in dealing with your business logic.\n\n### `options.debug` {boolean=false}\n\nlog to console.\n\n### `options.prefix` {string}\n\n### `options.suffix` {string}\n\n### `options.jsonp` {object}\n\nRead more in [superagent-jsonp][jsonp]\n\n### `options.jsonp.callbackParam` {string=callback}\n\n### `options.jsonp.callbackName` {string}\n\n### `options.jsonp.timeout` {number=1000}\n\n## LICENSE\n\nMIT\n\n[superagent]: https://github.com/visionmedia/superagent\n[jsonp]: https://github.com/lamp/superagent-jsonp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakca%2Fsuperagent-toolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flakca%2Fsuperagent-toolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakca%2Fsuperagent-toolkit/lists"}