mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63c23060f6 | ||
|
|
c3793f71a8 | ||
|
|
c693cfdbd4 | ||
|
|
d3675d484b | ||
|
|
053c59899b | ||
|
|
c1e2ea8c84 | ||
|
|
07ee3c268a | ||
|
|
0f92e6b1b7 | ||
|
|
b4a3862c1e | ||
|
|
24fa354f09 | ||
|
|
3d307bee6e | ||
|
|
d227f112e4 | ||
|
|
d83b8a2c26 | ||
|
|
333ac4a8a2 | ||
|
|
77e39752ed | ||
|
|
7c81f50ad2 | ||
|
|
44e7d16b5c | ||
|
|
473fbe80e9 | ||
|
|
1930dd0a27 | ||
|
|
a79fcf235e | ||
|
|
cb1347fffa | ||
|
|
48ecbd8ada | ||
|
|
e6cc08a292 | ||
|
|
120ea33547 |
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
scripts
|
||||
@@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
],
|
||||
env: {
|
||||
node: true
|
||||
}
|
||||
};
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
FROM node:24-alpine
|
||||
FROM node:16-alpine
|
||||
|
||||
# Create app directories
|
||||
RUN mkdir -p /usr/src/app
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install app dependencies
|
||||
COPY package.json package-lock.json tsconfig.json eslint.config.mjs Readme.md /usr/src/app/
|
||||
COPY package.json package-lock.json tsconfig.json .eslintignore .eslintrc.js Readme.md /usr/src/app/
|
||||
COPY src/ /usr/src/app/src/
|
||||
COPY scripts/ /usr/src/app/scripts/
|
||||
COPY other/ /usr/src/app/other/
|
||||
|
||||
+1
-6
@@ -96,14 +96,10 @@ Use this to unlock all features for one user for a specified duration.
|
||||
|
||||
### request
|
||||
|
||||
request properties: ``purchaseToken``, ``purchaseId`` and ``dryRun``
|
||||
request properties: ``purchaseToken`` and ``purchaseId``
|
||||
|
||||
- ``purchasetoken`` is a string which the client shows at the purchase screen
|
||||
- ``purchaseId`` is the ID that is used at the bill
|
||||
- ``dryRun`` is a boolean
|
||||
- setting true will skip the actual unlocking
|
||||
- false will add a four week tolerance to the token expiry to permit checking now and unlocking later
|
||||
- ``type`` is a string and must be ``year``, ``month`` or ``unpaid14``
|
||||
|
||||
### response
|
||||
|
||||
@@ -124,7 +120,6 @@ The response contains the following properties:
|
||||
- optional object
|
||||
- should be shown to the support
|
||||
- ``wasAlreadyExecuted`` (boolean, set if and only if ``ok`` is true)
|
||||
- ``mail`` (string, set if and only if ``ok`` is true)
|
||||
|
||||
If the request was malformed: HTTP status code 400 Bad Request
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ 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
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceAuthToken"
|
||||
"deviceAuthToken",
|
||||
"type"
|
||||
],
|
||||
"definitions": {},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
|
||||
+57
-5
@@ -130,8 +130,6 @@
|
||||
|
||||
* [SerializedMarkTaskPendingAction](./serializedapplogicaction-definitions-serializedmarktaskpendingaction.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedMarkTaskPendingAction`
|
||||
|
||||
* [SerializedPingAction](./serializedapplogicaction-definitions-serializedpingaction.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction`
|
||||
|
||||
* [SerializedRemoveCategoryAppsAction](./serializedparentaction-definitions-serializedremovecategoryappsaction.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedRemoveCategoryAppsAction`
|
||||
|
||||
* [SerializedRemoveInstalledAppsAction](./serializedapplogicaction-definitions-serializedremoveinstalledappsaction.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedRemoveInstalledAppsAction`
|
||||
@@ -240,8 +238,6 @@
|
||||
|
||||
* [ServerKeyResponse](./serverdatastatus-definitions-serverkeyresponse.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerKeyResponse`
|
||||
|
||||
* [ServerPing](./serverdatastatus-definitions-serverping.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerPing`
|
||||
|
||||
* [ServerSessionDurationItem](./serverdatastatus-definitions-serversessiondurationitem.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerSessionDurationItem`
|
||||
|
||||
* [ServerTimeLimitRule](./serverdatastatus-definitions-servertimelimitrule.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerTimeLimitRule`
|
||||
@@ -274,6 +270,14 @@
|
||||
|
||||
* [Untitled object in ClientPullChangesRequest](./clientpullchangesrequest-definitions-clientdatastatus-properties-devicesdetail.md) – `https://timelimit.io/ClientPullChangesRequest#/definitions/ClientDataStatus/properties/devicesDetail`
|
||||
|
||||
* [Untitled object in ClientPullChangesRequest](./clientpullchangesrequest-definitions-clientdatastatus-properties-apps.md) – `https://timelimit.io/ClientPullChangesRequest#/definitions/ClientDataStatus/properties/apps`
|
||||
|
||||
* [Untitled object in ClientPullChangesRequest](./clientpullchangesrequest-definitions-clientdatastatus-properties-categories.md) – `https://timelimit.io/ClientPullChangesRequest#/definitions/ClientDataStatus/properties/categories`
|
||||
|
||||
* [Untitled object in ClientPullChangesRequest](./clientpullchangesrequest-definitions-clientdatastatus-properties-devicesdetail.md) – `https://timelimit.io/ClientPullChangesRequest#/definitions/ClientDataStatus/properties/devicesDetail`
|
||||
|
||||
* [Untitled object in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items`
|
||||
|
||||
* [Untitled object in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items`
|
||||
|
||||
### Arrays
|
||||
@@ -302,6 +306,32 @@
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-updatedoradded.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/updatedOrAdded`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddinstalledappsaction-properties-apps.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddInstalledAppsAction/properties/apps`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items-properties-as.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items/properties/as`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items-properties-as-items.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items/properties/as/items`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items-properties-sdl.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items/properties/sdl`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedaddusedtimeactionversion2-properties-i-items-properties-sdl-items.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedAddUsedTimeActionVersion2/properties/i/items/properties/sdl/items`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedremoveinstalledappsaction-properties-packagenames.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedRemoveInstalledAppsAction/properties/packageNames`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-removed.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/removed`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-removed-items.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/removed/items`
|
||||
|
||||
* [Untitled array in SerializedAppLogicAction](./serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-updatedoradded.md) – `https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/updatedOrAdded`
|
||||
|
||||
* [Untitled array in SerializedParentAction](./serializedparentaction-definitions-serializedaddcategoryappsaction-properties-packagenames.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedAddCategoryAppsAction/properties/packageNames`
|
||||
|
||||
* [Untitled array in SerializedParentAction](./serializedparentaction-definitions-serializedremovecategoryappsaction-properties-packagenames.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedRemoveCategoryAppsAction/properties/packageNames`
|
||||
|
||||
* [Untitled array in SerializedParentAction](./serializedparentaction-definitions-serializedupdatecategorysortingaction-properties-categoryids.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategorySortingAction/properties/categoryIds`
|
||||
|
||||
* [Untitled array in SerializedParentAction](./serializedparentaction-definitions-serializedaddcategoryappsaction-properties-packagenames.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedAddCategoryAppsAction/properties/packageNames`
|
||||
|
||||
* [Untitled array in SerializedParentAction](./serializedparentaction-definitions-serializedremovecategoryappsaction-properties-packagenames.md) – `https://timelimit.io/SerializedParentAction#/definitions/SerializedRemoveCategoryAppsAction/properties/packageNames`
|
||||
@@ -350,7 +380,29 @@
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-properties-kr.md) – `https://timelimit.io/ServerDataStatus#/properties/kr`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-properties-pings.md) – `https://timelimit.io/ServerDataStatus#/properties/pings`
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-u2fdata-properties-d.md) – `https://timelimit.io/ServerDataStatus#/definitions/U2fData/properties/d`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverdevicelist-properties-data.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceList/properties/data`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverinstalledappsdata-properties-apps.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerInstalledAppsData/properties/apps`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverinstalledappsdata-properties-activities.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerInstalledAppsData/properties/activities`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-networks.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/networks`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryassignedapps-properties-apps.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryAssignedApps/properties/apps`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryusedtimes-properties-times.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryUsedTimes/properties/times`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryusedtimes-properties-sessiondurations.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryUsedTimes/properties/sessionDurations`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedtimelimitrules-properties-rules.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedTimeLimitRules/properties/rules`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorytasks-properties-tasks.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryTasks/properties/tasks`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serveruserlist-properties-data.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUserList/properties/data`
|
||||
|
||||
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-u2fdata-properties-d.md) – `https://timelimit.io/ServerDataStatus#/definitions/U2fData/properties/d`
|
||||
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SerializedMarkTaskPendingAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedPingAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedUpdateInstalledAppsAction"
|
||||
},
|
||||
@@ -312,43 +309,6 @@
|
||||
],
|
||||
"title": "SerializedMarkTaskPendingAction"
|
||||
},
|
||||
"SerializedPingAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"PING"
|
||||
]
|
||||
},
|
||||
"deviceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"event": {
|
||||
"$ref": "#/definitions/PingEvent"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceId",
|
||||
"event",
|
||||
"token",
|
||||
"type"
|
||||
],
|
||||
"title": "SerializedPingAction"
|
||||
},
|
||||
"PingEvent": {
|
||||
"enum": [
|
||||
"clear",
|
||||
"ping",
|
||||
"pong"
|
||||
],
|
||||
"type": "string",
|
||||
"title": "PingEvent"
|
||||
},
|
||||
"SerializedUpdateInstalledAppsAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -67,12 +67,6 @@
|
||||
"$ref": "#/definitions/ServerKeyResponse"
|
||||
}
|
||||
},
|
||||
"pings": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ServerPing"
|
||||
}
|
||||
},
|
||||
"dh": {
|
||||
"$ref": "#/definitions/ServerDhKey"
|
||||
},
|
||||
@@ -933,31 +927,6 @@
|
||||
],
|
||||
"title": "ServerKeyResponse"
|
||||
},
|
||||
"ServerPing": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"deviceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"ping",
|
||||
"pong"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceId",
|
||||
"token",
|
||||
"type"
|
||||
],
|
||||
"title": "ServerPing"
|
||||
},
|
||||
"ServerDhKey": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -18,7 +18,7 @@ https://timelimit.io/CanDoPurchaseRequest
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :---------------------------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type) | `string` | Optional | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-type.md "https://timelimit.io/CanDoPurchaseRequest#/properties/type") |
|
||||
| [type](#type) | `string` | Required | 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 optional
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# PingEvent Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/PingEvent
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## PingEvent Type
|
||||
|
||||
`string` ([PingEvent](serializedapplogicaction-definitions-pingevent.md))
|
||||
|
||||
## PingEvent Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :-------- | :---------- |
|
||||
| `"clear"` | |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
# Untitled string in SerializedAppLogicAction Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/deviceId
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## deviceId Type
|
||||
|
||||
`string`
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
# PingEvent Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/event
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## event Type
|
||||
|
||||
`string` ([PingEvent](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md))
|
||||
|
||||
## event Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :-------- | :---------- |
|
||||
| `"clear"` | |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
# Untitled string in SerializedAppLogicAction Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/token
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## token Type
|
||||
|
||||
`string`
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
# Untitled string in SerializedAppLogicAction Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/type
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## type Type
|
||||
|
||||
`string`
|
||||
|
||||
## type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"PING"` | |
|
||||
@@ -1,114 +0,0 @@
|
||||
# SerializedPingAction Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :----------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- |
|
||||
| Can be instantiated | No | Unknown status | No | Forbidden | Forbidden | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") |
|
||||
|
||||
## SerializedPingAction Type
|
||||
|
||||
`object` ([SerializedPingAction](serializedapplogicaction-definitions-serializedpingaction.md))
|
||||
|
||||
# SerializedPingAction Properties
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------------- | :------- | :------- | :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/type") |
|
||||
| [deviceId](#deviceid) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/deviceId") |
|
||||
| [event](#event) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/event") |
|
||||
| [token](#token) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-token.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/token") |
|
||||
|
||||
## type
|
||||
|
||||
|
||||
|
||||
`type`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/type")
|
||||
|
||||
### type Type
|
||||
|
||||
`string`
|
||||
|
||||
### type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"PING"` | |
|
||||
|
||||
## deviceId
|
||||
|
||||
|
||||
|
||||
`deviceId`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/deviceId")
|
||||
|
||||
### deviceId Type
|
||||
|
||||
`string`
|
||||
|
||||
## event
|
||||
|
||||
|
||||
|
||||
`event`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string` ([PingEvent](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md))
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/event")
|
||||
|
||||
### event Type
|
||||
|
||||
`string` ([PingEvent](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md))
|
||||
|
||||
### event Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :-------- | :---------- |
|
||||
| `"clear"` | |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
|
||||
## token
|
||||
|
||||
|
||||
|
||||
`token`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-token.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/token")
|
||||
|
||||
### token Type
|
||||
|
||||
`string`
|
||||
@@ -30,8 +30,6 @@ any of
|
||||
|
||||
* [SerializedMarkTaskPendingAction](serializedapplogicaction-definitions-serializedmarktaskpendingaction.md "check type definition")
|
||||
|
||||
* [SerializedPingAction](serializedapplogicaction-definitions-serializedpingaction.md "check type definition")
|
||||
|
||||
* [SerializedUpdateInstalledAppsAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction.md "check type definition")
|
||||
|
||||
* [SerializedRemoveInstalledAppsAction](serializedapplogicaction-definitions-serializedremoveinstalledappsaction.md "check type definition")
|
||||
@@ -690,122 +688,6 @@ Reference this group by using
|
||||
|
||||
`string`
|
||||
|
||||
## Definitions group SerializedPingAction
|
||||
|
||||
Reference this group by using
|
||||
|
||||
```json
|
||||
{"$ref":"https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction"}
|
||||
```
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------------- | :------- | :------- | :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-7) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/type") |
|
||||
| [deviceId](#deviceid) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/deviceId") |
|
||||
| [event](#event) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/event") |
|
||||
| [token](#token) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-token.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/token") |
|
||||
|
||||
### type
|
||||
|
||||
|
||||
|
||||
`type`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/type")
|
||||
|
||||
#### type Type
|
||||
|
||||
`string`
|
||||
|
||||
#### type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"PING"` | |
|
||||
|
||||
### deviceId
|
||||
|
||||
|
||||
|
||||
`deviceId`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/deviceId")
|
||||
|
||||
#### deviceId Type
|
||||
|
||||
`string`
|
||||
|
||||
### event
|
||||
|
||||
|
||||
|
||||
`event`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string` ([PingEvent](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md))
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/event")
|
||||
|
||||
#### event Type
|
||||
|
||||
`string` ([PingEvent](serializedapplogicaction-definitions-serializedpingaction-properties-pingevent.md))
|
||||
|
||||
#### event Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :-------- | :---------- |
|
||||
| `"clear"` | |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
|
||||
### token
|
||||
|
||||
|
||||
|
||||
`token`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedpingaction-properties-token.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedPingAction/properties/token")
|
||||
|
||||
#### token Type
|
||||
|
||||
`string`
|
||||
|
||||
## Definitions group PingEvent
|
||||
|
||||
Reference this group by using
|
||||
|
||||
```json
|
||||
{"$ref":"https://timelimit.io/SerializedAppLogicAction#/definitions/PingEvent"}
|
||||
```
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :------- | :--- | :------- | :------- | :--------- |
|
||||
|
||||
## Definitions group SerializedUpdateInstalledAppsAction
|
||||
|
||||
Reference this group by using
|
||||
@@ -816,7 +698,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------- | :-------- | :------- | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-8) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateInstalledAppsAction/properties/type") |
|
||||
| [type](#type-7) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateInstalledAppsAction/properties/type") |
|
||||
| [b](#b) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction-properties-b.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateInstalledAppsAction/properties/b") |
|
||||
| [d](#d-1) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction-properties-d.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateInstalledAppsAction/properties/d") |
|
||||
| [w](#w) | `boolean` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateinstalledappsaction-properties-w.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateInstalledAppsAction/properties/w") |
|
||||
@@ -911,7 +793,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :---------------------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-9) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedremoveinstalledappsaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedRemoveInstalledAppsAction/properties/type") |
|
||||
| [type](#type-8) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedremoveinstalledappsaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedRemoveInstalledAppsAction/properties/type") |
|
||||
| [packageNames](#packagenames) | `array` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedremoveinstalledappsaction-properties-packagenames.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedRemoveInstalledAppsAction/properties/packageNames") |
|
||||
|
||||
### type
|
||||
@@ -968,9 +850,9 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------------------- | :------- | :------- | :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-10) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/type") |
|
||||
| [type](#type-9) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/type") |
|
||||
| [dsn](#dsn-1) | `number` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-dsn.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/dsn") |
|
||||
| [deviceId](#deviceid-1) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/deviceId") |
|
||||
| [deviceId](#deviceid) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-deviceid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/deviceId") |
|
||||
| [categoryId](#categoryid-1) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-categoryid.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/categoryId") |
|
||||
| [dataType](#datatype) | `number` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-datatype.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/dataType") |
|
||||
| [tempKey](#tempkey-1) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsendkeyrequestaction-properties-tempkey.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSendKeyRequestAction/properties/tempKey") |
|
||||
@@ -1120,7 +1002,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :--------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-11) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsignoutatdeviceaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSignOutAtDeviceAction/properties/type") |
|
||||
| [type](#type-10) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedsignoutatdeviceaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedSignOutAtDeviceAction/properties/type") |
|
||||
|
||||
### type
|
||||
|
||||
@@ -1158,7 +1040,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :--------------- | :------- | :------- | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-12) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serialiezdtrieddisablingdeviceadminaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerialiezdTriedDisablingDeviceAdminAction/properties/type") |
|
||||
| [type](#type-11) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serialiezdtrieddisablingdeviceadminaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerialiezdTriedDisablingDeviceAdminAction/properties/type") |
|
||||
|
||||
### type
|
||||
|
||||
@@ -1196,7 +1078,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------------------------- | :------- | :------- | :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-13) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/type") |
|
||||
| [type](#type-12) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/type") |
|
||||
| [removed](#removed) | `array` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-removed.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/removed") |
|
||||
| [updatedOrAdded](#updatedoradded) | `array` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdateappactivitiesaction-properties-updatedoradded.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateAppActivitiesAction/properties/updatedOrAdded") |
|
||||
|
||||
@@ -1348,7 +1230,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :---------------------------------------------------------- | :-------- | :------- | :------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-14) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/type") |
|
||||
| [type](#type-13) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/type") |
|
||||
| [protectionLevel](#protectionlevel) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-protectionlevel.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/protectionLevel") |
|
||||
| [usageStats](#usagestats) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-usagestats.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/usageStats") |
|
||||
| [notificationAccess](#notificationaccess) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-notificationaccess.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/notificationAccess") |
|
||||
@@ -1636,7 +1518,7 @@ Reference this group by using
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :--------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [type](#type-15) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializeduploaddevicepublickeyaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUploadDevicePublicKeyAction/properties/type") |
|
||||
| [type](#type-14) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializeduploaddevicepublickeyaction-properties-type.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUploadDevicePublicKeyAction/properties/type") |
|
||||
| [key](#key) | `string` | Required | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializeduploaddevicepublickeyaction-properties-key.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUploadDevicePublicKeyAction/properties/key") |
|
||||
|
||||
### type
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# EncryptableParentPassword Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/SerializedParentAction#/definitions/EncryptableParentPassword
|
||||
https://timelimit.io/SerializedParentAction#/definitions/SerializedSetChildPasswordAction/properties/newPassword
|
||||
```
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ https://timelimit.io/SerializedParentAction#/definitions/EncryptableParentPasswo
|
||||
| :------------------ | :--------- | :------------- | :----------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | No | Forbidden | Forbidden | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
|
||||
|
||||
## EncryptableParentPassword Type
|
||||
## newPassword Type
|
||||
|
||||
`object` ([EncryptableParentPassword](serializedparentaction-definitions-encryptableparentpassword.md))
|
||||
|
||||
# EncryptableParentPassword Properties
|
||||
# newPassword Properties
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :------------------------ | :-------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# Untitled string in ServerDataStatus Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/deviceId
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") |
|
||||
|
||||
## deviceId Type
|
||||
|
||||
`string`
|
||||
@@ -1,15 +0,0 @@
|
||||
# Untitled string in ServerDataStatus Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/token
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") |
|
||||
|
||||
## token Type
|
||||
|
||||
`string`
|
||||
@@ -1,24 +0,0 @@
|
||||
# Untitled string in ServerDataStatus Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/type
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") |
|
||||
|
||||
## type Type
|
||||
|
||||
`string`
|
||||
|
||||
## type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
@@ -1,86 +0,0 @@
|
||||
# ServerPing Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/ServerDataStatus#/definitions/ServerPing
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :----------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | No | Forbidden | Forbidden | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") |
|
||||
|
||||
## ServerPing Type
|
||||
|
||||
`object` ([ServerPing](serverdatastatus-definitions-serverping.md))
|
||||
|
||||
# ServerPing Properties
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :-------------------- | :------- | :------- | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [deviceId](#deviceid) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-deviceid.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/deviceId") |
|
||||
| [token](#token) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-token.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/token") |
|
||||
| [type](#type) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-type.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/type") |
|
||||
|
||||
## deviceId
|
||||
|
||||
|
||||
|
||||
`deviceId`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-deviceid.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/deviceId")
|
||||
|
||||
### deviceId Type
|
||||
|
||||
`string`
|
||||
|
||||
## token
|
||||
|
||||
|
||||
|
||||
`token`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-token.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/token")
|
||||
|
||||
### token Type
|
||||
|
||||
`string`
|
||||
|
||||
## type
|
||||
|
||||
|
||||
|
||||
`type`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-type.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/type")
|
||||
|
||||
### type Type
|
||||
|
||||
`string`
|
||||
|
||||
### type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
@@ -1,15 +0,0 @@
|
||||
# Untitled array in ServerDataStatus Schema
|
||||
|
||||
```txt
|
||||
https://timelimit.io/ServerDataStatus#/properties/pings
|
||||
```
|
||||
|
||||
|
||||
|
||||
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ |
|
||||
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") |
|
||||
|
||||
## pings Type
|
||||
|
||||
`object[]` ([ServerPing](serverdatastatus-definitions-serverping.md))
|
||||
@@ -30,7 +30,6 @@ https://timelimit.io/ServerDataStatus
|
||||
| [users](#users) | `object` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serveruserlist.md "https://timelimit.io/ServerDataStatus#/properties/users") |
|
||||
| [krq](#krq) | `array` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-properties-krq.md "https://timelimit.io/ServerDataStatus#/properties/krq") |
|
||||
| [kr](#kr) | `array` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-properties-kr.md "https://timelimit.io/ServerDataStatus#/properties/kr") |
|
||||
| [pings](#pings) | `array` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-properties-pings.md "https://timelimit.io/ServerDataStatus#/properties/pings") |
|
||||
| [dh](#dh) | `object` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdhkey.md "https://timelimit.io/ServerDataStatus#/properties/dh") |
|
||||
| [u2f](#u2f) | `object` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-u2fdata.md "https://timelimit.io/ServerDataStatus#/properties/u2f") |
|
||||
| [fullVersion](#fullversion) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-properties-fullversion.md "https://timelimit.io/ServerDataStatus#/properties/fullVersion") |
|
||||
@@ -253,24 +252,6 @@ https://timelimit.io/ServerDataStatus
|
||||
|
||||
`object[]` ([ServerKeyResponse](serverdatastatus-definitions-serverkeyresponse.md))
|
||||
|
||||
## pings
|
||||
|
||||
|
||||
|
||||
`pings`
|
||||
|
||||
* is optional
|
||||
|
||||
* Type: `object[]` ([ServerPing](serverdatastatus-definitions-serverping.md))
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-properties-pings.md "https://timelimit.io/ServerDataStatus#/properties/pings")
|
||||
|
||||
### pings Type
|
||||
|
||||
`object[]` ([ServerPing](serverdatastatus-definitions-serverping.md))
|
||||
|
||||
## dh
|
||||
|
||||
|
||||
@@ -3468,83 +3449,6 @@ Reference this group by using
|
||||
|
||||
`string`
|
||||
|
||||
## Definitions group ServerPing
|
||||
|
||||
Reference this group by using
|
||||
|
||||
```json
|
||||
{"$ref":"https://timelimit.io/ServerDataStatus#/definitions/ServerPing"}
|
||||
```
|
||||
|
||||
| Property | Type | Required | Nullable | Defined by |
|
||||
| :---------------------- | :------- | :------- | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [deviceId](#deviceid-4) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-deviceid.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/deviceId") |
|
||||
| [token](#token) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-token.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/token") |
|
||||
| [type](#type-2) | `string` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverping-properties-type.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/type") |
|
||||
|
||||
### deviceId
|
||||
|
||||
|
||||
|
||||
`deviceId`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-deviceid.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/deviceId")
|
||||
|
||||
#### deviceId Type
|
||||
|
||||
`string`
|
||||
|
||||
### token
|
||||
|
||||
|
||||
|
||||
`token`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-token.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/token")
|
||||
|
||||
#### token Type
|
||||
|
||||
`string`
|
||||
|
||||
### type
|
||||
|
||||
|
||||
|
||||
`type`
|
||||
|
||||
* is required
|
||||
|
||||
* Type: `string`
|
||||
|
||||
* cannot be null
|
||||
|
||||
* defined in: [ServerDataStatus](serverdatastatus-definitions-serverping-properties-type.md "https://timelimit.io/ServerDataStatus#/definitions/ServerPing/properties/type")
|
||||
|
||||
#### type Type
|
||||
|
||||
`string`
|
||||
|
||||
#### type Constraints
|
||||
|
||||
**enum**: the value of this property must be equal to one of the following values:
|
||||
|
||||
| Value | Explanation |
|
||||
| :------- | :---------- |
|
||||
| `"ping"` | |
|
||||
| `"pong"` | |
|
||||
|
||||
## Definitions group ServerDhKey
|
||||
|
||||
Reference this group by using
|
||||
|
||||
@@ -57,3 +57,5 @@
|
||||
- SIGN_SECRET
|
||||
- used for signing tokens
|
||||
- if not set or set to an empty string, then the features that depend on it are disabled
|
||||
- UA_MAIL_BLOCKLIST
|
||||
- List of user agents, separated by comma, that are not allowed to trigger sign in mails
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
import eslint from '@eslint/js';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default defineConfig(
|
||||
eslint.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
{
|
||||
ignores: ['build', 'scripts']
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { caughtErrors: 'none' }]
|
||||
}
|
||||
}
|
||||
)
|
||||
Generated
+4390
-3047
File diff suppressed because it is too large
Load Diff
+12
-10
@@ -6,10 +6,10 @@
|
||||
"scripts": {
|
||||
"start": "node ./build/index.js",
|
||||
"test": "node scripts/test-launch-with-different-databases.js",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
||||
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
|
||||
"build": "npm run build:clean && npm run build:json && npm run build:ts && npm run lint && npm run build:doc",
|
||||
"build:clean": "rm -rf build",
|
||||
"build:clean": "rimraf build",
|
||||
"build:json": "node ./scripts/build-schemas.js",
|
||||
"build:ts": "tsc",
|
||||
"build:doc": "npm run build:doc:json",
|
||||
@@ -29,8 +29,7 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/timelimit.io/timelimit-server-2018#README",
|
||||
"devDependencies": {
|
||||
"@adobe/jsonschema2md": "^8.0.8",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@adobe/jsonschema2md": "^7.0.0",
|
||||
"@types/basic-auth": "^1.1.3",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/ejs": "^3.1.0",
|
||||
@@ -39,13 +38,15 @@
|
||||
"@types/lodash": "^4.14.166",
|
||||
"@types/node": "^16.11.59",
|
||||
"@types/nodemailer": "^6.4.4",
|
||||
"eslint": "^10.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||
"@typescript-eslint/parser": "^7.18.0",
|
||||
"eslint": "^8.7.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^5.5.4",
|
||||
"typescript-eslint": "^8.56.0",
|
||||
"typescript-json-schema": "^0.52.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": "^8.18.0",
|
||||
"ajv": "^7.0.2",
|
||||
"basic-auth": "^2.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"ejs": "^3.1.5",
|
||||
@@ -55,15 +56,16 @@
|
||||
"jose": "^4.9.3",
|
||||
"lodash": "^4.17.21",
|
||||
"mariadb": "^2.5.2",
|
||||
"nodemailer": "^9.0.4",
|
||||
"nodemailer": "^7.0.9",
|
||||
"pg": "^8.5.1",
|
||||
"pg-hstore": "^2.3.3",
|
||||
"pkijs": "^3.0.16",
|
||||
"rate-limiter-flexible": "^2.1.15",
|
||||
"sequelize": "^6.25.5",
|
||||
"socket.io": "^4.0.1",
|
||||
"umzug": "^3.8.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"sqlite3": "npm:@vscode/sqlite3@^5.1.12-vscode"
|
||||
"sqlite3": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ const { spawnAsync } = require('../process.js')
|
||||
const { sleep } = require('../sleep.js')
|
||||
|
||||
async function startMariadb() {
|
||||
const osUsername = require('os').userInfo().username
|
||||
|
||||
try { await mkdirAsync(tempDir) } catch (ex) {/* ignore */}
|
||||
|
||||
const instanceDir = resolve(tempDir, generateShortToken())
|
||||
@@ -62,12 +60,12 @@ async function startMariadb() {
|
||||
|
||||
for (command of commands) {
|
||||
console.log(command)
|
||||
await spawnAsync('mysql', ['-S', socketPath, '-u', osUsername, '-e', command], { stdio: 'inherit' })
|
||||
await spawnAsync('mysql', ['-S', socketPath, '-u', 'root', '-e', command], { stdio: 'inherit' })
|
||||
}
|
||||
|
||||
return {
|
||||
shutdown: () => {
|
||||
spawnAsync('mysql', ['-S', socketPath, '-u', osUsername, '-e', 'SHUTDOWN;'], { stdio: 'inherit' }).catch((ex) => {
|
||||
spawnAsync('mysql', ['-S', socketPath, '-u', 'root', '-e', 'SHUTDOWN;'], { stdio: 'inherit' }).catch((ex) => {
|
||||
console.warn(ex)
|
||||
})
|
||||
},
|
||||
|
||||
@@ -58,7 +58,7 @@ async function startPostgres() {
|
||||
const password = generateToken() // this database accepts anything
|
||||
|
||||
await spawnAsync('createuser', ['-h', socketDir, username], { stdio: 'inherit' })
|
||||
await spawnAsync('createdb', ['-h', socketDir, '--owner', username, database], { stdio: 'inherit' })
|
||||
await spawnAsync('createdb', ['-h', socketDir, database], { stdio: 'inherit' })
|
||||
|
||||
return {
|
||||
shutdown: () => task.kill('SIGINT'),
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -78,7 +78,6 @@ export { UpdateTimelimitRuleAction } from './updatetimelimitrule'
|
||||
export { UpdateUserFlagsAction } from './updateuserflags'
|
||||
export { UpdateUserLimitLoginCategory } from './updateuserlimitlogincategory'
|
||||
export { MarkTaskPendingAction } from './marktaskpendingaction'
|
||||
export { PingAction } from './ping'
|
||||
export { DeleteChildTaskAction } from './deletechildtaskaction'
|
||||
export { UpdateChildTaskAction } from './updatechildtaskaction'
|
||||
export { ReviewChildTaskAction } from './reviewchildtaskaction'
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 { AppLogicAction } from './basetypes'
|
||||
import { assertIdWithinFamily } from './meta/util'
|
||||
|
||||
const actionType = 'PingAction'
|
||||
|
||||
export class PingAction extends AppLogicAction {
|
||||
readonly deviceId: string
|
||||
readonly event: PingEvent
|
||||
readonly token: string
|
||||
|
||||
constructor ({ deviceId, event, token }: {
|
||||
deviceId: string
|
||||
event: PingEvent
|
||||
token: string
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily({ actionType, field: 'deviceId', value: deviceId })
|
||||
assertIdWithinFamily({ actionType, field: 'token', value: token })
|
||||
|
||||
this.deviceId = deviceId
|
||||
this.event = event
|
||||
this.token = token
|
||||
}
|
||||
|
||||
static parse = ({ deviceId, event, token }: SerializedPingAction) => (
|
||||
new PingAction({ deviceId, event, token })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedPingAction {
|
||||
type: 'PING'
|
||||
deviceId: string
|
||||
event: PingEvent
|
||||
token: string
|
||||
}
|
||||
|
||||
export type PingEvent = 'ping' | 'pong' | 'clear'
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -24,7 +24,6 @@ import { ForceSyncAction, SerializedForceSyncAction } from '../forcesync'
|
||||
import { ReplyToKeyRequestAction, SerializedReplyToKeyRequestAction } from '../replytokeyrequest'
|
||||
import { MarkTaskPendingAction, SerializedMarkTaskPendingAction } from '../marktaskpendingaction'
|
||||
import { UnknownActionTypeException } from '../meta/exception'
|
||||
import { PingAction, SerializedPingAction } from '../ping'
|
||||
import { UpdateInstalledAppsAction, SerializedUpdateInstalledAppsAction } from '../updateinstalledapps'
|
||||
import { RemoveInstalledAppsAction, SerializedRemoveInstalledAppsAction } from '../removeinstalledapps'
|
||||
import { SendKeyRequestAction, SerializedSendKeyRequestAction } from '../sendkeyrequest'
|
||||
@@ -42,7 +41,6 @@ export type SerializedAppLogicAction =
|
||||
SerializedForceSyncAction |
|
||||
SerializedReplyToKeyRequestAction |
|
||||
SerializedMarkTaskPendingAction |
|
||||
SerializedPingAction |
|
||||
SerializedUpdateInstalledAppsAction |
|
||||
SerializedRemoveInstalledAppsAction |
|
||||
SerializedSendKeyRequestAction |
|
||||
@@ -67,8 +65,6 @@ export const parseAppLogicAction = (serialized: SerializedAppLogicAction): AppLo
|
||||
return ReplyToKeyRequestAction.parse(serialized)
|
||||
} else if (serialized.type === 'MARK_TASK_PENDING') {
|
||||
return MarkTaskPendingAction.parse(serialized)
|
||||
} else if (serialized.type === 'PING') {
|
||||
return PingAction.parse(serialized)
|
||||
} else if (serialized.type === 'UPDATE_INSTALLED_APPS') {
|
||||
return UpdateInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'REMOVE_INSTALLED_APPS') {
|
||||
|
||||
+25
-39
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -19,7 +19,7 @@ import { json } from 'body-parser'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest, Conflict } from 'http-errors'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
import { addPurchase, canDoNextPurchase } from '../function/purchase'
|
||||
import { getStatusMessage, setStatusMessage } from '../function/statusmessage'
|
||||
import { EventHandler } from '../monitoring/eventhandler'
|
||||
@@ -28,7 +28,7 @@ import { verifyIdentitifyToken, TokenValidationException } from '../util/identit
|
||||
import { WebsocketApi } from '../websocket'
|
||||
|
||||
export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
eventHandler: EventHandler
|
||||
}) => {
|
||||
@@ -60,9 +60,7 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
|
||||
router.get('/status-message', async (_, res, next) => {
|
||||
try {
|
||||
const currentStatusMessage = await database.transaction(async (transaction) => {
|
||||
return getStatusMessage({ transaction })
|
||||
})
|
||||
const currentStatusMessage = await getStatusMessage({ database })
|
||||
|
||||
res.json({
|
||||
statusMessage: currentStatusMessage
|
||||
@@ -104,12 +102,12 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
}
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
const userEntryUnsafe = await transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await database.user.findOne({
|
||||
where: {
|
||||
mail
|
||||
},
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -121,12 +119,13 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
}
|
||||
|
||||
await addPurchase({
|
||||
transaction,
|
||||
database,
|
||||
familyId: userEntry.familyId,
|
||||
type,
|
||||
service: 'directpurchase',
|
||||
transactionId: 'legacyunlock-' + type + '-' + generatePurchaseId(),
|
||||
websocket
|
||||
websocket,
|
||||
transaction
|
||||
})
|
||||
})
|
||||
|
||||
@@ -141,23 +140,15 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
if (
|
||||
typeof req.body !== 'object' ||
|
||||
typeof req.body.purchaseToken !== 'string' ||
|
||||
typeof req.body.purchaseId !== 'string' ||
|
||||
typeof req.body.dryRun !== 'boolean' ||
|
||||
typeof req.body.type !== 'string'
|
||||
typeof req.body.purchaseId !== 'string'
|
||||
) {
|
||||
throw new BadRequest()
|
||||
}
|
||||
|
||||
const purchaseToken: string = req.body.purchaseToken
|
||||
const purchaseId: string = req.body.purchaseId
|
||||
const dryRun: boolean = req.body.dryRun
|
||||
const type: string = req.body.type
|
||||
|
||||
if (type !== 'month' && type !== 'year' && type !== 'unpaid14') {
|
||||
throw new BadRequest()
|
||||
}
|
||||
|
||||
const tokenContent = await verifyIdentitifyToken(purchaseToken, dryRun)
|
||||
const tokenContent = await verifyIdentitifyToken(purchaseToken)
|
||||
|
||||
if (tokenContent.purpose !== 'purchase') {
|
||||
res.json({ ok: false, error: 'token invalid', detail: 'wrong purpose' })
|
||||
@@ -166,14 +157,14 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
}
|
||||
|
||||
const response = await database.transaction(async (transaction) => {
|
||||
const userValid = await transaction.legacy.database.user.count({
|
||||
const userValid = await database.user.count({
|
||||
where: {
|
||||
familyId: tokenContent.familyId,
|
||||
userId: tokenContent.userId,
|
||||
mail: tokenContent.mail,
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!userValid) return {
|
||||
@@ -186,7 +177,7 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
|
||||
if (tokenContent.mail !== '') mailToReturn = tokenContent.mail
|
||||
else {
|
||||
const userEntryWithMail = await transaction.legacy.database.user.findOne({
|
||||
const userEntryWithMail = await database.user.findOne({
|
||||
where: {
|
||||
familyId: tokenContent.familyId,
|
||||
mail: {
|
||||
@@ -194,7 +185,7 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
},
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!userEntryWithMail) return {
|
||||
@@ -208,12 +199,11 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
|
||||
let wasAlreadyExecuted: boolean
|
||||
|
||||
const oldPurchaseByPurchaseId = await transaction.legacy.database.purchase.findOne({
|
||||
const oldPurchaseByPurchaseId = await database.purchase.findOne({
|
||||
where: {
|
||||
service: 'directpurchase',
|
||||
transactionId: purchaseId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
}
|
||||
})
|
||||
|
||||
if (oldPurchaseByPurchaseId === null) wasAlreadyExecuted = false
|
||||
@@ -224,11 +214,11 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
}
|
||||
|
||||
if (!wasAlreadyExecuted) {
|
||||
const familyEntry = await transaction.legacy.database.family.findOne({
|
||||
const familyEntry = await database.family.findOne({
|
||||
where: {
|
||||
familyId: tokenContent.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!familyEntry) return {
|
||||
@@ -236,17 +226,14 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
error: 'family not found'
|
||||
}
|
||||
|
||||
const canDoPurchase = canDoNextPurchase({
|
||||
fullVersionUntil: parseInt(familyEntry.fullVersionUntil),
|
||||
fullVersionDebts: parseInt(familyEntry.fullVersionDebts),
|
||||
})
|
||||
const canDoPurchase = canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil) })
|
||||
|
||||
if (!canDoPurchase) {
|
||||
const lastPurchase = await transaction.legacy.database.purchase.findOne({
|
||||
const lastPurchase = await database.purchase.findOne({
|
||||
where: {
|
||||
familyId: tokenContent.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
order: [['loggedAt', 'DESC']],
|
||||
limit: 1
|
||||
})
|
||||
@@ -263,17 +250,16 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
||||
}
|
||||
}
|
||||
|
||||
if (!dryRun) {
|
||||
await addPurchase({
|
||||
transaction,
|
||||
database,
|
||||
familyId: tokenContent.familyId,
|
||||
type,
|
||||
type: 'year',
|
||||
service: 'directpurchase',
|
||||
transactionId: purchaseId,
|
||||
websocket,
|
||||
transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
|
||||
+15
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2024 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
|
||||
@@ -17,19 +17,26 @@
|
||||
|
||||
import { json } from 'body-parser'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest } from 'http-errors'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { BadRequest, Forbidden } from 'http-errors'
|
||||
import { config } from '../config'
|
||||
import { Database } from '../database'
|
||||
import { sendLoginCode, signInByMailCode } from '../function/authentication/login-by-mail'
|
||||
import { isMailAddressCoveredByWhitelist, isMailServerBlacklisted, sanitizeMailAddress } from '../util/mail'
|
||||
import {
|
||||
isSendMailLoginCodeRequest,
|
||||
isSignInByMailCodeRequest
|
||||
} from './validator'
|
||||
import { analyze } from './integrity'
|
||||
|
||||
export const createAuthRouter = (database: SimpleDatabase) => {
|
||||
export const createAuthRouter = (database: Database) => {
|
||||
const router = Router()
|
||||
|
||||
router.post('/send-mail-login-code-v2', json(), async (req, res, next) => {
|
||||
const info = {
|
||||
ua: req.headers['user-agent'],
|
||||
cert: analyze(req),
|
||||
}
|
||||
|
||||
try {
|
||||
if (!isSendMailLoginCodeRequest(req.body)) {
|
||||
throw new BadRequest()
|
||||
@@ -45,12 +52,15 @@ export const createAuthRouter = (database: SimpleDatabase) => {
|
||||
res.json({ mailAddressNotWhitelisted: true })
|
||||
} else if (isMailServerBlacklisted(mail)) {
|
||||
res.json({ mailServerBlacklisted: true })
|
||||
} else if (config.uaMailBlocklist.indexOf(req.headers['user-agent'] || '') !== -1) {
|
||||
throw new Forbidden()
|
||||
} else {
|
||||
const { mailLoginToken } = await sendLoginCode({
|
||||
mail,
|
||||
deviceAuthToken: req.body.deviceAuthToken,
|
||||
locale: req.body.locale,
|
||||
database
|
||||
database,
|
||||
info: Buffer.from(JSON.stringify(info), 'utf8')
|
||||
})
|
||||
|
||||
res.json({ mailLoginToken })
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -18,7 +18,7 @@
|
||||
import { json } from 'body-parser'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest } from 'http-errors'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
import { addChildDevice } from '../function/child/add-device'
|
||||
import { logoutAtPrimaryDevice } from '../function/child/logout-at-primary-device'
|
||||
import { setPrimaryDevice } from '../function/child/set-primary-device'
|
||||
@@ -27,7 +27,7 @@ import { isRegisterChildDeviceRequest, isRequestWithAuthToken, isUpdatePrimaryDe
|
||||
import { EventHandler } from '../monitoring/eventhandler'
|
||||
|
||||
export const createChildRouter = ({ database, websocket, eventHandler }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
eventHandler: EventHandler
|
||||
}) => {
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -18,7 +18,7 @@
|
||||
import * as basicAuth from 'basic-auth'
|
||||
import * as express from 'express'
|
||||
import { VisibleConnectedDevicesManager } from '../connected-devices'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
import { EventHandler } from '../monitoring/eventhandler'
|
||||
import { WebsocketApi } from '../websocket'
|
||||
import { createAdminRouter } from './admin'
|
||||
@@ -31,7 +31,7 @@ import { createSyncRouter } from './sync'
|
||||
const adminToken = process.env.ADMIN_TOKEN || ''
|
||||
|
||||
export const createApi = ({ database, websocket, connectedDevicesManager, eventHandler }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
eventHandler: EventHandler
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { X509Certificate } from 'crypto'
|
||||
import { Request } from 'express'
|
||||
import { fromBER, Sequence, Integer, OctetString, Set } from 'asn1js'
|
||||
import { Certificate } from 'pkijs'
|
||||
|
||||
export interface CertInfo {
|
||||
applicationCerts: Array<string>
|
||||
}
|
||||
|
||||
export function analyze(req: Request): CertInfo | null {
|
||||
try {
|
||||
const certStr = req.headers['clientcertificate']
|
||||
|
||||
if (typeof certStr !== 'string') return null
|
||||
|
||||
const nativeCert = new X509Certificate(decodeURIComponent(certStr))
|
||||
|
||||
const now = Date.now()
|
||||
const from = Date.parse(nativeCert.validFrom)
|
||||
const to = Date.parse(nativeCert.validTo)
|
||||
|
||||
if (from > now || to < now) return null
|
||||
if (from > to || from + 1000 * 60 * 5 < to) return null
|
||||
|
||||
const cert1 = fromBER(nativeCert.raw)
|
||||
|
||||
if (cert1.offset === -1) return null
|
||||
|
||||
const cert2 = new Certificate({ schema: cert1.result })
|
||||
const androidExtension = (cert2.extensions || []).find((item) => item.extnID === '1.3.6.1.4.1.11129.2.1.17')?.extnValue?.valueBlock?.valueHexView
|
||||
|
||||
if (!androidExtension) return null
|
||||
|
||||
const androidExtensionParsed = fromBER(androidExtension)
|
||||
|
||||
if (androidExtensionParsed.offset === -1) return null
|
||||
|
||||
const androidExtensionSequence = androidExtensionParsed.result
|
||||
|
||||
if (!(androidExtensionSequence instanceof Sequence)) return null
|
||||
|
||||
const versionInteger = androidExtensionSequence.valueBlock.value[0]
|
||||
|
||||
if (!(versionInteger instanceof Integer)) return null
|
||||
|
||||
const versionValue = versionInteger.valueBlock.valueDec
|
||||
|
||||
const authorizationLists = androidExtensionSequence.valueBlock.value.slice(6, 8)
|
||||
|
||||
let applicationId = null
|
||||
|
||||
for (const authList of authorizationLists) {
|
||||
if (!(authList instanceof Sequence)) continue
|
||||
|
||||
for (const authListItem of authList.valueBlock.value) {
|
||||
if (
|
||||
// version 1 does not provide this data structure
|
||||
versionValue !== 1 &&
|
||||
authListItem.idBlock.tagNumber === 709
|
||||
) {
|
||||
if (!('value' in authListItem.valueBlock)) continue
|
||||
|
||||
const value = (authListItem.valueBlock as unknown as { value: object }).value
|
||||
|
||||
if (!Array.isArray(value) || value.length !== 1) continue
|
||||
|
||||
if (value[0] instanceof OctetString) applicationId = value[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!applicationId) return null
|
||||
|
||||
const parsedApplicationId = fromBER(applicationId.valueBlock.valueHexView)
|
||||
|
||||
if (parsedApplicationId.offset === -1) return null
|
||||
|
||||
if (!(parsedApplicationId.result instanceof Sequence)) return null
|
||||
|
||||
const parsedApplicationIdInfo = parsedApplicationId.result.valueBlock.value
|
||||
|
||||
if (parsedApplicationIdInfo.length !== 2) return null
|
||||
|
||||
const signatureDigests = parsedApplicationIdInfo[1]
|
||||
|
||||
if (!(signatureDigests instanceof Set)) return null
|
||||
|
||||
const applicationCerts = []
|
||||
|
||||
for (const cert of signatureDigests.valueBlock.value) {
|
||||
if (cert instanceof OctetString) {
|
||||
applicationCerts.push(Buffer.from(cert.valueBlock.valueHexView).toString('hex'))
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
applicationCerts
|
||||
}
|
||||
} catch (ex) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
+20
-18
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -20,7 +20,7 @@ import { createHmac } from 'crypto'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest, Forbidden, Unauthorized } from 'http-errors'
|
||||
import { config } from '../config'
|
||||
import { SimpleDatabase, SimpleDatabaseTransaction } from '../database/simple'
|
||||
import { Database, Transaction } from '../database'
|
||||
import { deleteAccount } from '../function/cleanup/account-deletion'
|
||||
import { removeDevice } from '../function/device/remove-device'
|
||||
import { createAddDeviceToken } from '../function/parent/create-add-device-token'
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
export const createParentRouter = ({
|
||||
database, websocket, eventHandler
|
||||
}: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
eventHandler: EventHandler
|
||||
}) => {
|
||||
@@ -58,7 +58,7 @@ export const createParentRouter = ({
|
||||
|
||||
const { mailAuthToken } = req.body
|
||||
const { status, mail } = await database.transaction(async (transaction) => {
|
||||
return getStatusByMailToken({ transaction, mailAuthToken })
|
||||
return getStatusByMailToken({ database, mailAuthToken, transaction })
|
||||
})
|
||||
|
||||
res.json({
|
||||
@@ -153,13 +153,13 @@ export const createParentRouter = ({
|
||||
deviceAuthToken: string
|
||||
parentId: string
|
||||
secondPasswordHash: string
|
||||
transaction: SimpleDatabaseTransaction
|
||||
transaction: Transaction
|
||||
}) {
|
||||
const deviceEntry = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken: deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -171,13 +171,13 @@ export const createParentRouter = ({
|
||||
throw new Unauthorized()
|
||||
}
|
||||
|
||||
const parentEntry = await transaction.legacy.database.user.findOne({
|
||||
const parentEntry = await database.user.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
type: 'parent',
|
||||
userId: deviceEntry.currentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -187,11 +187,11 @@ export const createParentRouter = ({
|
||||
return { deviceEntry, parentEntry }
|
||||
} else if (secondPasswordHash.startsWith('u2f:')) {
|
||||
try {
|
||||
const familyEntryUnsafe = await transaction.legacy.database.family.findOne({
|
||||
const familyEntryUnsafe = await database.family.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['hasFullVersion']
|
||||
})
|
||||
|
||||
@@ -208,6 +208,7 @@ export const createParentRouter = ({
|
||||
hasFullVersion,
|
||||
familyId: deviceEntry.familyId,
|
||||
deviceId: deviceEntry.deviceId,
|
||||
database,
|
||||
transaction,
|
||||
calculateHmac: (secret) => createHmac('sha256', secret)
|
||||
.update('direct action')
|
||||
@@ -216,13 +217,13 @@ export const createParentRouter = ({
|
||||
|
||||
if (u2fResult.userId !== parentId) throw new Unauthorized()
|
||||
|
||||
const parentEntry = await transaction.legacy.database.user.findOne({
|
||||
const parentEntry = await database.user.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
type: 'parent',
|
||||
userId: u2fResult.userId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -235,14 +236,14 @@ export const createParentRouter = ({
|
||||
else throw ex
|
||||
}
|
||||
} else {
|
||||
const parentEntry = await transaction.legacy.database.user.findOne({
|
||||
const parentEntry = await database.user.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
type: 'parent',
|
||||
userId: parentId,
|
||||
secondPasswordHash: secondPasswordHash
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -267,7 +268,7 @@ export const createParentRouter = ({
|
||||
transaction
|
||||
})
|
||||
|
||||
return createAddDeviceToken({ familyId: deviceEntry.familyId, transaction })
|
||||
return createAddDeviceToken({ familyId: deviceEntry.familyId, database, transaction })
|
||||
})
|
||||
|
||||
res.json({ token, deviceId })
|
||||
@@ -312,10 +313,11 @@ export const createParentRouter = ({
|
||||
})
|
||||
|
||||
await removeDevice({
|
||||
transaction,
|
||||
database,
|
||||
familyId: deviceEntry.familyId,
|
||||
deviceId: req.body.deviceId,
|
||||
websocket
|
||||
websocket,
|
||||
transaction
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+16
-17
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -18,7 +18,7 @@
|
||||
import { json } from 'body-parser'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest, Conflict, Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
import {
|
||||
addPurchase,
|
||||
areGooglePlayPaymentsPossible,
|
||||
@@ -31,32 +31,30 @@ import { WebsocketApi } from '../websocket'
|
||||
import { isCanDoPurchaseRequest, isFinishPurchaseByGooglePlayRequest } from './validator'
|
||||
|
||||
export const createPurchaseRouter = ({ database, websocket }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
}) => {
|
||||
const router = Router()
|
||||
|
||||
router.post('/can-do-purchase', json(), async (req, res, next) => {
|
||||
if (!areGooglePlayPaymentsPossible) {
|
||||
res.json({ canDoPurchase: 'no because not supported by the server' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (!isCanDoPurchaseRequest(req.body)) {
|
||||
throw new BadRequest()
|
||||
}
|
||||
|
||||
if (req.body.type === 'googleplay' && !areGooglePlayPaymentsPossible) {
|
||||
res.json({ canDoPurchase: 'no because not supported by the server' })
|
||||
return
|
||||
}
|
||||
|
||||
const result: boolean = await database.transaction(async (transaction) => {
|
||||
const familyEntry = await requireFamilyEntry({
|
||||
transaction,
|
||||
database,
|
||||
deviceAuthToken: req.body.deviceAuthToken,
|
||||
transaction
|
||||
})
|
||||
|
||||
return canDoNextPurchase({
|
||||
fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10),
|
||||
fullVersionDebts: parseInt(familyEntry.fullVersionDebts, 10),
|
||||
})
|
||||
return canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10) })
|
||||
})
|
||||
|
||||
res.json({
|
||||
@@ -75,12 +73,12 @@ export const createPurchaseRouter = ({ database, websocket }: {
|
||||
}
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken: req.body.deviceAuthToken
|
||||
},
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -121,12 +119,13 @@ export const createPurchaseRouter = ({ database, websocket }: {
|
||||
}
|
||||
|
||||
await addPurchase({
|
||||
transaction,
|
||||
database,
|
||||
familyId: deviceEntry.familyId,
|
||||
type,
|
||||
service: 'googleplay',
|
||||
transactionId: orderId,
|
||||
websocket
|
||||
websocket,
|
||||
transaction
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ export interface CreateRegisterDeviceTokenRequest {
|
||||
}
|
||||
|
||||
export interface CanDoPurchaseRequest {
|
||||
type?: 'googleplay' | 'any'
|
||||
type: 'googleplay' | 'any'
|
||||
deviceAuthToken: string
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -19,7 +19,7 @@ import { json } from 'body-parser'
|
||||
import { Router } from 'express'
|
||||
import { BadRequest, Unauthorized } from 'http-errors'
|
||||
import { VisibleConnectedDevicesManager } from '../connected-devices'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
import { reportDeviceRemoved } from '../function/device/report-device-removed'
|
||||
import { applyActionsFromDevice } from '../function/sync/apply-actions'
|
||||
import { generateServerDataStatus } from '../function/sync/get-server-data-status'
|
||||
@@ -34,7 +34,7 @@ const getRoundedTimestampForLastConnectivity = () => {
|
||||
}
|
||||
|
||||
export const createSyncRouter = ({ database, websocket, connectedDevicesManager, eventHandler }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
eventHandler: EventHandler
|
||||
@@ -86,12 +86,12 @@ export const createSyncRouter = ({ database, websocket, connectedDevicesManager,
|
||||
}
|
||||
|
||||
const serverStatus = await database.transaction(async (transaction) => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken: body.deviceAuthToken
|
||||
},
|
||||
attributes: ['familyId', 'deviceId', 'lastConnectivity'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -102,21 +102,22 @@ export const createSyncRouter = ({ database, websocket, connectedDevicesManager,
|
||||
const now = getRoundedTimestampForLastConnectivity()
|
||||
|
||||
if (parseInt(lastConnectivity, 10) !== now) {
|
||||
await transaction.legacy.database.device.update({
|
||||
await database.device.update({
|
||||
lastConnectivity: now.toString(10)
|
||||
}, {
|
||||
where: {
|
||||
deviceAuthToken: body.deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
return generateServerDataStatus({
|
||||
transaction,
|
||||
database,
|
||||
familyId,
|
||||
deviceId,
|
||||
clientStatus: body.status,
|
||||
transaction,
|
||||
eventHandler
|
||||
})
|
||||
})
|
||||
@@ -164,11 +165,11 @@ export const createSyncRouter = ({ database, websocket, connectedDevicesManager,
|
||||
}
|
||||
|
||||
const isDeviceRemoved: boolean = await database.transaction(async (transaction) => {
|
||||
const removedEntry = await transaction.legacy.database.oldDevice.findOne({
|
||||
const removedEntry = await database.oldDevice.findOne({
|
||||
where: {
|
||||
deviceAuthToken: req.body.deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
return !!removedEntry
|
||||
|
||||
+2
-63
@@ -1759,41 +1759,6 @@ const definitions = {
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedPingAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"PING"
|
||||
]
|
||||
},
|
||||
"deviceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"event": {
|
||||
"$ref": "#/definitions/PingEvent"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceId",
|
||||
"event",
|
||||
"token",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"PingEvent": {
|
||||
"enum": [
|
||||
"clear",
|
||||
"ping",
|
||||
"pong"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"SerializedUpdateInstalledAppsAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2850,30 +2815,6 @@ const definitions = {
|
||||
"tempKey"
|
||||
]
|
||||
},
|
||||
"ServerPing": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"deviceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"ping",
|
||||
"pong"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceId",
|
||||
"token",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"ServerDhKey": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -3272,9 +3213,6 @@ export const isSerializedAppLogicAction: (value: unknown) => value is Serialized
|
||||
{
|
||||
"$ref": "#/definitions/SerializedMarkTaskPendingAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedPingAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedUpdateInstalledAppsAction"
|
||||
},
|
||||
@@ -3353,7 +3291,8 @@ export const isCanDoPurchaseRequest: (value: unknown) => value is CanDoPurchaseR
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"deviceAuthToken"
|
||||
"deviceAuthToken",
|
||||
"type"
|
||||
],
|
||||
"definitions": definitions,
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 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
|
||||
@@ -16,10 +16,9 @@
|
||||
*/
|
||||
|
||||
import { defaultDatabase } from '../database'
|
||||
import { fromLegacy as createSimpleDatabase } from '../database/simple'
|
||||
import { deleteOldFamilies } from '../function/cleanup/delete-old-families'
|
||||
|
||||
const database = createSimpleDatabase(defaultDatabase)
|
||||
const database = defaultDatabase
|
||||
|
||||
deleteOldFamilies(database)
|
||||
.then(() => console.log('done'))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 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
|
||||
@@ -16,10 +16,9 @@
|
||||
*/
|
||||
|
||||
import { defaultDatabase } from '../database'
|
||||
import { fromLegacy as createSimpleDatabase } from '../database/simple'
|
||||
import { findOldFamilyIds } from '../function/cleanup/delete-old-families'
|
||||
|
||||
const database = createSimpleDatabase(defaultDatabase)
|
||||
const database = defaultDatabase
|
||||
|
||||
findOldFamilyIds(database)
|
||||
.then((res) => console.log(JSON.stringify(res)))
|
||||
|
||||
+9
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2024 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
|
||||
@@ -22,6 +22,7 @@ interface Config {
|
||||
pingInterval: number
|
||||
alwaysPro: boolean
|
||||
signSecret: string
|
||||
uaMailBlocklist: Array<string>
|
||||
}
|
||||
|
||||
function parseYesNo (value: string) {
|
||||
@@ -34,12 +35,17 @@ function parseYesNo (value: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseList(list: string) {
|
||||
return list.split(',').map((item) => item.trim()).filter((item) => item.length > 0)
|
||||
}
|
||||
|
||||
class ParseYesNoException extends Error {}
|
||||
|
||||
export const config: Config = {
|
||||
mailWhitelist: (process.env.MAIL_WHITELIST || '').split(',').map((item) => item.trim()).filter((item) => item.length > 0),
|
||||
mailWhitelist: parseList(process.env.MAIL_WHITELIST || ''),
|
||||
disableSignup: parseYesNo(process.env.DISABLE_SIGNUP || 'no'),
|
||||
pingInterval: parseInt(process.env.PING_INTERVAL_SEC || '25', 10) * 1000,
|
||||
alwaysPro: process.env.ALWAYS_PRO ? parseYesNo(process.env.ALWAYS_PRO) : false,
|
||||
signSecret: process.env.SIGN_SECRET || ''
|
||||
signSecret: process.env.SIGN_SECRET || '',
|
||||
uaMailBlocklist: parseList(process.env.UA_MAIL_BLOCKLIST || '')
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
import { SimpleDatabase } from '../database/simple'
|
||||
import { Database } from '../database'
|
||||
|
||||
export class ConnectedDevicesManager {
|
||||
private deviceConnectionCounters = new Map<string, number>()
|
||||
@@ -59,10 +59,10 @@ export class ConnectedDevicesManager {
|
||||
|
||||
export class VisibleConnectedDevicesManager {
|
||||
connectedDevicesManager = new ConnectedDevicesManager()
|
||||
private database: SimpleDatabase
|
||||
private database: Database
|
||||
|
||||
constructor ({ database }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
}) {
|
||||
this.database = database
|
||||
}
|
||||
@@ -174,25 +174,20 @@ export class VisibleConnectedDevicesManager {
|
||||
|
||||
// add all current devices
|
||||
;(async () => {
|
||||
const devices = await this.database.transaction(async (transaction) => {
|
||||
const devicesUnsafe = await transaction.legacy.database.device.findAll({
|
||||
const devicesUnsafe = await this.database.device.findAll({
|
||||
where: {
|
||||
familyId
|
||||
},
|
||||
attributes: [
|
||||
'deviceId',
|
||||
'showDeviceConnected'
|
||||
],
|
||||
transaction: transaction.legacy.transaction
|
||||
]
|
||||
})
|
||||
|
||||
const devices = devicesUnsafe.map(({ deviceId, showDeviceConnected }) => ({
|
||||
deviceId, showDeviceConnected
|
||||
}))
|
||||
|
||||
return devices
|
||||
})
|
||||
|
||||
devices.forEach(({ deviceId, showDeviceConnected }) => {
|
||||
addDevice({ deviceId, showDeviceConnected })
|
||||
})
|
||||
|
||||
+3
-20
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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,13 +37,8 @@ export interface FamilyAttributesVersion3 {
|
||||
u2fKeysVersion: string
|
||||
}
|
||||
|
||||
export interface FamilyAttributesVersion4 {
|
||||
fullVersionDebts: string
|
||||
}
|
||||
|
||||
export type FamilyAttributes = FamilyAttributesVersion1 &
|
||||
FamilyAttributesVersion2 & FamilyAttributesVersion3 &
|
||||
FamilyAttributesVersion4
|
||||
FamilyAttributesVersion2 & FamilyAttributesVersion3
|
||||
|
||||
export type FamilyModel = Sequelize.Model<FamilyAttributes> & FamilyAttributes
|
||||
export type FamilyModelStatic = typeof Sequelize.Model & {
|
||||
@@ -81,22 +76,10 @@ 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,
|
||||
...attributesVersion4
|
||||
...attributesVersion3
|
||||
}
|
||||
|
||||
export const createFamilyModel = (sequelize: Sequelize.Sequelize): FamilyModelStatic => sequelize.define('Family', attributes) as FamilyModelStatic
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -33,7 +33,6 @@ import { createKeyResponseModel, KeyResponseModelStatic } from './keyresponse'
|
||||
import { createMailLoginTokenModel, MailLoginTokenModelStatic } from './maillogintoken'
|
||||
import { createUmzug } from './migration/umzug'
|
||||
import { createOldDeviceModel, OldDeviceModelStatic } from './olddevice'
|
||||
import { createPingModel, PingModelStatic } from './ping'
|
||||
import { createPurchaseModel, PurchaseModelStatic } from './purchase'
|
||||
import { createSessionDurationModel, SessionDurationModelStatic } from './sessionduration'
|
||||
import { createTimelimitRuleModel, TimelimitRuleModelStatic } from './timelimitrule'
|
||||
@@ -62,7 +61,6 @@ export interface Database {
|
||||
keyResponse: KeyResponseModelStatic
|
||||
mailLoginToken: MailLoginTokenModelStatic
|
||||
oldDevice: OldDeviceModelStatic
|
||||
ping: PingModelStatic
|
||||
purchase: PurchaseModelStatic
|
||||
sessionDuration: SessionDurationModelStatic
|
||||
timelimitRule: TimelimitRuleModelStatic
|
||||
@@ -99,7 +97,6 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
|
||||
keyResponse: createKeyResponseModel(sequelize),
|
||||
mailLoginToken: createMailLoginTokenModel(sequelize),
|
||||
oldDevice: createOldDeviceModel(sequelize),
|
||||
ping: createPingModel(sequelize),
|
||||
purchase: createPurchaseModel(sequelize),
|
||||
sessionDuration: createSessionDurationModel(sequelize),
|
||||
timelimitRule: createTimelimitRuleModel(sequelize),
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
const dialect = sequelize.getDialect()
|
||||
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
||||
|
||||
if (isMysql) {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `Pings` ' +
|
||||
'(`familyId` VARCHAR(10) NOT NULL,' +
|
||||
'`receiverDeviceId` VARCHAR(6) NOT NULL,' +
|
||||
'`senderDeviceId` VARCHAR(6) NOT NULL,' +
|
||||
'`type` INTEGER NOT NULL,' +
|
||||
'`token` VARCHAR(6) NOT NULL,' +
|
||||
'PRIMARY KEY (`familyId`, `receiverDeviceId`, `senderDeviceId`, `type`),' +
|
||||
'FOREIGN KEY (`familyId`, `receiverDeviceId`) REFERENCES `Devices` (`familyId`, `deviceId`) ON UPDATE CASCADE ON DELETE CASCADE,' +
|
||||
'FOREIGN KEY (`familyId`, `senderDeviceId`) REFERENCES `Devices` (`familyId`, `deviceId`) ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
} else {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE "Pings" ' +
|
||||
'("familyId" VARCHAR(10) NOT NULL,' +
|
||||
'"receiverDeviceId" VARCHAR(6) NOT NULL,' +
|
||||
'"senderDeviceId" VARCHAR(6) NOT NULL,' +
|
||||
'"type" INTEGER NOT NULL,' +
|
||||
'"token" VARCHAR(6) NOT NULL,' +
|
||||
'PRIMARY KEY ("familyId", "receiverDeviceId", "senderDeviceId", "type"),' +
|
||||
'FOREIGN KEY ("familyId", "receiverDeviceId") REFERENCES "Devices" ("familyId", "deviceId") ON UPDATE CASCADE ON DELETE CASCADE,' +
|
||||
'FOREIGN KEY ("familyId", "senderDeviceId") REFERENCES "Devices" ("familyId", "deviceId") ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
await queryInterface.addIndex('Pings', ['familyId', 'senderDeviceId'], { transaction })
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('Pings', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 })
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2024 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
|
||||
@@ -27,7 +27,7 @@ export const createUmzug = (sequelize: Sequelize) => (
|
||||
resolve: ({ name, path }) => {
|
||||
if (!path) throw new Error()
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const migration = require(path)
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface PingAttributes {
|
||||
familyId: string
|
||||
receiverDeviceId: string
|
||||
senderDeviceId: string
|
||||
type: number
|
||||
token: string
|
||||
}
|
||||
|
||||
export const types = {
|
||||
ping: 1,
|
||||
pong: 2,
|
||||
all: [1, 2]
|
||||
}
|
||||
|
||||
export type PingModel = Sequelize.Model<PingAttributes> & PingAttributes
|
||||
export type PingModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): PingModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<PingAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
receiverDeviceId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
senderDeviceId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isIn: [types.all]
|
||||
},
|
||||
primaryKey: true
|
||||
},
|
||||
token: {
|
||||
...idWithinFamilyColumn
|
||||
}
|
||||
}
|
||||
|
||||
export const createPingModel = (sequelize: Sequelize.Sequelize): PingModelStatic => sequelize.define('Ping', attributes) as PingModelStatic
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -23,7 +23,7 @@ export interface PurchaseAttributes {
|
||||
familyId: string
|
||||
service: 'googleplay' | 'directpurchase'
|
||||
transactionId: string
|
||||
type: 'month' | 'year' | 'unpaid14'
|
||||
type: 'month' | 'year'
|
||||
loggedAt: string
|
||||
previousFullVersionEndTime: string
|
||||
newFullVersionEndTime: string
|
||||
@@ -44,7 +44,7 @@ export const attributes: SequelizeAttributes<PurchaseAttributes> = {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true
|
||||
},
|
||||
type: createEnumColumn(['month', 'year', 'unpaid14']),
|
||||
type: createEnumColumn(['month', 'year']),
|
||||
loggedAt: { ...timestampColumn },
|
||||
previousFullVersionEndTime: { ...timestampColumn },
|
||||
newFullVersionEndTime: { ...timestampColumn }
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 { Database as LegacyDatabase, Transaction as LegacyTransaction } from '../main'
|
||||
|
||||
export interface SimpleDatabase {
|
||||
legacy: LegacyDatabase
|
||||
transaction: <T> (
|
||||
inner: (t: SimpleDatabaseTransaction) => Promise<T>
|
||||
) => Promise<T>
|
||||
}
|
||||
|
||||
export interface SimpleDatabaseTransaction {
|
||||
transaction: <T> (
|
||||
inner: (t: SimpleDatabaseTransaction) => Promise<T>
|
||||
) => Promise<T>
|
||||
|
||||
enqueueAfterCommit(callback: () => void): void
|
||||
|
||||
legacy: {
|
||||
database: LegacyDatabase
|
||||
transaction: LegacyTransaction
|
||||
}
|
||||
}
|
||||
|
||||
export function fromLegacy(database: LegacyDatabase): SimpleDatabase {
|
||||
return {
|
||||
legacy: database,
|
||||
transaction: (inner) => database.transaction((legacyTransaction) => inner(fromLegacyTransaction(database, legacyTransaction)))
|
||||
}
|
||||
}
|
||||
|
||||
function fromLegacyTransaction(database: LegacyDatabase, legacyTransaction: LegacyTransaction): SimpleDatabaseTransaction {
|
||||
return {
|
||||
transaction: (inner) => database.transaction(
|
||||
(innerTransaction) => inner(fromLegacyTransaction(database, innerTransaction)),
|
||||
{ transaction: legacyTransaction }
|
||||
),
|
||||
enqueueAfterCommit: (afterCommitAction) => legacyTransaction.afterCommit(afterCommitAction),
|
||||
legacy: {
|
||||
database,
|
||||
transaction: legacyTransaction
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2021 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
|
||||
@@ -16,45 +16,45 @@
|
||||
*/
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
import { generateAuthToken } from '../../util/token'
|
||||
|
||||
export const createAuthTokenByMailAddress = async ({
|
||||
mail, transaction, locale
|
||||
mail, database, transaction, locale
|
||||
}: {
|
||||
mail: string, transaction: SimpleDatabaseTransaction, locale: string
|
||||
mail: string, database: Database, transaction: Transaction, locale: string
|
||||
}) => {
|
||||
const token = generateAuthToken()
|
||||
|
||||
await transaction.legacy.database.authtoken.create({
|
||||
await database.authtoken.create({
|
||||
token,
|
||||
mail,
|
||||
createdAt: Date.now().toString(),
|
||||
locale
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
}, { transaction })
|
||||
|
||||
return token
|
||||
}
|
||||
|
||||
export const getMailAndLocaleByAuthToken = async ({
|
||||
mailAuthToken, transaction, invalidate
|
||||
mailAuthToken, database, transaction, invalidate
|
||||
}: {
|
||||
mailAuthToken: string, transaction: SimpleDatabaseTransaction, invalidate: boolean
|
||||
mailAuthToken: string, database: Database, transaction: Transaction, invalidate: boolean
|
||||
}) => {
|
||||
const entry = await transaction.legacy.database.authtoken.findOne({
|
||||
const entry = await database.authtoken.findOne({
|
||||
where: {
|
||||
token: mailAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (entry) {
|
||||
if (invalidate) {
|
||||
const rowCounter = await transaction.legacy.database.authtoken.destroy({
|
||||
const rowCounter = await database.authtoken.destroy({
|
||||
where: {
|
||||
token: mailAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (rowCounter !== 1) {
|
||||
@@ -72,11 +72,11 @@ export const getMailAndLocaleByAuthToken = async ({
|
||||
}
|
||||
|
||||
export const requireMailAndLocaleByAuthToken = async ({
|
||||
mailAuthToken, transaction, invalidate
|
||||
mailAuthToken, database, transaction, invalidate
|
||||
}: {
|
||||
mailAuthToken: string, transaction: SimpleDatabaseTransaction, invalidate: boolean
|
||||
mailAuthToken: string, database: Database, transaction: Transaction, invalidate: boolean
|
||||
}) => {
|
||||
const result = await getMailAndLocaleByAuthToken({ mailAuthToken, transaction, invalidate })
|
||||
const result = await getMailAndLocaleByAuthToken({ mailAuthToken, database, transaction, invalidate })
|
||||
|
||||
if (!result) {
|
||||
throw new Unauthorized()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2024 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
|
||||
@@ -16,28 +16,29 @@
|
||||
*/
|
||||
|
||||
import { Forbidden, Gone, TooManyRequests, Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { sendAuthenticationMail } from '../../util/mail'
|
||||
import { areWordSequencesEqual, randomWords } from '../../util/random-words'
|
||||
import { checkMailSendLimit } from '../../util/ratelimit-authmail'
|
||||
import { generateAuthToken } from '../../util/token'
|
||||
import { createAuthTokenByMailAddress } from './index'
|
||||
|
||||
export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database }: {
|
||||
export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database, info }: {
|
||||
mail: string
|
||||
deviceAuthToken?: string
|
||||
locale: string
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
info: Buffer
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}): Promise<{ mailLoginToken: string }> => {
|
||||
let deviceName = null
|
||||
|
||||
if (deviceAuthToken !== undefined) {
|
||||
const info = await database.transaction(async (transaction) => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: { deviceAuthToken },
|
||||
attributes: ['familyId', 'name'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -49,12 +50,12 @@ export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database }:
|
||||
name: deviceEntryUnsafe.name
|
||||
}
|
||||
|
||||
const userEntryCounter = await transaction.legacy.database.user.count({
|
||||
const userEntryCounter = await database.user.count({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
mail
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (userEntryCounter === 1) {
|
||||
@@ -82,18 +83,19 @@ export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database }:
|
||||
receiver: mail,
|
||||
code,
|
||||
locale,
|
||||
deviceName
|
||||
deviceName,
|
||||
info
|
||||
})
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
await transaction.legacy.database.mailLoginToken.create({
|
||||
await database.mailLoginToken.create({
|
||||
mailLoginToken,
|
||||
receivedCode: code,
|
||||
mail,
|
||||
createdAt: Date.now().toString(10),
|
||||
remainingAttempts: 3,
|
||||
locale
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
}, { transaction })
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -106,15 +108,15 @@ export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database }:
|
||||
export const signInByMailCode = async ({ mailLoginToken, receivedCode, database }: {
|
||||
mailLoginToken: string
|
||||
receivedCode: string
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}): Promise<{ mailAuthToken: string }> => {
|
||||
const result = await database.transaction(async (transaction) => {
|
||||
const entry = await transaction.legacy.database.mailLoginToken.findOne({
|
||||
const entry = await database.mailLoginToken.findOne({
|
||||
where: {
|
||||
mailLoginToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if ((!entry) || entry.remainingAttempts === 0) {
|
||||
@@ -124,7 +126,7 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
||||
if (!areWordSequencesEqual(entry.receivedCode, receivedCode)) {
|
||||
entry.remainingAttempts--
|
||||
|
||||
await entry.save({ transaction: transaction.legacy.transaction })
|
||||
await entry.save({ transaction })
|
||||
|
||||
if (entry.remainingAttempts === 0) {
|
||||
return () => { throw new Gone() }
|
||||
@@ -133,11 +135,11 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
||||
}
|
||||
}
|
||||
|
||||
const counter = await transaction.legacy.database.mailLoginToken.destroy({
|
||||
const counter = await database.mailLoginToken.destroy({
|
||||
where: {
|
||||
mailLoginToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (counter !== 1) {
|
||||
@@ -147,6 +149,7 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
||||
const mailAuthToken = await createAuthTokenByMailAddress({
|
||||
mail: entry.mail,
|
||||
locale: entry.locale,
|
||||
database,
|
||||
transaction
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { RegisterChildDeviceRequest } from '../../api/schema'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { generateAuthToken, generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { prepareDeviceEntry } from '../device/prepare-device-entry'
|
||||
@@ -28,7 +28,7 @@ import { ServerDataStatus } from '../../object/serverdatastatus'
|
||||
import { createEmptyClientDataStatus } from '../../object/clientdatastatus'
|
||||
|
||||
export const addChildDevice = async ({ database, eventHandler, websocket, request }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
eventHandler: EventHandler
|
||||
websocket: WebsocketApi
|
||||
request: RegisterChildDeviceRequest
|
||||
@@ -39,23 +39,23 @@ export const addChildDevice = async ({ database, eventHandler, websocket, reques
|
||||
data: ServerDataStatus
|
||||
}> => {
|
||||
return database.transaction(async (transaction) => {
|
||||
const entry = await transaction.legacy.database.addDeviceToken.findOne({
|
||||
const entry = await database.addDeviceToken.findOne({
|
||||
where: {
|
||||
token: request.registerToken.toLowerCase()
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!entry) {
|
||||
throw new Unauthorized()
|
||||
}
|
||||
|
||||
await entry.destroy({ transaction: transaction.legacy.transaction })
|
||||
await entry.destroy({ transaction })
|
||||
|
||||
const { deviceId, familyId } = entry
|
||||
const deviceAuthToken = generateAuthToken()
|
||||
|
||||
await transaction.legacy.database.device.create(prepareDeviceEntry({
|
||||
await database.device.create(prepareDeviceEntry({
|
||||
familyId,
|
||||
deviceId,
|
||||
deviceAuthToken,
|
||||
@@ -63,31 +63,33 @@ export const addChildDevice = async ({ database, eventHandler, websocket, reques
|
||||
newDeviceInfo: request.childDevice,
|
||||
userId: '',
|
||||
isUserKeptSignedIn: false
|
||||
}), { transaction: transaction.legacy.transaction })
|
||||
}), { transaction })
|
||||
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
deviceListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
familyId,
|
||||
websocket,
|
||||
transaction,
|
||||
database,
|
||||
generalLevel: 1,
|
||||
targetedLevels: new Map(),
|
||||
sourceDeviceId: deviceId
|
||||
sourceDeviceId: deviceId,
|
||||
transaction
|
||||
})
|
||||
|
||||
const data = await generateServerDataStatus({
|
||||
transaction,
|
||||
database,
|
||||
clientStatus: createEmptyClientDataStatus({ clientLevel: request.clientLevel || null }),
|
||||
familyId: entry.familyId,
|
||||
deviceId,
|
||||
transaction,
|
||||
eventHandler
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 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
|
||||
@@ -16,21 +16,21 @@
|
||||
*/
|
||||
|
||||
import { Conflict, Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
|
||||
export const logoutAtPrimaryDevice = async ({ deviceAuthToken, database, websocket }: {
|
||||
deviceAuthToken: string
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}) => {
|
||||
await database.transaction(async (transaction) => {
|
||||
const ownDeviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const ownDeviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['familyId', 'currentUserId', 'deviceId']
|
||||
})
|
||||
|
||||
@@ -43,14 +43,14 @@ export const logoutAtPrimaryDevice = async ({ deviceAuthToken, database, websock
|
||||
currentUserId: ownDeviceEntryUnsafe.currentUserId
|
||||
}
|
||||
|
||||
const deviceUserEntryUnsafe = await transaction.legacy.database.user.findOne({
|
||||
const deviceUserEntryUnsafe = await database.user.findOne({
|
||||
where: {
|
||||
familyId: ownDeviceEntry.familyId,
|
||||
userId: ownDeviceEntry.currentUserId,
|
||||
type: 'child'
|
||||
},
|
||||
attributes: ['currentDevice'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceUserEntryUnsafe) {
|
||||
@@ -61,14 +61,14 @@ export const logoutAtPrimaryDevice = async ({ deviceAuthToken, database, websock
|
||||
currentDevice: deviceUserEntryUnsafe.currentDevice
|
||||
}
|
||||
|
||||
const otherDeviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const otherDeviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
familyId: ownDeviceEntry.familyId,
|
||||
deviceId: deviceUserEntry.currentDevice,
|
||||
currentUserId: ownDeviceEntry.currentUserId
|
||||
},
|
||||
attributes: ['deviceAuthToken'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!otherDeviceEntryUnsafe) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -17,13 +17,13 @@
|
||||
|
||||
import { Conflict, InternalServerError, Unauthorized } from 'http-errors'
|
||||
import { config } from '../../config'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { notifyClientsAboutChangesDelayed } from '../websocket'
|
||||
|
||||
export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, currentUserId, action }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
deviceAuthToken: string
|
||||
currentUserId: string
|
||||
@@ -31,11 +31,11 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}): Promise<'assigned to other device' | 'requires full version' | 'success'> => {
|
||||
return database.transaction(async (transaction): Promise<'assigned to other device' | 'requires full version' | 'success'> => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['familyId', 'currentUserId', 'deviceId']
|
||||
})
|
||||
|
||||
@@ -53,12 +53,12 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
throw new Conflict()
|
||||
}
|
||||
|
||||
const userEntryUnsafe = await transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await database.user.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
userId: deviceEntry.currentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['currentDevice']
|
||||
})
|
||||
|
||||
@@ -70,12 +70,12 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
currentDevice: userEntryUnsafe.currentDevice
|
||||
}
|
||||
|
||||
const userDeviceEntriesUnsafe = await transaction.legacy.database.device.findAll({
|
||||
const userDeviceEntriesUnsafe = await database.device.findAll({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
currentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['deviceId']
|
||||
})
|
||||
|
||||
@@ -84,11 +84,11 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
}))
|
||||
|
||||
if (userDeviceEntries.length >= 2) {
|
||||
const familyEntryUnsafe = await transaction.legacy.database.family.findOne({
|
||||
const familyEntryUnsafe = await database.family.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['hasFullVersion']
|
||||
})
|
||||
|
||||
@@ -112,14 +112,14 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
}
|
||||
|
||||
// update
|
||||
const [affectedRows] = await transaction.legacy.database.user.update({
|
||||
const [affectedRows] = await database.user.update({
|
||||
currentDevice: deviceEntry.deviceId
|
||||
}, {
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
userId: currentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 1) {
|
||||
@@ -131,14 +131,14 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
}
|
||||
|
||||
// update
|
||||
const [affectedRows] = await transaction.legacy.database.user.update({
|
||||
const [affectedRows] = await database.user.update({
|
||||
currentDevice: ''
|
||||
}, {
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
userId: currentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 1) {
|
||||
@@ -149,10 +149,10 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
}
|
||||
|
||||
// invalidiate user list
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
userListVersion: generateVersionId()
|
||||
}, {
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
}
|
||||
@@ -163,9 +163,10 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c
|
||||
familyId: deviceEntry.familyId,
|
||||
sourceDeviceId: deviceEntry.deviceId,
|
||||
websocket,
|
||||
transaction,
|
||||
database,
|
||||
generalLevel: 1, // the source device knows it already
|
||||
targetedLevels: new Map(),
|
||||
transaction
|
||||
})
|
||||
|
||||
return 'success'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { DeleteAccountPayload } from '../../api/schema'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { sendAccountDeletedMail } from '../../util/mail'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { requireMailAndLocaleByAuthToken } from '../authentication'
|
||||
@@ -25,14 +25,14 @@ import { deleteFamilies } from './delete-families'
|
||||
|
||||
export async function deleteAccount({ request, database, websocket }: {
|
||||
request: DeleteAccountPayload
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
}) {
|
||||
await database.transaction(async (transaction) => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: { deviceAuthToken: request.deviceAuthToken },
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -43,13 +43,13 @@ export async function deleteAccount({ request, database, websocket }: {
|
||||
familyId: deviceEntryUnsafe.familyId
|
||||
}
|
||||
|
||||
const userEntries = (await transaction.legacy.database.user.findAll({
|
||||
const userEntries = (await database.user.findAll({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId,
|
||||
type: 'parent'
|
||||
},
|
||||
attributes: ['mail'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})).map((item) => ({ mail: item.mail }))
|
||||
|
||||
const registeredMailAddresses = new Set<string>()
|
||||
@@ -63,6 +63,7 @@ export async function deleteAccount({ request, database, websocket }: {
|
||||
for (const mailAuthToken of request.mailAuthTokens) {
|
||||
const info = await requireMailAndLocaleByAuthToken({
|
||||
mailAuthToken,
|
||||
database,
|
||||
transaction,
|
||||
invalidate: true
|
||||
})
|
||||
@@ -78,17 +79,17 @@ export async function deleteAccount({ request, database, websocket }: {
|
||||
if (!authenticatedMailAddresses.has(mail)) throw new Unauthorized()
|
||||
})
|
||||
|
||||
const deviceEntries = (await transaction.legacy.database.device.findAll({
|
||||
const deviceEntries = (await database.device.findAll({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['deviceAuthToken']
|
||||
})).map((item) => ({ deviceAuthToken: item.deviceAuthToken }))
|
||||
|
||||
await deleteFamilies({ transaction, familiyIds: [deviceEntry.familyId] })
|
||||
await deleteFamilies({ database, transaction, familiyIds: [deviceEntry.familyId] })
|
||||
|
||||
transaction.enqueueAfterCommit(() => {
|
||||
transaction.afterCommit(() => {
|
||||
for (const device of deviceEntries) {
|
||||
websocket.triggerSyncByDeviceAuthToken({
|
||||
deviceAuthToken: device.deviceAuthToken,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -17,136 +17,138 @@
|
||||
|
||||
import { difference } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
|
||||
export async function deleteFamilies ({ transaction, familiyIds }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export async function deleteFamilies ({ database, transaction, familiyIds }: {
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
familiyIds: Array<string>
|
||||
// no transaction here because this should run isolated
|
||||
}) {
|
||||
if (familiyIds.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// category
|
||||
await transaction.legacy.database.category.destroy({
|
||||
await database.category.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// categoryapp
|
||||
await transaction.legacy.database.categoryApp.destroy({
|
||||
await database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// purchase
|
||||
await transaction.legacy.database.purchase.destroy({
|
||||
await database.purchase.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// timelimitrule
|
||||
await transaction.legacy.database.timelimitRule.destroy({
|
||||
await database.timelimitRule.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// usedtime
|
||||
await transaction.legacy.database.usedTime.destroy({
|
||||
await database.usedTime.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// session durations
|
||||
await transaction.legacy.database.sessionDuration.destroy({
|
||||
await database.sessionDuration.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// user
|
||||
await transaction.legacy.database.user.destroy({
|
||||
await database.user.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// device
|
||||
const oldDeviceAuthTokens = (await transaction.legacy.database.device.findAll({
|
||||
const oldDeviceAuthTokens = (await database.device.findAll({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
attributes: ['deviceAuthToken'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})).map((item) => item.deviceAuthToken)
|
||||
|
||||
await transaction.legacy.database.device.destroy({
|
||||
await database.device.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// olddevice
|
||||
if (oldDeviceAuthTokens.length > 0) {
|
||||
const knownOldDeviceAuthTokens = (await transaction.legacy.database.oldDevice.findAll({
|
||||
const knownOldDeviceAuthTokens = (await database.oldDevice.findAll({
|
||||
where: {
|
||||
deviceAuthToken: {
|
||||
[Sequelize.Op.in]: oldDeviceAuthTokens
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})).map((item) => item.deviceAuthToken)
|
||||
|
||||
const oldDeviceAuthTokensToAdd = difference(oldDeviceAuthTokens, knownOldDeviceAuthTokens)
|
||||
|
||||
if (oldDeviceAuthTokensToAdd.length > 0) {
|
||||
await transaction.legacy.database.oldDevice.bulkCreate(
|
||||
await database.oldDevice.bulkCreate(
|
||||
oldDeviceAuthTokensToAdd.map((item) => ({
|
||||
deviceAuthToken: item
|
||||
})),
|
||||
{ transaction: transaction.legacy.transaction }
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// family
|
||||
await transaction.legacy.database.family.destroy({
|
||||
await database.family.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
import { difference } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { deleteFamilies } from './delete-families'
|
||||
|
||||
export async function deleteOldFamilies (database: SimpleDatabase) {
|
||||
export async function deleteOldFamilies (database: Database) {
|
||||
const oldFamilyIds = await findOldFamilyIds(database)
|
||||
|
||||
if (oldFamilyIds.length > 0) {
|
||||
@@ -28,6 +28,7 @@ export async function deleteOldFamilies (database: SimpleDatabase) {
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
await deleteFamilies({
|
||||
database,
|
||||
transaction,
|
||||
familiyIds: familyIdsToDelete
|
||||
})
|
||||
@@ -35,23 +36,23 @@ export async function deleteOldFamilies (database: SimpleDatabase) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function findOldFamilyIds (database: SimpleDatabase): Promise<Array<string>> {
|
||||
export async function findOldFamilyIds (database: Database) {
|
||||
return database.transaction(async (transaction) => {
|
||||
const familyIdsWithExpiredLicenses = (await transaction.legacy.database.family.findAll({
|
||||
const familyIdsWithExpiredLicenses = (await database.family.findAll({
|
||||
where: {
|
||||
fullVersionUntil: {
|
||||
[Sequelize.Op.lt]: (Date.now() - 1000 * 60 * 60 * 24 * 90 /* 90 days */).toString(10)
|
||||
}
|
||||
},
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})).map((item) => item.familyId)
|
||||
|
||||
if (familyIdsWithExpiredLicenses.length === 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const recentlyUsedFamilyIds = (await transaction.legacy.database.device.findAll({
|
||||
const recentlyUsedFamilyIds = (await database.device.findAll({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familyIdsWithExpiredLicenses
|
||||
@@ -61,7 +62,7 @@ export async function findOldFamilyIds (database: SimpleDatabase): Promise<Array
|
||||
}
|
||||
},
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})).map((item) => item.familyId)
|
||||
|
||||
return difference(familyIdsWithExpiredLicenses, recentlyUsedFamilyIds)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -16,23 +16,24 @@
|
||||
*/
|
||||
|
||||
import { Conflict } from 'http-errors'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
import { generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { notifyClientsAboutChangesDelayed } from '../websocket'
|
||||
|
||||
export async function removeDevice ({ familyId, deviceId, websocket, transaction }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export async function removeDevice ({ database, familyId, deviceId, websocket, transaction }: {
|
||||
database: Database
|
||||
familyId: string
|
||||
deviceId: string
|
||||
websocket: WebsocketApi
|
||||
transaction: Transaction
|
||||
}) {
|
||||
const deviceEntry = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await database.device.findOne({
|
||||
where: {
|
||||
familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -40,37 +41,37 @@ export async function removeDevice ({ familyId, deviceId, websocket, transaction
|
||||
}
|
||||
|
||||
// remove as current device
|
||||
await transaction.legacy.database.user.update({
|
||||
await database.user.update({
|
||||
currentDevice: ''
|
||||
}, {
|
||||
where: {
|
||||
familyId,
|
||||
currentDevice: deviceId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// add to old devices if it is not yet there (it could be there if it reported a uninstall)
|
||||
const oldOldDeviceEntry = await transaction.legacy.database.oldDevice.findOne({
|
||||
const oldOldDeviceEntry = await database.oldDevice.findOne({
|
||||
where: {
|
||||
deviceAuthToken: deviceEntry.deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!oldOldDeviceEntry) {
|
||||
await transaction.legacy.database.oldDevice.create({
|
||||
await database.oldDevice.create({
|
||||
deviceAuthToken: deviceEntry.deviceAuthToken
|
||||
}, {
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
// remove from the device list
|
||||
await deviceEntry.destroy({ transaction: transaction.legacy.transaction })
|
||||
await deviceEntry.destroy({ transaction })
|
||||
|
||||
// invalidiate the caches
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
deviceListVersion: generateVersionId(),
|
||||
// the device could have become unassigned during this
|
||||
userListVersion: generateVersionId()
|
||||
@@ -78,19 +79,20 @@ export async function removeDevice ({ familyId, deviceId, websocket, transaction
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
transaction,
|
||||
database,
|
||||
websocket,
|
||||
familyId,
|
||||
sourceDeviceId: null,
|
||||
generalLevel: 1,
|
||||
targetedLevels: new Map()
|
||||
targetedLevels: new Map(),
|
||||
transaction
|
||||
})
|
||||
|
||||
transaction.enqueueAfterCommit(() => {
|
||||
transaction.afterCommit(() => {
|
||||
websocket.triggerSyncByDeviceAuthToken({
|
||||
deviceAuthToken: deviceEntry.deviceAuthToken,
|
||||
isImportant: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -16,24 +16,24 @@
|
||||
*/
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { generateAuthToken, generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { sendUninstallWarnings } from '../warningmail/uninstall'
|
||||
import { notifyClientsAboutChangesDelayed } from '../websocket'
|
||||
|
||||
export async function reportDeviceRemoved ({ database, deviceAuthToken, websocket }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
deviceAuthToken: string
|
||||
websocket: WebsocketApi
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}) {
|
||||
await database.transaction(async (transaction) => {
|
||||
const deviceEntry = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (deviceEntry) {
|
||||
@@ -41,45 +41,47 @@ export async function reportDeviceRemoved ({ database, deviceAuthToken, websocke
|
||||
|
||||
deviceEntry.didDeviceReportUninstall = true
|
||||
deviceEntry.deviceAuthToken = generateAuthToken() // invalidiate the token
|
||||
await deviceEntry.save({ transaction: transaction.legacy.transaction })
|
||||
await deviceEntry.save({ transaction })
|
||||
|
||||
// invalidiate device list
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
deviceListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// add to old devices
|
||||
await transaction.legacy.database.oldDevice.create({
|
||||
await database.oldDevice.create({
|
||||
deviceAuthToken: currentAuthToken
|
||||
}, {
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
transaction,
|
||||
database,
|
||||
websocket,
|
||||
familyId: deviceEntry.familyId,
|
||||
sourceDeviceId: null,
|
||||
generalLevel: 1,
|
||||
targetedLevels: new Map(),
|
||||
transaction
|
||||
})
|
||||
|
||||
await sendUninstallWarnings({
|
||||
transaction,
|
||||
database,
|
||||
familyId: deviceEntry.familyId,
|
||||
deviceName: deviceEntry.name,
|
||||
transaction
|
||||
})
|
||||
} else {
|
||||
const oldDeviceEntry = await transaction.legacy.database.oldDevice.findOne({
|
||||
const oldDeviceEntry = await database.oldDevice.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!oldDeviceEntry) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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,15 +15,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { createDecipheriv } from 'crypto'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { isVersionId } from '../../util/token'
|
||||
import { getSharedSecret, SharedSecretException } from './shared-secret'
|
||||
|
||||
export async function decrypt({
|
||||
transaction, familyId, deviceId, encryptedData, authData
|
||||
database, transaction, familyId, deviceId, encryptedData, authData
|
||||
}: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
database: Database
|
||||
transaction: Sequelize.Transaction
|
||||
familyId: string
|
||||
deviceId: string
|
||||
encryptedData: string
|
||||
@@ -44,6 +46,7 @@ export async function decrypt({
|
||||
const sharedSecret = await (async () => {
|
||||
try {
|
||||
return getSharedSecret({
|
||||
database,
|
||||
transaction,
|
||||
familyId,
|
||||
deviceId,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -31,6 +31,7 @@ export async function decryptParentPassword({ cache, password } : {
|
||||
|
||||
try {
|
||||
const secondHash = (await decrypt({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
familyId: cache.familyId,
|
||||
deviceId: cache.deviceId,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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,15 +15,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { createPrivateKey, createPublicKey, diffieHellman } from 'crypto'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { calculateExpireTime } from '../../database/devicedhkey'
|
||||
import { isVersionId } from '../../util/token'
|
||||
|
||||
export async function getSharedSecret({
|
||||
transaction, familyId, deviceId, keyId, otherPublicKey
|
||||
database, transaction, familyId, deviceId, keyId, otherPublicKey
|
||||
}: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
database: Database
|
||||
transaction: Sequelize.Transaction
|
||||
familyId: string
|
||||
deviceId: string
|
||||
keyId: string
|
||||
@@ -31,20 +33,20 @@ export async function getSharedSecret({
|
||||
}) {
|
||||
if (!isVersionId(keyId)) throw new KeyNotFoundException('invalid key id')
|
||||
|
||||
const databaseKeyEntry = await transaction.legacy.database.deviceDhKey.findOne({
|
||||
const databaseKeyEntry = await database.deviceDhKey.findOne({
|
||||
where: {
|
||||
familyId,
|
||||
deviceId,
|
||||
version: keyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!databaseKeyEntry) throw new KeyNotFoundException('private key not found')
|
||||
|
||||
if (databaseKeyEntry.expireAt === null) {
|
||||
databaseKeyEntry.expireAt = calculateExpireTime(BigInt(Date.now())).toString(10)
|
||||
await databaseKeyEntry.save({ transaction: transaction.legacy.transaction })
|
||||
await databaseKeyEntry.save({ transaction })
|
||||
} else {
|
||||
if (BigInt(databaseKeyEntry.expireAt) < BigInt(Date.now())) throw new KeyExpiredException()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 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,30 +15,31 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
import { randomWords } from '../../util/random-words'
|
||||
import { generateIdWithinFamily } from '../../util/token'
|
||||
|
||||
export const createAddDeviceToken = async ({ familyId, transaction }: {
|
||||
export const createAddDeviceToken = async ({ familyId, database, transaction }: {
|
||||
familyId: string
|
||||
transaction: SimpleDatabaseTransaction
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
}) => {
|
||||
const token = randomWords(5)
|
||||
const deviceId = generateIdWithinFamily()
|
||||
|
||||
await transaction.legacy.database.addDeviceToken.destroy({
|
||||
await database.addDeviceToken.destroy({
|
||||
where: {
|
||||
familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await transaction.legacy.database.addDeviceToken.create({
|
||||
await database.addDeviceToken.create({
|
||||
familyId,
|
||||
token: token.toLowerCase(),
|
||||
deviceId,
|
||||
createdAt: Date.now().toString()
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
}, { transaction })
|
||||
|
||||
return { token, deviceId }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -18,7 +18,7 @@
|
||||
import { Conflict } from 'http-errors'
|
||||
import { generateServerDataStatus } from '../sync/get-server-data-status'
|
||||
import { NewDeviceInfo, PlaintextParentPassword, assertPlaintextParentPasswordValid } from '../../api/schema'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { maxMailNotificationFlags } from '../../database/user'
|
||||
import { EventHandler } from '../../monitoring/eventhandler'
|
||||
import { ServerDataStatus } from '../../object/serverdatastatus'
|
||||
@@ -33,7 +33,7 @@ export async function createFamily ({
|
||||
database, eventHandler, mailAuthToken, firstParentDevice,
|
||||
password, timeZone, parentName, deviceName, clientLevel
|
||||
}: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
eventHandler: EventHandler
|
||||
mailAuthToken: string
|
||||
firstParentDevice: NewDeviceInfo
|
||||
@@ -52,14 +52,14 @@ export async function createFamily ({
|
||||
|
||||
return database.transaction(async (transaction) => {
|
||||
const now = Date.now().toString(10)
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ transaction, mailAuthToken, invalidate: true })
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ database, mailAuthToken, transaction, invalidate: true })
|
||||
|
||||
// ensure that no family was created for this mail yet
|
||||
const existingUserEntry = await transaction.legacy.database.user.findOne({
|
||||
const existingUserEntry = await database.user.findOne({
|
||||
where: {
|
||||
mail: mailInfo.mail
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (existingUserEntry) {
|
||||
@@ -72,7 +72,7 @@ export async function createFamily ({
|
||||
const deviceAuthToken = generateAuthToken()
|
||||
|
||||
// create family
|
||||
await transaction.legacy.database.family.create({
|
||||
await database.family.create({
|
||||
familyId,
|
||||
name: '',
|
||||
createdAt: now,
|
||||
@@ -82,12 +82,11 @@ export async function createFamily ({
|
||||
fullVersionUntil: (Date.now() + 1000 * 60 * 60 * 24 * 14).toString(10),
|
||||
hasFullVersion: true,
|
||||
nextServerKeyRequestSeq: '1',
|
||||
u2fKeysVersion: generateVersionId(),
|
||||
fullVersionDebts: '0'
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
u2fKeysVersion: generateVersionId()
|
||||
}, { transaction })
|
||||
|
||||
// create parent user
|
||||
await transaction.legacy.database.user.create({
|
||||
await database.user.create({
|
||||
familyId,
|
||||
userId,
|
||||
name: parentName,
|
||||
@@ -104,10 +103,10 @@ export async function createFamily ({
|
||||
mailNotificationFlags: maxMailNotificationFlags,
|
||||
blockedTimes: '',
|
||||
flags: '0'
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
}, { transaction })
|
||||
|
||||
// add parent device
|
||||
await transaction.legacy.database.device.create(prepareDeviceEntry({
|
||||
await database.device.create(prepareDeviceEntry({
|
||||
familyId,
|
||||
deviceId,
|
||||
deviceName,
|
||||
@@ -115,13 +114,14 @@ export async function createFamily ({
|
||||
userId,
|
||||
deviceAuthToken,
|
||||
isUserKeptSignedIn: true
|
||||
}), { transaction: transaction.legacy.transaction })
|
||||
}), { transaction })
|
||||
|
||||
const data = await generateServerDataStatus({
|
||||
transaction,
|
||||
database,
|
||||
clientStatus: createEmptyClientDataStatus({ clientLevel }),
|
||||
familyId,
|
||||
deviceId,
|
||||
transaction,
|
||||
eventHandler
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2021 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,22 +15,22 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
import { StaticMessageException } from '../../exception'
|
||||
import { requireMailAndLocaleByAuthToken } from '../authentication'
|
||||
|
||||
const getStatusByMailAddress = async ({
|
||||
mail, transaction
|
||||
}: { mail: string, transaction: SimpleDatabaseTransaction }) => {
|
||||
mail, database, transaction
|
||||
}: { mail: string, database: Database, transaction: Transaction }) => {
|
||||
if (!mail) {
|
||||
throw new StaticMessageException({ staticMessage: 'getStatusByMailAddress: no mail address provided' })
|
||||
}
|
||||
|
||||
const entry = await transaction.legacy.database.user.findOne({
|
||||
const entry = await database.user.findOne({
|
||||
where: {
|
||||
mail
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (entry) {
|
||||
@@ -41,12 +41,12 @@ const getStatusByMailAddress = async ({
|
||||
}
|
||||
|
||||
export const getStatusByMailToken = async ({
|
||||
mailAuthToken, transaction
|
||||
}: { mailAuthToken: string, transaction: SimpleDatabaseTransaction }) => {
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, transaction, invalidate: false })
|
||||
mailAuthToken, database, transaction
|
||||
}: { mailAuthToken: string, database: Database, transaction: Transaction }) => {
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, database, transaction, invalidate: false })
|
||||
const mail = mailInfo.mail
|
||||
|
||||
const status = await getStatusByMailAddress({ mail, transaction })
|
||||
const status = await getStatusByMailAddress({ mail, database, transaction })
|
||||
|
||||
return { mail, status }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Conflict, Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { requireMailAndLocaleByAuthToken } from '../authentication'
|
||||
@@ -27,16 +27,16 @@ export const linkMailAddress = async ({ mailAuthToken, deviceAuthToken, parentUs
|
||||
deviceAuthToken: string
|
||||
parentUserId: string
|
||||
parentPasswordSecondHash: string
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}) => {
|
||||
await database.transaction(async (transaction) => {
|
||||
const deviceEntry = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -45,26 +45,26 @@ export const linkMailAddress = async ({ mailAuthToken, deviceAuthToken, parentUs
|
||||
|
||||
const familyId = deviceEntry.familyId
|
||||
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, transaction, invalidate: true })
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, database, transaction, invalidate: true })
|
||||
|
||||
const exisitingUser = await transaction.legacy.database.user.findOne({
|
||||
const exisitingUser = await database.user.findOne({
|
||||
where: {
|
||||
mail: mailInfo.mail
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (exisitingUser) {
|
||||
throw new Conflict()
|
||||
}
|
||||
|
||||
const parentEntry = await transaction.legacy.database.user.findOne({
|
||||
const parentEntry = await database.user.findOne({
|
||||
where: {
|
||||
type: 'parent',
|
||||
familyId,
|
||||
userId: parentUserId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -85,16 +85,16 @@ export const linkMailAddress = async ({ mailAuthToken, deviceAuthToken, parentUs
|
||||
|
||||
parentEntry.mail = mailInfo.mail
|
||||
|
||||
await parentEntry.save({ transaction: transaction.legacy.transaction })
|
||||
await parentEntry.save({ transaction })
|
||||
|
||||
// invalidiate client caches
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
userListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
// notify
|
||||
@@ -103,8 +103,9 @@ export const linkMailAddress = async ({ mailAuthToken, deviceAuthToken, parentUs
|
||||
sourceDeviceId: null,
|
||||
generalLevel: 1,
|
||||
targetedLevels: new Map(),
|
||||
transaction,
|
||||
websocket
|
||||
database,
|
||||
websocket,
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Conflict } from 'http-errors'
|
||||
import { PlaintextParentPassword, assertPlaintextParentPasswordValid } from '../../api/schema'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { sendPasswordRecoveryUsedMail } from '../../util/mail'
|
||||
import { generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
@@ -25,7 +25,7 @@ import { requireMailAndLocaleByAuthToken } from '../authentication'
|
||||
import { notifyClientsAboutChangesDelayed } from '../websocket'
|
||||
|
||||
export const recoverParentPassword = async ({ database, websocket, password, mailAuthToken }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
password: PlaintextParentPassword
|
||||
mailAuthToken: string
|
||||
@@ -34,14 +34,14 @@ export const recoverParentPassword = async ({ database, websocket, password, mai
|
||||
assertPlaintextParentPasswordValid(password)
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, transaction, invalidate: true })
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, database, transaction, invalidate: true })
|
||||
|
||||
// update the user entry
|
||||
const userEntry = await transaction.legacy.database.user.findOne({
|
||||
const userEntry = await database.user.findOne({
|
||||
where: {
|
||||
mail: mailInfo.mail
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!userEntry) {
|
||||
@@ -52,28 +52,29 @@ export const recoverParentPassword = async ({ database, websocket, password, mai
|
||||
userEntry.secondPasswordHash = password.secondHash
|
||||
userEntry.secondPasswordSalt = password.secondSalt
|
||||
|
||||
await userEntry.save({ transaction: transaction.legacy.transaction })
|
||||
await userEntry.save({ transaction })
|
||||
|
||||
// invalidate the user list
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
userListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: userEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
transaction,
|
||||
database,
|
||||
familyId: userEntry.familyId,
|
||||
websocket,
|
||||
generalLevel: 2,
|
||||
targetedLevels: new Map(),
|
||||
sourceDeviceId: null
|
||||
sourceDeviceId: null,
|
||||
transaction
|
||||
})
|
||||
|
||||
transaction.enqueueAfterCommit(async () => {
|
||||
transaction.afterCommit(async () => {
|
||||
await sendPasswordRecoveryUsedMail({
|
||||
receiver: mailInfo.mail,
|
||||
locale: mailInfo.locale
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Conflict } from 'http-errors'
|
||||
import { NewDeviceInfo } from '../../api/schema'
|
||||
import { SimpleDatabase } from '../../database/simple'
|
||||
import { Database } from '../../database'
|
||||
import { sendDeviceLinkedMail } from '../../util/mail'
|
||||
import { generateAuthToken, generateIdWithinFamily, generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
@@ -30,7 +30,7 @@ import { ServerDataStatus } from '../../object/serverdatastatus'
|
||||
import { createEmptyClientDataStatus } from '../../object/clientdatastatus'
|
||||
|
||||
export const signInIntoFamily = async ({ database, eventHandler, mailAuthToken, newDeviceInfo, deviceName, websocket, clientLevel }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
eventHandler: EventHandler
|
||||
mailAuthToken: string
|
||||
newDeviceInfo: NewDeviceInfo
|
||||
@@ -40,14 +40,14 @@ export const signInIntoFamily = async ({ database, eventHandler, mailAuthToken,
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}): Promise<{ deviceId: string; deviceAuthToken: string; data: ServerDataStatus }> => {
|
||||
return database.transaction(async (transaction) => {
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ mailAuthToken, transaction, invalidate: true })
|
||||
const mailInfo = await requireMailAndLocaleByAuthToken({ database, mailAuthToken, transaction, invalidate: true })
|
||||
|
||||
const userEntryUnsafe = await transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await database.user.findOne({
|
||||
where: {
|
||||
mail: mailInfo.mail
|
||||
},
|
||||
attributes: ['familyId', 'userId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -62,7 +62,7 @@ export const signInIntoFamily = async ({ database, eventHandler, mailAuthToken,
|
||||
const deviceAuthToken = generateAuthToken()
|
||||
const deviceId = generateIdWithinFamily()
|
||||
|
||||
await transaction.legacy.database.device.create(prepareDeviceEntry({
|
||||
await database.device.create(prepareDeviceEntry({
|
||||
familyId: userEntry.familyId,
|
||||
deviceId,
|
||||
userId: userEntry.userId,
|
||||
@@ -70,28 +70,29 @@ export const signInIntoFamily = async ({ database, eventHandler, mailAuthToken,
|
||||
deviceAuthToken,
|
||||
newDeviceInfo,
|
||||
isUserKeptSignedIn: true
|
||||
}), { transaction: transaction.legacy.transaction })
|
||||
}), { transaction })
|
||||
|
||||
// notify about changes
|
||||
await transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
deviceListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: userEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
familyId: userEntry.familyId,
|
||||
websocket,
|
||||
transaction,
|
||||
database,
|
||||
generalLevel: 1,
|
||||
targetedLevels: new Map(),
|
||||
sourceDeviceId: deviceId
|
||||
sourceDeviceId: deviceId,
|
||||
transaction
|
||||
})
|
||||
|
||||
transaction.enqueueAfterCommit(async () => {
|
||||
transaction.afterCommit(async () => {
|
||||
await sendDeviceLinkedMail({
|
||||
receiver: mailInfo.mail,
|
||||
locale: mailInfo.locale,
|
||||
@@ -100,10 +101,11 @@ export const signInIntoFamily = async ({ database, eventHandler, mailAuthToken,
|
||||
})
|
||||
|
||||
const data = await generateServerDataStatus({
|
||||
transaction,
|
||||
database,
|
||||
clientStatus: createEmptyClientDataStatus({ clientLevel }),
|
||||
familyId: userEntry.familyId,
|
||||
deviceId,
|
||||
transaction,
|
||||
eventHandler
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -16,40 +16,40 @@
|
||||
*/
|
||||
|
||||
import { Conflict } from 'http-errors'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
import { notifyClientsAboutChangesDelayed } from '../../function/websocket'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
|
||||
const day = 1000 * 60 * 60 * 24
|
||||
const week = day * 7
|
||||
const month = day * 31
|
||||
const year = day * 366
|
||||
|
||||
export const addPurchase = async ({ familyId, type, service, transactionId, websocket, transaction }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export const addPurchase = async ({ database, familyId, type, service, transactionId, websocket, transaction }: {
|
||||
database: Database
|
||||
familyId: string
|
||||
type: 'month' | 'year' | 'unpaid14'
|
||||
type: 'month' | 'year'
|
||||
service: 'googleplay' | 'directpurchase'
|
||||
transactionId: string
|
||||
websocket: WebsocketApi
|
||||
transaction: Transaction
|
||||
}) => {
|
||||
const oldPurchaseEntry = await transaction.legacy.database.purchase.findOne({
|
||||
const oldPurchaseEntry = await database.purchase.findOne({
|
||||
where: {
|
||||
service,
|
||||
transactionId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (oldPurchaseEntry) {
|
||||
return
|
||||
}
|
||||
|
||||
const familyEntry = await transaction.legacy.database.family.findOne({
|
||||
const familyEntry = await database.family.findOne({
|
||||
where: {
|
||||
familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!familyEntry) {
|
||||
@@ -57,63 +57,33 @@ export const addPurchase = async ({ familyId, type, service, transactionId, webs
|
||||
}
|
||||
|
||||
const previousFullVersionEndTime = familyEntry.fullVersionUntil
|
||||
const previousFullVersionDebts = parseInt(familyEntry.fullVersionDebts, 10)
|
||||
|
||||
if (type === 'month' || type === 'year') {
|
||||
const typeDuration = type === 'year' ? year : month
|
||||
|
||||
if (typeDuration > previousFullVersionDebts) {
|
||||
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + typeDuration - previousFullVersionDebts
|
||||
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + (type === 'year' ? year : month)
|
||||
|
||||
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
|
||||
familyEntry.fullVersionDebts = '0'
|
||||
familyEntry.hasFullVersion = true
|
||||
} else {
|
||||
familyEntry.fullVersionDebts = (previousFullVersionDebts - typeDuration).toString(10)
|
||||
}
|
||||
} else if (type === 'unpaid14') {
|
||||
const debtsAdd = 2 * week
|
||||
const debtsMax = 3 * week
|
||||
|
||||
const newDebts = Math.min(debtsMax, previousFullVersionDebts + debtsAdd)
|
||||
await familyEntry.save({ transaction })
|
||||
|
||||
if (newDebts <= previousFullVersionDebts) {
|
||||
// do not save anything
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const durationToAdd = newDebts - previousFullVersionDebts
|
||||
|
||||
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + durationToAdd
|
||||
|
||||
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
|
||||
familyEntry.fullVersionDebts = newDebts.toString(10)
|
||||
familyEntry.hasFullVersion = true
|
||||
} else {
|
||||
throw new Error()
|
||||
}
|
||||
|
||||
await familyEntry.save({ transaction: transaction.legacy.transaction })
|
||||
|
||||
await transaction.legacy.database.purchase.create({
|
||||
await database.purchase.create({
|
||||
familyId,
|
||||
service,
|
||||
transactionId,
|
||||
type,
|
||||
loggedAt: Date.now().toString(10),
|
||||
previousFullVersionEndTime,
|
||||
newFullVersionEndTime: familyEntry.fullVersionUntil
|
||||
newFullVersionEndTime: newFullVersionUntil.toString(10)
|
||||
}, {
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({
|
||||
familyId,
|
||||
sourceDeviceId: null,
|
||||
transaction,
|
||||
database,
|
||||
websocket,
|
||||
generalLevel: 2,
|
||||
targetedLevels: new Map()
|
||||
targetedLevels: new Map(),
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 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,9 +15,6 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export const canDoNextPurchase = ({ fullVersionUntil, fullVersionDebts }: {
|
||||
fullVersionUntil: number
|
||||
fullVersionDebts: number
|
||||
}) => (
|
||||
(fullVersionUntil - fullVersionDebts) < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
|
||||
export const canDoNextPurchase = ({ fullVersionUntil }: {fullVersionUntil: number}) => (
|
||||
fullVersionUntil < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 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
|
||||
@@ -16,18 +16,19 @@
|
||||
*/
|
||||
|
||||
import { InternalServerError, Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import { Database, Transaction } from '../../database'
|
||||
|
||||
export const requireFamilyEntry = async ({ transaction, deviceAuthToken }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export const requireFamilyEntry = async ({ database, deviceAuthToken, transaction }: {
|
||||
database: Database
|
||||
deviceAuthToken: string
|
||||
transaction: Transaction
|
||||
}) => {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: {
|
||||
deviceAuthToken
|
||||
},
|
||||
attributes: ['familyId'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -38,12 +39,12 @@ export const requireFamilyEntry = async ({ transaction, deviceAuthToken }: {
|
||||
familyId: deviceEntryUnsafe.familyId
|
||||
}
|
||||
|
||||
const familyEntryUnsafe = await transaction.legacy.database.family.findOne({
|
||||
const familyEntryUnsafe = await database.family.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
attributes: ['fullVersionUntil', 'fullVersionDebts'],
|
||||
transaction: transaction.legacy.transaction
|
||||
attributes: ['fullVersionUntil'],
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!familyEntryUnsafe) {
|
||||
@@ -51,8 +52,7 @@ export const requireFamilyEntry = async ({ transaction, deviceAuthToken }: {
|
||||
}
|
||||
|
||||
const familyEntry = {
|
||||
fullVersionUntil: familyEntryUnsafe.fullVersionUntil,
|
||||
fullVersionDebts: familyEntryUnsafe.fullVersionDebts,
|
||||
fullVersionUntil: familyEntryUnsafe.fullVersionUntil
|
||||
}
|
||||
|
||||
return familyEntry
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 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,39 +15,37 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { SimpleDatabase, SimpleDatabaseTransaction } from '../../database/simple'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { Database } from '../../database'
|
||||
import { configItemIds } from '../../database/config'
|
||||
|
||||
export const getStatusMessage = async ({ transaction }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export const getStatusMessage = async ({ database, transaction }: {
|
||||
database: Database
|
||||
transaction?: Sequelize.Transaction
|
||||
}) => {
|
||||
const currentStatusMessageItem = await transaction.legacy.database.config.findByPk(
|
||||
configItemIds.statusMessage,
|
||||
{ transaction: transaction.legacy.transaction }
|
||||
)
|
||||
|
||||
const currentStatusMessageItem = await database.config.findByPk(configItemIds.statusMessage, { transaction })
|
||||
const currentStatusMessage = (currentStatusMessageItem ? currentStatusMessageItem.value : null) || ''
|
||||
|
||||
return currentStatusMessage
|
||||
}
|
||||
|
||||
export const setStatusMessage = async ({ database, newStatusMessage }: {
|
||||
database: SimpleDatabase
|
||||
database: Database
|
||||
newStatusMessage: string
|
||||
}) => {
|
||||
await database.transaction(async (transaction) => {
|
||||
if (newStatusMessage === '') {
|
||||
await transaction.legacy.database.config.destroy({
|
||||
await database.config.destroy({
|
||||
where: {
|
||||
id: configItemIds.statusMessage
|
||||
},
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
} else {
|
||||
await transaction.legacy.database.config.upsert({
|
||||
await database.config.upsert({
|
||||
id: configItemIds.statusMessage,
|
||||
value: newStatusMessage
|
||||
}, { transaction: transaction.legacy.transaction })
|
||||
}, { transaction })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 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
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { SimpleDatabaseTransaction } from '../../../database/simple'
|
||||
import { Database, Transaction } from '../../../database'
|
||||
import { SourceFamilyNotFoundException } from './exception/illegal-state'
|
||||
|
||||
export interface ApplyActionBaseInfo {
|
||||
@@ -26,14 +26,15 @@ export interface ApplyActionBaseInfo {
|
||||
hasFullVersion: boolean
|
||||
}
|
||||
|
||||
export async function getApplyActionBaseInfo ({ transaction, deviceAuthToken }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
export async function getApplyActionBaseInfo ({ database, transaction, deviceAuthToken }: {
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
deviceAuthToken: string
|
||||
}): Promise<ApplyActionBaseInfo> {
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
where: { deviceAuthToken },
|
||||
attributes: ['familyId', 'deviceId', 'nextSequenceNumber'],
|
||||
transaction: transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -46,11 +47,11 @@ export async function getApplyActionBaseInfo ({ transaction, deviceAuthToken }:
|
||||
nextSequenceNumber: deviceEntryUnsafe.nextSequenceNumber
|
||||
}
|
||||
|
||||
const familyEntryUnsafe = await transaction.legacy.database.family.findOne({
|
||||
const familyEntryUnsafe = await database.family.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction: transaction.legacy.transaction,
|
||||
transaction,
|
||||
attributes: ['hasFullVersion']
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -19,7 +19,7 @@ import { memoize } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { config } from '../../../config'
|
||||
import { VisibleConnectedDevicesManager } from '../../../connected-devices'
|
||||
import { SimpleDatabaseTransaction } from '../../../database/simple'
|
||||
import { Database } from '../../../database'
|
||||
import { setToList } from '../../../util/list'
|
||||
import { generateVersionId } from '../../../util/token'
|
||||
import { SourceUserNotFoundException } from './exception/illegal-state'
|
||||
@@ -29,7 +29,8 @@ export class Cache {
|
||||
readonly familyId: string
|
||||
readonly deviceId: string
|
||||
readonly hasFullVersion: boolean
|
||||
transaction: SimpleDatabaseTransaction
|
||||
transaction: Sequelize.Transaction
|
||||
readonly database: Database
|
||||
readonly connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
private requireSenderDoFullSync = false
|
||||
|
||||
@@ -47,16 +48,18 @@ export class Cache {
|
||||
triggeredSyncLevel: 0 | 1 | 2 = 0 // 0 = no, 1 = unimportant, 2 = important
|
||||
targetedTriggeredSyncLevels = new Map<string, 0 | 1 | 2>()
|
||||
|
||||
constructor ({ familyId, deviceId, hasFullVersion, transaction, connectedDevicesManager }: {
|
||||
constructor ({ familyId, deviceId, hasFullVersion, database, transaction, connectedDevicesManager }: {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
hasFullVersion: boolean
|
||||
transaction: SimpleDatabaseTransaction
|
||||
database: Database
|
||||
transaction: Sequelize.Transaction
|
||||
connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
}) {
|
||||
this.familyId = familyId
|
||||
this.deviceId = deviceId
|
||||
this.hasFullVersion = hasFullVersion || config.alwaysPro
|
||||
this.database = database
|
||||
this.transaction = transaction
|
||||
this.connectedDevicesManager = connectedDevicesManager
|
||||
}
|
||||
@@ -74,7 +77,7 @@ export class Cache {
|
||||
async subtransaction<T> (callback: () => Promise<T>): Promise<T> {
|
||||
const oldTransaction = this.transaction
|
||||
|
||||
return this.transaction.transaction(async (newTransaction) => {
|
||||
return this.database.transaction(async (newTransaction) => {
|
||||
try {
|
||||
this.transaction = newTransaction
|
||||
|
||||
@@ -84,18 +87,18 @@ export class Cache {
|
||||
} finally {
|
||||
this.transaction = oldTransaction
|
||||
}
|
||||
})
|
||||
}, { transaction: oldTransaction })
|
||||
}
|
||||
|
||||
getSecondPasswordHashOfParent = memoize(async (parentId: string) => {
|
||||
const userEntryUnsafe = await this.transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await this.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId: parentId,
|
||||
type: 'parent'
|
||||
},
|
||||
attributes: ['secondPasswordHash'],
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction: this.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -106,14 +109,14 @@ export class Cache {
|
||||
})
|
||||
|
||||
getSecondPasswordHashOfChild = memoize(async (childId: string) => {
|
||||
const userEntryUnsafe = await this.transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await this.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId: childId,
|
||||
type: 'child'
|
||||
},
|
||||
attributes: ['secondPasswordHash'],
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction: this.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -128,24 +131,24 @@ export class Cache {
|
||||
})
|
||||
|
||||
doesCategoryExist = memoize(async (categoryId: string) => {
|
||||
const categoryEntry = await this.transaction.legacy.database.category.findOne({
|
||||
const categoryEntry = await this.database.category.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction: this.transaction
|
||||
})
|
||||
|
||||
return !!categoryEntry
|
||||
})
|
||||
|
||||
doesUserExist = memoize(async (userId: string) => {
|
||||
const userEntry = await this.transaction.legacy.database.user.findOne({
|
||||
const userEntry = await this.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction: this.transaction
|
||||
})
|
||||
|
||||
return !!userEntry
|
||||
@@ -155,10 +158,10 @@ export class Cache {
|
||||
requireSenderFullSync: () => void = () => this.requireSenderDoFullSync = true
|
||||
|
||||
async saveModifiedVersionNumbers () {
|
||||
const { familyId } = this
|
||||
const { database, transaction, familyId } = this
|
||||
|
||||
if (this.categoriesWithModifiedApps.size > 0) {
|
||||
await this.transaction.legacy.database.category.update({
|
||||
await database.category.update({
|
||||
assignedAppsVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -167,14 +170,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedApps)
|
||||
}
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedApps.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedBaseData.size > 0) {
|
||||
await this.transaction.legacy.database.category.update({
|
||||
await database.category.update({
|
||||
baseVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -183,14 +186,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedBaseData)
|
||||
}
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedBaseData.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTimeLimitRules.size > 0) {
|
||||
await this.transaction.legacy.database.category.update({
|
||||
await database.category.update({
|
||||
timeLimitRulesVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -199,14 +202,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTimeLimitRules)
|
||||
}
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedTimeLimitRules.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedUsedTimes.size > 0) {
|
||||
await this.transaction.legacy.database.category.update({
|
||||
await database.category.update({
|
||||
usedTimesVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -215,14 +218,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedUsedTimes)
|
||||
}
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTasks.size > 0) {
|
||||
await this.transaction.legacy.database.category.update({
|
||||
await database.category.update({
|
||||
taskListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -231,46 +234,46 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTasks)
|
||||
}
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.invalidiateUserList) {
|
||||
await this.transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
userListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.invalidiateUserList = false
|
||||
}
|
||||
|
||||
if (this.invalidiateDeviceList) {
|
||||
await this.transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
deviceListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.invalidiateDeviceList = false
|
||||
}
|
||||
|
||||
if (this.invalidateU2fList) {
|
||||
await this.transaction.legacy.database.family.update({
|
||||
await database.family.update({
|
||||
u2fKeysVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction: this.transaction.legacy.transaction
|
||||
transaction
|
||||
})
|
||||
|
||||
this.invalidateU2fList = false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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,12 +37,12 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
}) {
|
||||
const roundedTimestamp = getRoundedTimestamp().toString(10)
|
||||
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: [
|
||||
'childId',
|
||||
'parentCategoryId',
|
||||
@@ -65,7 +65,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
currentExtraTime: number
|
||||
}) => {
|
||||
if (action.timeToAdd !== 0) {
|
||||
const oldItem = await cache.transaction.legacy.database.usedTime.findOne({
|
||||
const oldItem = await cache.database.usedTime.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
@@ -73,7 +73,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (oldItem) {
|
||||
@@ -84,7 +84,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
const newLastUpdate = parseInt(roundedTimestamp, 10)
|
||||
|
||||
if (oldUsedTime !== newUsedTime || oldLastUpdate !== newLastUpdate) {
|
||||
const [updatedRows] = await cache.transaction.legacy.database.usedTime.update({
|
||||
const [updatedRows] = await cache.database.usedTime.update({
|
||||
usedTime: newUsedTime,
|
||||
lastUpdate: newLastUpdate.toString(10)
|
||||
}, {
|
||||
@@ -95,7 +95,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (updatedRows === 0) {
|
||||
@@ -103,7 +103,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await cache.transaction.legacy.database.usedTime.create({
|
||||
await cache.database.usedTime.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
dayOfEpoch: action.dayOfEpoch,
|
||||
@@ -112,20 +112,20 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
}, {
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (action.extraTimeToSubtract !== 0) {
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: Math.max(0, currentExtraTime - action.extraTimeToSubtract)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(categoryId)
|
||||
@@ -140,13 +140,13 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
})
|
||||
|
||||
if (categoryEntry.parentCategoryId !== '') {
|
||||
const parentCategoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
const parentCategoryEntry = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: categoryEntry.parentCategoryId,
|
||||
childId: categoryEntry.childId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (parentCategoryEntry) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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,13 +37,13 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: deviceId
|
||||
},
|
||||
attributes: ['currentUserId'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -60,12 +60,12 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
let addUsedTimeForADifferentUserThanTheCurrentUserOfTheDevice = false
|
||||
|
||||
for (const item of action.items) {
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: [
|
||||
'childId',
|
||||
'extraTimeInMillis'
|
||||
@@ -89,11 +89,12 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
addUsedTimeForADifferentUserThanTheCurrentUserOfTheDevice = true
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-inner-declarations
|
||||
async function handle (start: number, end: number) {
|
||||
const lengthInMinutes = (end - start) + 1
|
||||
const lengthInMs = lengthInMinutes * 1000 * 60
|
||||
|
||||
const oldItem = await cache.transaction.legacy.database.usedTime.findOne({
|
||||
const oldItem = await cache.database.usedTime.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -101,7 +102,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (oldItem) {
|
||||
@@ -112,7 +113,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
const newLastUpdate = parseInt(roundedTimestampForUsedTime, 10)
|
||||
|
||||
if (oldUsedTime !== newUsedTime || oldLastUpdate !== newLastUpdate) {
|
||||
const [updatedRows] = await cache.transaction.legacy.database.usedTime.update({
|
||||
const [updatedRows] = await cache.database.usedTime.update({
|
||||
usedTime: newUsedTime,
|
||||
lastUpdate: newLastUpdate.toString(10)
|
||||
}, {
|
||||
@@ -123,7 +124,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (updatedRows === 0) {
|
||||
@@ -131,7 +132,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const oldTime: number | null = await cache.transaction.legacy.database.usedTime.aggregate(
|
||||
const oldTime: number | null = await cache.database.usedTime.aggregate(
|
||||
'usedTime',
|
||||
'MAX',
|
||||
{
|
||||
@@ -146,13 +147,13 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
[Sequelize.Op.lte]: end
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
}
|
||||
) || 0
|
||||
|
||||
if (oldTime !== null && typeof oldTime !== 'number') throw new Error()
|
||||
|
||||
await cache.transaction.legacy.database.usedTime.create({
|
||||
await cache.database.usedTime.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
dayOfEpoch: action.dayOfEpoch,
|
||||
@@ -161,7 +162,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
}, {
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -179,7 +180,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
for (let j = 0; j < item.sessionDurationLimits.length; j++) {
|
||||
const limit = item.sessionDurationLimits[j]
|
||||
|
||||
const oldItem = await cache.transaction.legacy.database.sessionDuration.findOne({
|
||||
const oldItem = await cache.database.sessionDuration.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -188,11 +189,11 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: limit.start,
|
||||
endMinuteOfDay: limit.end
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
const oldDuration: () => Promise<number> = async () => {
|
||||
const fittingDurationItems = await cache.transaction.legacy.database.sessionDuration.findAll({
|
||||
const fittingDurationItems = await cache.database.sessionDuration.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -209,15 +210,15 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
[Sequelize.Op.lte]: limit.pause
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
const fittingDurationItemsLastUsageFiltered =
|
||||
hasTrustedTimestamp ?
|
||||
fittingDurationItems.filter((it) => (
|
||||
fittingDurationItems.filter((it) => {
|
||||
action.trustedTimestamp - item.timeToAdd <=
|
||||
parseInt(it.lastUsage, 10) + it.sessionPauseDuration - tolerance
|
||||
)) : fittingDurationItems
|
||||
}) : fittingDurationItems
|
||||
|
||||
return fittingDurationItemsLastUsageFiltered
|
||||
.map((it) => it.lastSessionDuration)
|
||||
@@ -259,9 +260,9 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
}
|
||||
}
|
||||
|
||||
await oldItem.save({ transaction: cache.transaction.legacy.transaction })
|
||||
await oldItem.save({ transaction: cache.transaction })
|
||||
} else {
|
||||
await cache.transaction.legacy.database.sessionDuration.create({
|
||||
await cache.database.sessionDuration.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
maxSessionDuration: limit.duration,
|
||||
@@ -272,21 +273,21 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
lastUsage: action.trustedTimestamp.toString(10),
|
||||
lastSessionDuration: await oldDuration() + item.timeToAdd,
|
||||
roundedLastUpdate: roundedTimestampForSessionDuration
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}, { transaction: cache.transaction })
|
||||
}
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedUsedTimes.add(item.categoryId)
|
||||
|
||||
if (item.extraTimeToSubtract !== 0) {
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: Math.max(0, categoryEntry.extraTimeInMillis - item.extraTimeToSubtract)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(item.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -23,13 +23,13 @@ export async function dispatchFinishKeyRequestAction ({ action, cache, deviceId
|
||||
action: FinishKeyRequestAction
|
||||
cache: Cache
|
||||
}) {
|
||||
await cache.transaction.legacy.database.keyRequest.destroy({
|
||||
await cache.database.keyRequest.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
senderDeviceId: deviceId,
|
||||
senderSequenceNumber: action.deviceSequenceNumber.toString(10)
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
// no sync triggered
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
FinishKeyRequestAction,
|
||||
ForceSyncAction,
|
||||
MarkTaskPendingAction,
|
||||
PingAction,
|
||||
ReplyToKeyRequestAction,
|
||||
RemoveInstalledAppsAction,
|
||||
SendKeyRequestAction,
|
||||
@@ -42,7 +41,6 @@ import { dispatchAddUsedTimeVersion2 } from './addusedtime2'
|
||||
import { dispatchFinishKeyRequestAction } from './finishkeyrequest'
|
||||
import { dispatchForceSyncAction } from './forcesync'
|
||||
import { dispatchMarkTaskPendingAction } from './marktaskpendingaction'
|
||||
import { dispatchPingAction } from './ping'
|
||||
import { dispatchReplyToKeyRequestAction } from './replytokeyrequest'
|
||||
import { dispatchSendKeyRequestAction } from './sendkeyrequest'
|
||||
import { dispatchSignOutAtDevice } from './signoutatdevice'
|
||||
@@ -69,8 +67,6 @@ export const dispatchAppLogicAction = async ({ action, deviceId, cache, eventHan
|
||||
await dispatchForceSyncAction({ deviceId, action, cache })
|
||||
} else if (action instanceof MarkTaskPendingAction) {
|
||||
await dispatchMarkTaskPendingAction({ deviceId, action, cache })
|
||||
} else if (action instanceof PingAction) {
|
||||
await dispatchPingAction({ deviceId, action, cache })
|
||||
} else if (action instanceof ReplyToKeyRequestAction) {
|
||||
await dispatchReplyToKeyRequestAction({ deviceId, action, cache, eventHandler })
|
||||
} else if (action instanceof RemoveInstalledAppsAction) {
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
action: MarkTaskPendingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.transaction.legacy.database.childTask.findOne({
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: ['categoryId', 'pendingRequest', 'taskTitle']
|
||||
})
|
||||
|
||||
@@ -45,13 +45,13 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
|
||||
if (taskInfo.pendingRequest !== 0) return // review already requested
|
||||
|
||||
const categoryInfoUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
@@ -60,13 +60,13 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
|
||||
const categoryInfo = { childId: categoryInfoUnsafe.childId }
|
||||
|
||||
const deviceInfoUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceInfoUnsafe = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
attributes: ['currentUserId'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (deviceInfoUnsafe === null) throw new SourceDeviceNotFoundException()
|
||||
@@ -77,33 +77,33 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
throw new IllegalStateException({ staticMessage: 'Can not mark task pending for other user than the current user' })
|
||||
}
|
||||
|
||||
const childInfoUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
const childInfoUnsafe = await cache.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: categoryInfo.childId
|
||||
},
|
||||
attributes: ['name'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (childInfoUnsafe === null) throw new SourceUserNotFoundException()
|
||||
|
||||
const childInfo = { name: childInfoUnsafe.name }
|
||||
|
||||
await cache.transaction.legacy.database.childTask.update({ pendingRequest: 1 }, {
|
||||
await cache.database.childTask.update({ pendingRequest: 1 }, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(1) // parents are not faster reachable
|
||||
|
||||
await sendTaskDoneMails({
|
||||
database: cache.transaction.legacy.database,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
familyId: cache.familyId,
|
||||
childName: childInfo.name,
|
||||
taskTitle: taskInfo.taskTitle
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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 { PingAction } from '../../../../action'
|
||||
import { types as pingTypes } from '../../../../database/ping'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchPingAction ({ action, cache, deviceId }: {
|
||||
deviceId: string
|
||||
action: PingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
// handle insertion
|
||||
if (action.event === 'ping' || action.event === 'pong') {
|
||||
let type
|
||||
|
||||
if (action.event === 'ping') type = pingTypes.ping
|
||||
else if (action.event === 'pong') type = pingTypes.pong
|
||||
else throw new Error()
|
||||
|
||||
// delete any previous ping/pong
|
||||
await cache.transaction.legacy.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type: type
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// insert
|
||||
await cache.transaction.legacy.database.ping.create({
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type,
|
||||
token: action.token
|
||||
}, {
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// notify
|
||||
cache.incrementTargetedTriggeredSyncLevel(action.deviceId, 2)
|
||||
}
|
||||
|
||||
// handle deleting
|
||||
if (action.event === 'pong' || action.event === 'clear') {
|
||||
await cache.transaction.legacy.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: deviceId,
|
||||
senderDeviceId: action.deviceId,
|
||||
token: action.token
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -26,13 +26,13 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const requestUnsafe = await cache.transaction.legacy.database.keyRequest.findOne({
|
||||
const requestUnsafe = await cache.database.keyRequest.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
serverSequenceNumber: action.requestServerSequenceNumber.toString(10)
|
||||
},
|
||||
attributes: ['senderDeviceId', 'senderSequenceNumber'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!requestUnsafe) {
|
||||
@@ -46,14 +46,14 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
senderSequenceNumber: requestUnsafe.senderSequenceNumber
|
||||
}
|
||||
|
||||
const oldReplyCounter = await cache.transaction.legacy.database.keyResponse.count({
|
||||
const oldReplyCounter = await cache.database.keyResponse.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: request.senderDeviceId,
|
||||
requestServerSequenceNumber: action.requestServerSequenceNumber.toString(10),
|
||||
senderDeviceId: deviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (oldReplyCounter !== 0) {
|
||||
@@ -62,12 +62,12 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
return
|
||||
}
|
||||
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: request.senderDeviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: ['nextKeyReplySequenceNumber']
|
||||
})
|
||||
|
||||
@@ -81,17 +81,17 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
nextKeyReplySequenceNumber: deviceEntryUnsafe.nextKeyReplySequenceNumber
|
||||
}
|
||||
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
await cache.database.device.update({
|
||||
nextKeyReplySequenceNumber: (parseInt(deviceEntry.nextKeyReplySequenceNumber) + 1).toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: request.senderDeviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
await cache.transaction.legacy.database.keyResponse.create({
|
||||
await cache.database.keyResponse.create({
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: request.senderDeviceId,
|
||||
requestServerSequenceNumber: action.requestServerSequenceNumber.toString(10),
|
||||
@@ -102,7 +102,7 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
encryptedKey: action.encryptedKey,
|
||||
signature: action.signature
|
||||
}, {
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.incrementTargetedTriggeredSyncLevel(request.senderDeviceId, 2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -24,11 +24,11 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
action: SendKeyRequestAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const familyEntryUnsafe = await cache.transaction.legacy.database.family.findOne({
|
||||
const familyEntryUnsafe = await cache.database.family.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: ['nextServerKeyRequestSeq']
|
||||
})
|
||||
|
||||
@@ -38,16 +38,16 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
|
||||
const serverSequenceNumber = familyEntryUnsafe.nextServerKeyRequestSeq
|
||||
|
||||
await cache.transaction.legacy.database.family.update({
|
||||
await cache.database.family.update({
|
||||
nextServerKeyRequestSeq: (parseInt(serverSequenceNumber, 10) + 1).toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
await cache.transaction.legacy.database.keyRequest.destroy({
|
||||
await cache.database.keyRequest.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
senderDeviceId: deviceId,
|
||||
@@ -55,10 +55,10 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
deviceId: action.deviceId || null,
|
||||
categoryId: action.categoryId || null
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
await cache.transaction.legacy.database.keyRequest.create({
|
||||
await cache.database.keyRequest.create({
|
||||
familyId: cache.familyId,
|
||||
serverSequenceNumber: serverSequenceNumber,
|
||||
senderDeviceId: deviceId,
|
||||
@@ -69,7 +69,7 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
tempKey: action.tempKey,
|
||||
signature: action.signature
|
||||
}, {
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -30,12 +30,12 @@ export async function dispatchSignOutAtDevice ({ deviceId, cache }: {
|
||||
throw new PremiumVersionMissingException()
|
||||
}
|
||||
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
|
||||
+5
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
action: TriedDisablingDeviceAdminAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (deviceEntry === null) {
|
||||
@@ -43,7 +43,7 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
if (!deviceEntry.triedDisablingDeviceAdmin) {
|
||||
deviceEntry.triedDisablingDeviceAdmin = true
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
@@ -51,6 +51,7 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
|
||||
if (!hadManipulationBefore) {
|
||||
await sendManipulationWarnings({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
deviceName: deviceEntry.name,
|
||||
familyId: cache.familyId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -30,12 +30,12 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
action: UpdateDeviceStatusAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -175,11 +175,12 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
|
||||
if (hasDeviceManipulation(deviceEntry)) {
|
||||
if (!hadManipulationBefore) {
|
||||
await sendManipulationWarnings({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
deviceName: deviceEntry.name,
|
||||
familyId: cache.familyId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -26,13 +26,13 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }:
|
||||
cache: Cache
|
||||
}) {
|
||||
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
||||
await cache.transaction.legacy.database.encryptedAppList.upsert({
|
||||
await cache.database.encryptedAppList.upsert({
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
type,
|
||||
version: generateVersionId(),
|
||||
data
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}, { transaction: cache.transaction })
|
||||
}
|
||||
|
||||
if (action.base) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchUploadDevicePublicKeyAction ({ deviceId, action, c
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (deviceEntry === null) {
|
||||
@@ -39,7 +39,7 @@ export async function dispatchUploadDevicePublicKeyAction ({ deviceId, action, c
|
||||
} else if (deviceEntry.publicKey === null) {
|
||||
deviceEntry.publicKey = action.key
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -25,13 +25,13 @@ export const dispatchChildChangePassword = async ({ action, childUserId, cache }
|
||||
childUserId: string
|
||||
cache: Cache
|
||||
}) => {
|
||||
const childEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
const childEntry = await cache.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: childUserId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!childEntry) {
|
||||
@@ -44,12 +44,11 @@ export const dispatchChildChangePassword = async ({ action, childUserId, cache }
|
||||
childEntry.secondPasswordSalt = newPassword.secondSalt
|
||||
childEntry.secondPasswordHash = newPassword.secondHash
|
||||
|
||||
await childEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
await childEntry.save({ transaction: cache.transaction })
|
||||
|
||||
{
|
||||
const clear = cache.getSecondPasswordHashOfChild.cache.clear
|
||||
|
||||
if (clear) clear()
|
||||
clear && clear()
|
||||
}
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -39,13 +39,13 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
cache
|
||||
})
|
||||
|
||||
const userEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await cache.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
type: 'child',
|
||||
userId: childUserId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: [
|
||||
'currentDevice'
|
||||
]
|
||||
@@ -58,7 +58,7 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
if (userEntryUnsafe.currentDevice === deviceId) {
|
||||
// unassign to prevent way aroundprimary device rule
|
||||
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
await cache.database.user.update({
|
||||
currentDevice: ''
|
||||
}, {
|
||||
where: {
|
||||
@@ -66,7 +66,7 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
type: 'child',
|
||||
userId: childUserId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -45,14 +45,14 @@ export async function dispatchParentAction ({
|
||||
parser: parseParentAction,
|
||||
applier: async (parsedAction) => {
|
||||
if (isChildLimitAdding) {
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
attributes: ['currentUserId'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
currentUserId: action.userId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -67,14 +67,14 @@ export async function dispatchParentAction ({
|
||||
})
|
||||
}
|
||||
|
||||
const deviceUserEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
const deviceUserEntryUnsafe = await cache.database.user.findOne({
|
||||
attributes: ['flags'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: deviceUserId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!deviceUserEntryUnsafe) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -29,12 +29,12 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -50,13 +50,13 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
}
|
||||
}
|
||||
|
||||
const categoriesOfSameChild = (await cache.transaction.legacy.database.category.findAll({
|
||||
const categoriesOfSameChild = (await cache.database.category.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
childId
|
||||
},
|
||||
attributes: ['categoryId', 'parentCategoryId'],
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})).map((item) => ({
|
||||
categoryId: item.categoryId,
|
||||
parentCategoryId: item.parentCategoryId
|
||||
@@ -64,7 +64,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
|
||||
const userCategoryIds = categoriesOfSameChild.map((item) => item.categoryId)
|
||||
|
||||
const oldCategories = (await cache.transaction.legacy.database.categoryApp.findAll({
|
||||
const oldCategories = (await cache.database.categoryApp.findAll({
|
||||
attributes: [ 'categoryId' ],
|
||||
group: [ 'categoryId' ],
|
||||
where: {
|
||||
@@ -76,7 +76,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})).map((item) => item.categoryId)
|
||||
|
||||
if (fromChildSelfLimitAddChildUserId !== null) {
|
||||
@@ -92,13 +92,13 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
|
||||
try {
|
||||
const parentCategoriesOfTargetCategory = getCategoryWithParentCategories(categoriesOfSameChild, action.categoryId)
|
||||
const userEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
const userEntryUnsafe = await cache.database.user.findOne({
|
||||
attributes: [ 'categoryForNotAssignedApps' ],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: fromChildSelfLimitAddChildUserId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -111,7 +111,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
parentCategoriesOfTargetCategory.indexOf(validatedDefaultCategoryId) !== -1
|
||||
|
||||
const assertCanAddApp = async (packageName: string, isApp: boolean) => {
|
||||
const categoryAppEntryUnsafe = await cache.transaction.legacy.database.categoryApp.findOne({
|
||||
const categoryAppEntryUnsafe = await cache.database.categoryApp.findOne({
|
||||
attributes: [ 'categoryId' ],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
@@ -120,7 +120,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
},
|
||||
packageName: packageName
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
const categoryAppEntry = categoryAppEntryUnsafe ? { categoryId: categoryAppEntryUnsafe.categoryId } : null
|
||||
@@ -162,7 +162,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
}
|
||||
|
||||
if (oldCategories.length > 0) {
|
||||
await cache.transaction.legacy.database.categoryApp.destroy({
|
||||
await cache.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
@@ -172,18 +172,18 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
await cache.transaction.legacy.database.categoryApp.bulkCreate(
|
||||
await cache.database.categoryApp.bulkCreate(
|
||||
action.packageNames.map((packageName): CategoryAppAttributes => ({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
packageName
|
||||
})),
|
||||
{
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -25,12 +25,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
action: AddCategoryNetworkIdAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
transaction: cache.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -38,12 +38,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
const count = await cache.transaction.legacy.database.categoryNetworkId.count({
|
||||
const count = await cache.database.categoryNetworkId.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (count + 1 > maxNetworkIdsPerCategory) {
|
||||
@@ -52,13 +52,13 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
})
|
||||
}
|
||||
|
||||
const hasOldItem = (await cache.transaction.legacy.database.categoryNetworkId.count({
|
||||
const hasOldItem = (await cache.database.categoryNetworkId.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
networkItemId: action.itemId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})) !== 0
|
||||
|
||||
if (hasOldItem) {
|
||||
@@ -67,12 +67,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
})
|
||||
}
|
||||
|
||||
await cache.transaction.legacy.database.categoryNetworkId.create({
|
||||
await cache.database.categoryNetworkId.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
networkItemId: action.itemId,
|
||||
hashedNetworkId: action.hashedNetworkId
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -25,16 +25,16 @@ export async function dispatchAddU2f ({ action, cache, parentUserId }: {
|
||||
cache: Cache
|
||||
parentUserId: string
|
||||
}) {
|
||||
const counter = await cache.transaction.legacy.database.u2fKey.count({
|
||||
const counter = await cache.database.u2fKey.count({
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (counter >= 16) throw new LimitReachedException({ type: 'u2f keys' })
|
||||
|
||||
await cache.transaction.legacy.database.u2fKey.create({
|
||||
await cache.database.u2fKey.create({
|
||||
familyId: cache.familyId,
|
||||
keyId: getU2fKeyId({ keyHandle: action.keyHandle, publicKey: action.publicKey }),
|
||||
userId: parentUserId,
|
||||
@@ -42,7 +42,7 @@ export async function dispatchAddU2f ({ action, cache, parentUserId }: {
|
||||
keyHandle: action.keyHandle,
|
||||
publicKey: action.publicKey,
|
||||
nextCounter: '0'
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
cache.invalidateU2fList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -28,7 +28,7 @@ export async function dispatchAddUser ({ action, cache }: {
|
||||
await decryptParentPassword({ cache, password: action.password }) :
|
||||
null
|
||||
|
||||
await cache.transaction.legacy.database.user.create({
|
||||
await cache.database.user.create({
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
type: action.userType,
|
||||
@@ -45,7 +45,7 @@ export async function dispatchAddUser ({ action, cache }: {
|
||||
mailNotificationFlags: 0,
|
||||
blockedTimes: '',
|
||||
flags: '0'
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user