Compare commits

...
3 Commits
Author SHA1 Message Date
Jonas Lochmann b2bcc3715f Update dependencies 2026-06-15 02:00:00 +02:00
Jonas Lochmann 2f35b969bf make CanDoPurchaseRequest.type optional 2026-06-08 02:00:00 +02:00
Jonas Lochmann 48d6a061f8 add full version debts system
foundation for granting the full version while consuming the same amount
automatically at the next purchase
2026-06-08 02:00:00 +02:00
14 changed files with 193 additions and 97 deletions
+24 -1
View File
@@ -15,13 +15,16 @@ Use this before a purchase to check if a purchase is possible.
see [this JSON schema](../schema/candopurchaserequest.md)
Note that ``type`` is not used at all.
### response
On a invalid request body: HTTP status code 400 Bad request
On a invalid auth token: HTTP status code 401 Unauthorized
On success: a JSON object with the property ``canDoPurchase`` (string) and ``googlePlayPublicKey`` (string, base64)
On success: a JSON object with the property ``canDoPurchase`` (string), ``googlePlayPublicKey`` (string, base64)
and ``permitDebts`` (boolean, optional, default false).
possible values of ``canDoPurchase``:
@@ -31,6 +34,26 @@ possible values of ``canDoPurchase``:
The ``googlePlayPublicKey`` is the key by which purchases using google play should be signed.
## POST /purchase/finish-purchase-by-debts
Use this to unlock without payment. Limitations apply.
### request
see [this JSON schema](../schema/candopurchaserequest.md)
Note that ``type`` is not used at all.
### response
On a invalid request body: HTTP status code 400 Bad request
On a invalid auth token: HTTP status code 401 Unauthorized
If not granted: HTTP status code 409 Conflict
On success: HTTP status code 200
## POST /purchase/finish-purchase-by-google-play
Use this to report a purchase to the server/ unlock all features after a purchase
+1 -2
View File
@@ -14,8 +14,7 @@
},
"additionalProperties": false,
"required": [
"deviceAuthToken",
"type"
"deviceAuthToken"
],
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
+2 -2
View File
@@ -18,7 +18,7 @@ https://timelimit.io/CanDoPurchaseRequest
| Property | Type | Required | Nullable | Defined by |
| :---------------------------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
| [type](#type) | `string` | Required | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-type.md "https://timelimit.io/CanDoPurchaseRequest#/properties/type") |
| [type](#type) | `string` | Optional | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-type.md "https://timelimit.io/CanDoPurchaseRequest#/properties/type") |
| [deviceAuthToken](#deviceauthtoken) | `string` | Required | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-deviceauthtoken.md "https://timelimit.io/CanDoPurchaseRequest#/properties/deviceAuthToken") |
## type
@@ -27,7 +27,7 @@ https://timelimit.io/CanDoPurchaseRequest
`type`
* is required
* is optional
* Type: `string`
+69 -69
View File
@@ -57,9 +57,9 @@
}
},
"node_modules/@adobe/jsonschema2md": {
"version": "8.0.8",
"resolved": "https://registry.npmjs.org/@adobe/jsonschema2md/-/jsonschema2md-8.0.8.tgz",
"integrity": "sha512-KqYjZxjvCj7/AlvVtXVKz1AJk+5f3LFnuWi8B2N1sRsJX3oCKNI/XXkns5uChaEL+qAazkvbh7AQd8kANtbjLA==",
"version": "8.0.11",
"resolved": "https://registry.npmjs.org/@adobe/jsonschema2md/-/jsonschema2md-8.0.11.tgz",
"integrity": "sha512-WRfZRqoyQqQ5eRWcfFPa/r3UUnOoKqREsED09pHj6AU3upcNdw/Mj28CYX8C5SUyov2VjIOhZZSsNaUovm6tUw==",
"dev": true,
"dependencies": {
"@types/json-schema": "^7.0.8",
@@ -67,13 +67,13 @@
"@types/unist": "^3.0.3",
"es2015-i18n-tag": "1.6.1",
"ferrum": "1.9.4",
"fs-extra": "11.3.2",
"fs-extra": "11.3.4",
"github-slugger": "2.0.0",
"js-yaml": "4.1.1",
"json-schema": "^0.4.0",
"mdast-builder": "1.1.1",
"mdast-util-to-string": "4.0.0",
"readdirp": "4.1.2",
"readdirp": "5.0.0",
"remark-gfm": "^4.0.0",
"remark-parse": "11.0.0",
"remark-stringify": "11.0.0",
@@ -1652,9 +1652,9 @@
}
},
"node_modules/engine.io": {
"version": "6.6.8",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.8.tgz",
"integrity": "sha512-2agL3ueZhqxoVrfmntO8yuVj+uNSlIOnhykYHk3Cq0ShYPdUjjUiSJrQvXjq01I9jAuI0Zl2YO8Evv5Mqytm5g==",
"version": "6.6.9",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.9.tgz",
"integrity": "sha512-clKkw4C7nJ22mGgoVcCg6V/W/TxdNyIOTr89k2ONZu81qqkddPFDF0LXcbAwhzPD8DjkiRCjzuiO6Y+fkpD4vg==",
"dependencies": {
"@types/cors": "^2.8.12",
"@types/node": ">=10.0.0",
@@ -1665,7 +1665,7 @@
"cors": "~2.8.5",
"debug": "~4.4.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.20.1"
"ws": "~8.21.0"
},
"engines": {
"node": ">=10.2.0"
@@ -2357,9 +2357,9 @@
}
},
"node_modules/fs-extra": {
"version": "11.3.2",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.2.tgz",
"integrity": "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A==",
"version": "11.3.4",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.4.tgz",
"integrity": "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.2.0",
@@ -2491,9 +2491,9 @@
}
},
"node_modules/graceful-fs": {
"version": "4.2.9",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==",
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true
},
"node_modules/has-symbols": {
@@ -2707,9 +2707,9 @@
"dev": true
},
"node_modules/jsonfile": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz",
"integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==",
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
"integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
"dev": true,
"dependencies": {
"universalify": "^2.0.0"
@@ -3789,9 +3789,9 @@
}
},
"node_modules/nodemailer": {
"version": "8.0.5",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.5.tgz",
"integrity": "sha512-0PF8Yb1yZuQfQbq+5/pZJrtF6WQcjTd5/S4JOHs9PGFxuTqoB/icwuB44pOdURHJbRKX1PPoJZtY7R4VUoCC8w==",
"version": "8.0.11",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.11.tgz",
"integrity": "sha512-nrO/pDAUKl+wXX+lx16tDLbnm0fW6sK/x8mgohaCpg+CdCEl482bD4tCuAZk2DyliruiNTIZxRCoWkDqJEnAiA==",
"engines": {
"node": ">=6.0.0"
}
@@ -4205,12 +4205,12 @@
}
},
"node_modules/readdirp": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz",
"integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==",
"dev": true,
"engines": {
"node": ">= 14.18.0"
"node": ">= 20.19.0"
},
"funding": {
"type": "individual",
@@ -4632,12 +4632,12 @@
}
},
"node_modules/socket.io-adapter": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.7.tgz",
"integrity": "sha512-e0LyK91f3cUxTmv95/KzoLg47+zF+s/sbxRGDNsyG4dmIP8ZSX8ax6byOxfJXeNNtS/8AZlfD+uP7gBeR7DLlg==",
"version": "2.5.8",
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.8.tgz",
"integrity": "sha512-6Oy52pbg+kvdCVvjcN+FnY7BvxZ7cIHNScbvztT/It5d0vbwoJoVZmF2gjJmnV0/4WlXRfG15zc45ySk9Ah8bw==",
"dependencies": {
"debug": "~4.4.1",
"ws": "~8.20.1"
"ws": "~8.21.0"
}
},
"node_modules/socket.io-adapter/node_modules/debug": {
@@ -4757,9 +4757,9 @@
}
},
"node_modules/tar": {
"version": "7.5.13",
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.13.tgz",
"integrity": "sha512-tOG/7GyXpFevhXVh8jOPJrmtRpOTsYqUIkVdVooZYJS/z8WhfQUX8RJILmeuJNinGAMSu1veBr4asSHFt5/hng==",
"version": "7.5.16",
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.16.tgz",
"integrity": "sha512-56adEpPMouktRlBLXiaYFFzZ/3+JXa8P9n7WbR+ibIjtviN55mEaOkiysCnPnWm+7kkui1Dn8J9l+g6zV8731w==",
"optional": true,
"dependencies": {
"@isaacs/fs-minipass": "^4.0.0",
@@ -5312,9 +5312,9 @@
"dev": true
},
"node_modules/ws": {
"version": "8.20.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.1.tgz",
"integrity": "sha512-It4dO0K5v//JtTXuPkfEOaI3uUN87iYPnqo/ZzqCoG3g8uhA66QUMs/SrM0YK7/NAu+r4LMh/9dq2A7k+rHs+w==",
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
"engines": {
"node": ">=10.0.0"
},
@@ -5429,9 +5429,9 @@
"dev": true
},
"@adobe/jsonschema2md": {
"version": "8.0.8",
"resolved": "https://registry.npmjs.org/@adobe/jsonschema2md/-/jsonschema2md-8.0.8.tgz",
"integrity": "sha512-KqYjZxjvCj7/AlvVtXVKz1AJk+5f3LFnuWi8B2N1sRsJX3oCKNI/XXkns5uChaEL+qAazkvbh7AQd8kANtbjLA==",
"version": "8.0.11",
"resolved": "https://registry.npmjs.org/@adobe/jsonschema2md/-/jsonschema2md-8.0.11.tgz",
"integrity": "sha512-WRfZRqoyQqQ5eRWcfFPa/r3UUnOoKqREsED09pHj6AU3upcNdw/Mj28CYX8C5SUyov2VjIOhZZSsNaUovm6tUw==",
"dev": true,
"requires": {
"@types/json-schema": "^7.0.8",
@@ -5439,13 +5439,13 @@
"@types/unist": "^3.0.3",
"es2015-i18n-tag": "1.6.1",
"ferrum": "1.9.4",
"fs-extra": "11.3.2",
"fs-extra": "11.3.4",
"github-slugger": "2.0.0",
"js-yaml": "4.1.1",
"json-schema": "^0.4.0",
"mdast-builder": "1.1.1",
"mdast-util-to-string": "4.0.0",
"readdirp": "4.1.2",
"readdirp": "5.0.0",
"remark-gfm": "^4.0.0",
"remark-parse": "11.0.0",
"remark-stringify": "11.0.0",
@@ -6598,9 +6598,9 @@
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
},
"engine.io": {
"version": "6.6.8",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.8.tgz",
"integrity": "sha512-2agL3ueZhqxoVrfmntO8yuVj+uNSlIOnhykYHk3Cq0ShYPdUjjUiSJrQvXjq01I9jAuI0Zl2YO8Evv5Mqytm5g==",
"version": "6.6.9",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.9.tgz",
"integrity": "sha512-clKkw4C7nJ22mGgoVcCg6V/W/TxdNyIOTr89k2ONZu81qqkddPFDF0LXcbAwhzPD8DjkiRCjzuiO6Y+fkpD4vg==",
"requires": {
"@types/cors": "^2.8.12",
"@types/node": ">=10.0.0",
@@ -6611,7 +6611,7 @@
"cors": "~2.8.5",
"debug": "~4.4.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.20.1"
"ws": "~8.21.0"
},
"dependencies": {
"cookie": {
@@ -7119,9 +7119,9 @@
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="
},
"fs-extra": {
"version": "11.3.2",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.2.tgz",
"integrity": "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A==",
"version": "11.3.4",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.4.tgz",
"integrity": "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
@@ -7213,9 +7213,9 @@
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="
},
"graceful-fs": {
"version": "4.2.9",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==",
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true
},
"has-symbols": {
@@ -7372,9 +7372,9 @@
"dev": true
},
"jsonfile": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz",
"integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==",
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
"integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6",
@@ -8095,9 +8095,9 @@
"optional": true
},
"nodemailer": {
"version": "8.0.5",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.5.tgz",
"integrity": "sha512-0PF8Yb1yZuQfQbq+5/pZJrtF6WQcjTd5/S4JOHs9PGFxuTqoB/icwuB44pOdURHJbRKX1PPoJZtY7R4VUoCC8w=="
"version": "8.0.11",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.11.tgz",
"integrity": "sha512-nrO/pDAUKl+wXX+lx16tDLbnm0fW6sK/x8mgohaCpg+CdCEl482bD4tCuAZk2DyliruiNTIZxRCoWkDqJEnAiA=="
},
"object-assign": {
"version": "4.1.1",
@@ -8380,9 +8380,9 @@
}
},
"readdirp": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz",
"integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==",
"dev": true
},
"remark-gfm": {
@@ -8669,12 +8669,12 @@
}
},
"socket.io-adapter": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.7.tgz",
"integrity": "sha512-e0LyK91f3cUxTmv95/KzoLg47+zF+s/sbxRGDNsyG4dmIP8ZSX8ax6byOxfJXeNNtS/8AZlfD+uP7gBeR7DLlg==",
"version": "2.5.8",
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.8.tgz",
"integrity": "sha512-6Oy52pbg+kvdCVvjcN+FnY7BvxZ7cIHNScbvztT/It5d0vbwoJoVZmF2gjJmnV0/4WlXRfG15zc45ySk9Ah8bw==",
"requires": {
"debug": "~4.4.1",
"ws": "~8.20.1"
"ws": "~8.21.0"
},
"dependencies": {
"debug": {
@@ -8762,9 +8762,9 @@
}
},
"tar": {
"version": "7.5.13",
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.13.tgz",
"integrity": "sha512-tOG/7GyXpFevhXVh8jOPJrmtRpOTsYqUIkVdVooZYJS/z8WhfQUX8RJILmeuJNinGAMSu1veBr4asSHFt5/hng==",
"version": "7.5.16",
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.16.tgz",
"integrity": "sha512-56adEpPMouktRlBLXiaYFFzZ/3+JXa8P9n7WbR+ibIjtviN55mEaOkiysCnPnWm+7kkui1Dn8J9l+g6zV8731w==",
"optional": true,
"requires": {
"@isaacs/fs-minipass": "^4.0.0",
@@ -9171,9 +9171,9 @@
"dev": true
},
"ws": {
"version": "8.20.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.1.tgz",
"integrity": "sha512-It4dO0K5v//JtTXuPkfEOaI3uUN87iYPnqo/ZzqCoG3g8uhA66QUMs/SrM0YK7/NAu+r4LMh/9dq2A7k+rHs+w==",
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
"requires": {}
},
"xtend": {
+5 -2
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -228,7 +228,10 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
error: 'family not found'
}
const canDoPurchase = canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil) })
const canDoPurchase = canDoNextPurchase({
fullVersionUntil: parseInt(familyEntry.fullVersionUntil),
fullVersionDebts: parseInt(familyEntry.fullVersionDebts),
})
if (!canDoPurchase) {
const lastPurchase = await database.purchase.findOne({
+5 -2
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -54,7 +54,10 @@ export const createPurchaseRouter = ({ database, websocket }: {
transaction
})
return canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10) })
return canDoNextPurchase({
fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10),
fullVersionDebts: parseInt(familyEntry.fullVersionDebts, 10),
})
})
res.json({
+1 -1
View File
@@ -113,7 +113,7 @@ export interface CreateRegisterDeviceTokenRequest {
}
export interface CanDoPurchaseRequest {
type: 'googleplay' | 'any'
type?: 'googleplay' | 'any'
deviceAuthToken: string
}
+1 -2
View File
@@ -3353,8 +3353,7 @@ export const isCanDoPurchaseRequest: (value: unknown) => value is CanDoPurchaseR
},
"additionalProperties": false,
"required": [
"deviceAuthToken",
"type"
"deviceAuthToken"
],
"definitions": definitions,
"$schema": "http://json-schema.org/draft-07/schema#"
+20 -3
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -37,8 +37,13 @@ export interface FamilyAttributesVersion3 {
u2fKeysVersion: string
}
export interface FamilyAttributesVersion4 {
fullVersionDebts: string
}
export type FamilyAttributes = FamilyAttributesVersion1 &
FamilyAttributesVersion2 & FamilyAttributesVersion3
FamilyAttributesVersion2 & FamilyAttributesVersion3 &
FamilyAttributesVersion4
export type FamilyModel = Sequelize.Model<FamilyAttributes> & FamilyAttributes
export type FamilyModelStatic = typeof Sequelize.Model & {
@@ -76,10 +81,22 @@ export const attributesVersion3: SequelizeAttributes<FamilyAttributesVersion3> =
}
}
export const attributesVersion4: SequelizeAttributes<FamilyAttributesVersion4> = {
fullVersionDebts: {
type: Sequelize.BIGINT,
allowNull: false,
defaultValue: 0,
validate: {
min: 0
}
}
}
export const attributes: SequelizeAttributes<FamilyAttributes> = {
...attributesVersion1,
...attributesVersion2,
...attributesVersion3
...attributesVersion3,
...attributesVersion4
}
export const createFamilyModel = (sequelize: Sequelize.Sequelize): FamilyModelStatic => sequelize.define('Family', attributes) as FamilyModelStatic
@@ -0,0 +1,39 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
import { attributesVersion4 as familyAttributes } from '../../family'
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.addColumn('Families', 'fullVersionDebts', {
...familyAttributes.fullVersionDebts
}, {
transaction
})
})
}
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.removeColumn('Families', 'fullVersionDebts', { transaction })
})
}
+3 -2
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -82,7 +82,8 @@ export async function createFamily ({
fullVersionUntil: (Date.now() + 1000 * 60 * 60 * 24 * 14).toString(10),
hasFullVersion: true,
nextServerKeyRequestSeq: '1',
u2fKeysVersion: generateVersionId()
u2fKeysVersion: generateVersionId(),
fullVersionDebts: '0'
}, { transaction })
// create parent user
+13 -5
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -57,11 +57,19 @@ export const addPurchase = async ({ database, familyId, type, service, transacti
}
const previousFullVersionEndTime = familyEntry.fullVersionUntil
const previousFullVersionDebts = parseInt(familyEntry.fullVersionDebts, 10)
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + (type === 'year' ? year : month)
const typeDuration = type === 'year' ? year : month
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
familyEntry.hasFullVersion = true
if (typeDuration > previousFullVersionDebts) {
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + typeDuration - previousFullVersionDebts
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
familyEntry.fullVersionDebts = '0'
familyEntry.hasFullVersion = true
} else {
familyEntry.fullVersionDebts = (previousFullVersionDebts - typeDuration).toString(10)
}
await familyEntry.save({ transaction })
@@ -72,7 +80,7 @@ export const addPurchase = async ({ database, familyId, type, service, transacti
type,
loggedAt: Date.now().toString(10),
previousFullVersionEndTime,
newFullVersionEndTime: newFullVersionUntil.toString(10)
newFullVersionEndTime: familyEntry.fullVersionUntil
}, {
transaction
})
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -15,6 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export const canDoNextPurchase = ({ fullVersionUntil }: {fullVersionUntil: number}) => (
fullVersionUntil < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
export const canDoNextPurchase = ({ fullVersionUntil, fullVersionDebts }: {
fullVersionUntil: number
fullVersionDebts: number
}) => (
(fullVersionUntil - fullVersionDebts) < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
)
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2026 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -43,7 +43,7 @@ export const requireFamilyEntry = async ({ database, deviceAuthToken, transactio
where: {
familyId: deviceEntry.familyId
},
attributes: ['fullVersionUntil'],
attributes: ['fullVersionUntil', 'fullVersionDebts'],
transaction
})
@@ -52,7 +52,8 @@ export const requireFamilyEntry = async ({ database, deviceAuthToken, transactio
}
const familyEntry = {
fullVersionUntil: familyEntryUnsafe.fullVersionUntil
fullVersionUntil: familyEntryUnsafe.fullVersionUntil,
fullVersionDebts: familyEntryUnsafe.fullVersionDebts,
}
return familyEntry