{"id":47688079,"url":"https://github.com/mosparo/js-api-client","last_synced_at":"2026-04-02T15:03:12.644Z","repository":{"id":64031210,"uuid":"538118705","full_name":"mosparo/js-api-client","owner":"mosparo","description":"A JavaScript library to communicate with mosparo.","archived":false,"fork":false,"pushed_at":"2025-01-02T10:29:12.000Z","size":436,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-30T17:59:36.379Z","etag":null,"topics":["javascript-library","mosparo","spam-detection"],"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/mosparo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-09-18T13:30:47.000Z","updated_at":"2025-01-02T10:25:02.000Z","dependencies_parsed_at":"2024-01-10T19:05:50.932Z","dependency_job_id":null,"html_url":"https://github.com/mosparo/js-api-client","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"80f920e036e9bf1df2bec7713f3daf5535e250f8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mosparo/js-api-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosparo%2Fjs-api-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosparo%2Fjs-api-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosparo%2Fjs-api-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosparo%2Fjs-api-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mosparo","download_url":"https://codeload.github.com/mosparo/js-api-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosparo%2Fjs-api-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31308589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript-library","mosparo","spam-detection"],"created_at":"2026-04-02T15:03:11.328Z","updated_at":"2026-04-02T15:03:12.637Z","avatar_url":"https://github.com/mosparo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u0026nbsp;\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/mosparo/mosparo/blob/master/assets/images/mosparo-logo.svg?raw=true\" alt=\"mosparo logo contains a bird with the name Mo and the mosparo text\"/\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n    JS API Client\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    This library offers the API client to communicate with mosparo to verify a submission.\n\u003c/p\u003e\n\n---\n\n## Description\n\nWith this JavaScript/TypeScript library you can connect to a mosparo installation and verify the submitted data.\n\n## Installation\n\nInstall this library by using npm:\n\n```text\nnpm install @mosparo/api-client\n```\n\n## Usage\n\n1. Create a project in your mosparo installation\n2. Include the mosparo script in your form\n\n```html\n\u003cdiv id=\"mosparo-box\"\u003e\u003c/div\u003e\n\n\u003cscript src=\"https://[URL]/build/mosparo-frontend.js\" defer\u003e\u003c/script\u003e\n\u003cscript\u003e\n\tvar m;\n\twindow.onload = function () {\n\t\tm = new mosparo(\"mosparo-box\", \"https://[URL]\", \"[UUID]\", \"[PUBLIC_KEY]\", {\n\t\t\tloadCssResource: true,\n\t\t});\n\t};\n\u003c/script\u003e\n```\n\n3. Include the library in your project\n\n```js\nconst mosparo = require('@mosparo/api-client');\n// or\nimport { Client } from '@mosparo/api-client';\n```\n\n4. After the form was submitted, verify the data before processing it\n\n```js\nlet client = new mosparo.Client(host, publicKey, privateKey, {});\n\nmosparoSubmitToken = formData._mosparo_submitToken;\nmosparoValidationToken = formData._mosparo_validationToken;\n\nclient\n\t.verifySubmission(formData, mosparoSubmitToken, mosparoValidationToken)\n\t.then((verificationResult) =\u003e {\n\t\tif (verificationResult.isSubmittable()) {\n\t\t\t// Send the email or process the data\n\t\t} else {\n\t\t\t// Show error message\n\t\t}\n\t});\n```\n\n## API Documentation\n\n### Client\n\n#### Client initialization\n\nCreate a new client object to use the API client.\n\n```js\n/**\n * @param string url URL of the mosparo installation\n * @param string publicKey Public key of the mosparo project\n * @param string privateKey Private key of the mosparo project\n * @param array args Arguments for the axios request\n */\nlet client = new Client(url, publicKey, privateKey, args);\n```\n\n#### Verify form data\n\nTo verify the form data, call `verifySubmission` with the form data in an array and the submit and validation token, which mosparo generated on the form initialization and the form data validation. The method will return a new Promise object that is resolved with the `VerificationResult` object.\n\n```js\n/**\n * @param array formData Array with the form values. All not-processed fields by mosparo (hidden, checkbox,\n *                       radio and so on) have to be removed from this array\n * @param string mosparoSubmitToken Submit token which mosparo returned on the form initialization\n * @param string mosparoValidationToken Validation token which mosparo returned after the form was validated\n * @return Promise Returns a Promise object that is resolved with a VerificationResult object\n */\nclient\n\t.verifySubmission(formData, mosparoSubmitToken, mosparoValidationToken)\n\t.then((validationResult) =\u003e {\n\t\tif (verificationResult.isSubmittable()) {\n\t\t\t// Do your stuff, e.g. sending emails...\n\t\t}\n\t});\n```\n\n#### Request the statistical data\n\nmosparo also has an API method to get the statistical data for a project. You can use the method `getStatisticByDate` to get the statistical data. You can specify the range in seconds or a start date from which mosparo should return the statistical data. This method will return a `StatisticResult` object.\n\n```js\n/**\n * @param int range = 0 The range in seconds for which mosparo should return the statistical data (will be rounded up to a full day since mosparo v1.1)\n * @param string startDate = null The Start date from which on mosparo should return the statistical data (requires mosparo v1.1)\n * @return Promise Returns a Promise object that is resolved with a StatisticResult object\n */\nclient.getStatisticByDate(range, startDate).then((statisticResult) =\u003e {\n\t// Process the statistical data\n});\n```\n\n### VerificationResult\n\n#### Constants\n\n- FIELD_NOT_VERIFIED: 'not-verified'\n- FIELD_VALID: 'valid'\n- FIELD_INVALID: 'invalid'\n\n#### isSubmittable(): boolean\n\nReturns true, if the form is submittable. This means that the verification was successful and the\nform data are valid.\n\n#### isValid(): boolean\n\nReturns true, if mosparo determined the form as valid. The difference to `isSubmittable()` is, that this\nis the raw result from mosparo while `isSubmittable()` also checks if the verification was done correctly.\n\n#### getVerifiedFields(): array (see Constants)\n\nReturns an array with all verified field keys.\n\n#### getVerifiedField(key): string (see Constants)\n\nReturns the verification status of one field.\n\n#### hasIssues(): boolean\n\nReturns true, if there were verification issues.\n\n#### getIssues(): array\n\nReturns an array with all verification issues.\n\n### StatisticResult\n\n#### getNumberOfValidSubmissions(): int\n\nReturns the total number of valid submissions in the requested date range.\n\n#### getNumberOfSpamSubmissions(): int\n\nReturns the total number of spam submissions in the requested date range.\n\n#### getNumbersByDate(): array\n\nReturns an array with all statistical data for the requested time range. The date is the key in the array, while an array is set as a value. The array contains a key `numberOfValidSubmissions` with the number of valid submissions and a key `numberOfSpamSubmissions` with the number of spam submissions.\n\n## TypeScript\n\nWhen you include `mosparo-frontend.js` in your form, Typescript doesn't recognize ther `mosparo` class from the external script. You will need to declare it:\n\n```typescript\ndeclare class mosparo {\n\tconstructor(\n\t\tcontainerId: string,\n\t\turl: string,\n\t\tuuid: string,\n\t\tpublicKey: string,\n\t\toptions: object\n\t);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosparo%2Fjs-api-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmosparo%2Fjs-api-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosparo%2Fjs-api-client/lists"}