Compare commits

...
11 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
Jonas Lochmann 0b6ece0d28 Update dependencies 2026-05-18 02:00:00 +02:00
Jonas Lochmann 271b27ffe9 Update dependencies 2026-05-18 02:00:00 +02:00
jonas-l b80b74b072 Merge pull request 'Fix eslint COPY in Dockerfile' (#46) from jaakristioja/timelimit-server:fix-eslint-in-dockerfile into master
Reviewed-on: https://codeberg.org/timelimit/timelimit-server/pulls/46
2026-05-17 15:16:39 +02:00
Jaak Ristioja 190ae54602 Fix eslint COPY in Dockerfile
Broken since commit a13656b27d.
2026-05-14 23:42:11 +03:00
Jonas Lochmann eb87d331b3 Update dependencies 2026-05-04 02:00:00 +02:00
Jonas Lochmann 5a6f37e4c7 Update dependencies 2026-04-06 02:00:00 +02:00
Jonas Lochmann bd4b5b206b Update dependencies 2026-03-30 02:00:00 +02:00
Jonas Lochmann a8db1ec1a9 Update dependencies 2026-03-30 02:00:00 +02:00
15 changed files with 392 additions and 512 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json package-lock.json tsconfig.json .eslintignore .eslintrc.js Readme.md /usr/src/app/
COPY package.json package-lock.json tsconfig.json eslint.config.mjs Readme.md /usr/src/app/
COPY src/ /usr/src/app/src/
COPY scripts/ /usr/src/app/scripts/
COPY other/ /usr/src/app/other/
+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`
+267 -483
View File
File diff suppressed because it is too large Load Diff
+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