{"id":22123348,"url":"https://github.com/drpaulbrewer/pointomatic","last_synced_at":"2026-05-01T01:32:11.511Z","repository":{"id":34887013,"uuid":"187155400","full_name":"DrPaulBrewer/pointomatic","owner":"DrPaulBrewer","description":"redis-based points/tokens key-key-value manager with create, add, get, getAll, delete, reap, weighted sums, logging","archived":false,"fork":false,"pushed_at":"2024-02-06T00:22:39.000Z","size":393,"stargazers_count":0,"open_issues_count":15,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T03:11:18.607Z","etag":null,"topics":["bank","crud","points","redis","tokens","weighted-sum"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DrPaulBrewer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-17T05:58:02.000Z","updated_at":"2019-05-23T02:21:29.000Z","dependencies_parsed_at":"2024-12-01T15:43:47.700Z","dependency_job_id":null,"html_url":"https://github.com/DrPaulBrewer/pointomatic","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/DrPaulBrewer%2Fpointomatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrPaulBrewer%2Fpointomatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrPaulBrewer%2Fpointomatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrPaulBrewer%2Fpointomatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrPaulBrewer","download_url":"https://codeload.github.com/DrPaulBrewer/pointomatic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245226976,"owners_count":20580777,"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":["bank","crud","points","redis","tokens","weighted-sum"],"created_at":"2024-12-01T15:32:32.681Z","updated_at":"2026-05-01T01:32:11.470Z","avatar_url":"https://github.com/DrPaulBrewer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pointomatic\n\n[![Build Status](https://travis-ci.org/DrPaulBrewer/pointomatic.svg?branch=master)](https://travis-ci.org/DrPaulBrewer/pointomatic)\n[![Coverage Status](https://coveralls.io/repos/github/DrPaulBrewer/pointomatic/badge.svg?branch=master)](https://coveralls.io/github/DrPaulBrewer/pointomatic?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/DrPaulBrewer/pointomatic.svg)](https://greenkeeper.io/)\n\nRedis-based points/tokens key-key-value manager with create, add, get, delete, reap, weighted sums, logging\n\n## Installation\n\n```\nnpm i ioredis -S\nnpm i pointomatic -S\n```\n\n## Dependencies\n\nDevelopers using this library must pass a configured `npm:ioredis` client on initialization.  \n\n`npm:@hapi/joi` is used for initial validation.\n\n## Initialization\n\nBelow is a sample configuration to:\n* track something called \"points\"\n* use the redis instance running on localhost\n* block invalid non-strings or empty-strings when used as keys\n* restrict points to be from 0 to 10 million inclusive\n* use plain-text keys on the redis database (encrypt/decrypt are identity functions)\n* log create/delete events (but not add, there is no general ledger or history)\n```\nconst ioredis = require('ioredis');\nconst pointomatic = require('pointomatic');\nconst IoRedis = require('ioredis');\nconst redisServerLocal = {\n  host: \"localhost\",\n  port: 6379,\n  retryStrategy(times) {\n    const delay = Math.min(times * 100, 2000);\n    return delay;\n  }\n};\nconst ioredis = new IoRedis(redisServerLocal);\nconst points = pointomatic({\n    ioredis,\n    name: 'points',\n    min: 0,\n    max: 10*1000*1000,\n    encrypt: (s)=\u003e(s),\n    decrypt: (s)=\u003e(s),\n    log: true,\n    invalid: (s)=\u003e((typeof(s)!=='string') || (s.length===0))\n});\n```\n\n## Usage\n\n```\nawait points.create(key, value, optionalReasonForLog);\n\nawait points.create(\"Lisa\", 100, \"trial offer\");\n// yields {key: \"Lisa\", value: 100 }\n\nawait points.create(\"Susan\", 20000, \"paid plan: conquest!\");\n// yields {key: \"Susan\", value: 20000 }\n\n// can not double-create an existing account\nawait points.create(\"Susan\", 5000, \"paid plan: basic\");\n// throws /conflict E/\n\nawait points.create(\"Undead\", -100, \"oh no!\");\n// throws /invalid value below min/\n\nawait points.create(\"Kraken\", 1e30, \"wow!\");\n// throws /invalid value above max/\n\nawait points.get(\"Susan\")\n// yields {key: \"Susan\", value: 20000 }\n\nawait points.add(\"Susan\",100);\n// yields {key: \"Susan\", value: 20100, change: 100 }\n\nawait points.add(\"Susan\",-500);\n// yields {key: \"Susan\", value: 19600, change: -500 }\n\n// in race conditions with multiple clients, values outside of allowed range can get temporarily written to redis\n// but they are detected and reversed and then an error is returned to one or more clients where addition failed\n\nawait points.add(\"Susan\",-1000000);\n// throws /invalid value below min/\n// database not updated because increment was out of bounds using current value.  Susan still has 19600 points\n\nawait points.delete(key, optionalReasonForLog);\n\nawait points.delete(\"Susan\",\"account expired\");\n// yields { key: \"Susan\", deleted: true }\n\nawait points.getDeleteReason(\"Susan\");\n// yields { key: \"Susan\", utc: \"Fri, 17 May 2019 05:00:54 GMT\", reason: \"account expired\"}\n\n// non-existent account deletion does not throw but is noted\nawait points.delete(\"Susan\", \"delete again\");\n// yields { key: \"Susan\", deleted: false}\n\n// recreating an account logged as deleted is forbidden\nawait points.create(\"Susan\", 100);\n// throws /conflict D/\n\nawait points.wsum(points.name, {[points.name]: 1, \"premium\": 20});\n// give premium members (in redis database set-valued key \"premium\") 20 points\n// uses redis zunionstore\n// side effects: ignores min/max and can create accounts that dont exist\n// yields { destination: points.name, weights, count }\n// count is the number of calculated values\n\nawait points.wsum(points.name, {[points.name]: 1, \"premium\": -20});\n// deduct 20 points from premium members\n\nawait points.wsum(\"backup\", {[points.name]:1});\n// store the points keys/values in another redis sorted set named \"backup\"\n\nawait points.wsum(points.name, {\"backup\": 1});\n// restore from backup, replacing all current keys/values\n// doesn't fix/restore logs\n\nawait points.reap(optionalReasonForLog);\n\nawait points.reap(\"expended\");\n// uses redis zremrangebyscore\n// when logging is enabled, first fetches list of keys to be deleted and writes delete logs\n// yields numberOfDeletedAccounts\n\n\n```\n\n## Tests\n\nTo test:\n\nFirst, spin up a redis database on localhost using docker\n\n```\n docker run -v /tmp/data:/data \\\n    --name \"red\" \\\n    -d \\\n    -p 127.0.0.1:6379:6379 \\\n    redis redis-server --appendonly yes\n```\n\nWarning:  Testing will FLUSHALL and DELETES THE ENTIRE DATABSE on localhost.  \n\n```\nnpm test\n```\n\nAfter running npm test, you may want to delete the redis docker container.\n\n```\ndocker kill red\ndocker rm red\n```\n\n### Copyright\n\nCopyright 2019 Paul Brewer, Economic and Financial Technology Consulting LLC\n\n### License\n\nThe MIT license\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrpaulbrewer%2Fpointomatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrpaulbrewer%2Fpointomatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrpaulbrewer%2Fpointomatic/lists"}