Compare commits

...

60 Commits

Author SHA1 Message Date
standardci
4bde4758c3 chore(release): publish new version
- @standardnotes/analytics@1.29.1
 - @standardnotes/api-gateway@1.19.5
 - @standardnotes/auth-server@1.28.3
 - @standardnotes/syncing-server@1.8.5
2022-09-16 10:19:03 +00:00
Karol Sójko
5eb957c82a fix(auth): change remaining subscription time stats to percentage 2022-09-16 12:17:34 +02:00
standardci
0b38617acf chore(release): publish new version
- @standardnotes/api-gateway@1.19.4
 - @standardnotes/auth-server@1.28.2
 - @standardnotes/domain-events-infra@1.8.10
 - @standardnotes/domain-events@2.60.4
 - @standardnotes/event-store@1.3.15
 - @standardnotes/files-server@1.5.52
 - @standardnotes/scheduler-server@1.10.29
 - @standardnotes/security@1.3.2
 - @standardnotes/syncing-server@1.8.4
2022-09-16 08:55:36 +00:00
Karol Sójko
377d32c449 fix(files): add verifying permitted operation on valet token 2022-09-16 10:52:25 +02:00
standardci
cdfb0c2603 chore(release): publish new version
- @standardnotes/auth-server@1.28.1
2022-09-15 12:19:43 +00:00
Karol Sójko
d85152429c fix(auth): missing injectable annotation 2022-09-15 14:17:56 +02:00
standardci
422e596fc7 chore(release): publish new version
- @standardnotes/api-gateway@1.19.3
2022-09-15 10:39:57 +00:00
Karol Sójko
89334c9022 fix(api-gateway): add remaining subscription time to stats 2022-09-15 12:38:28 +02:00
standardci
f5a0e88ab9 chore(release): publish new version
- @standardnotes/analytics@1.29.0
 - @standardnotes/api-gateway@1.19.2
 - @standardnotes/auth-server@1.28.0
 - @standardnotes/syncing-server@1.8.3
2022-09-15 10:23:29 +00:00
Karol Sójko
a59ba08339 feat(auth): add remaining subscription time stats 2022-09-15 12:21:59 +02:00
standardci
2641056c51 chore(release): publish new version
- @standardnotes/auth-server@1.27.0
2022-09-15 10:14:51 +00:00
Karol Sójko
5d812befc4 feat(auth): implement subscription server interface on server side 2022-09-15 12:12:50 +02:00
standardci
1c592d6f96 chore(release): publish new version
- @standardnotes/auth-server@1.26.1
2022-09-15 08:44:32 +00:00
Karol Sójko
531f13fe1f fix(auth): disallow duplicating subscription invites 2022-09-15 10:43:07 +02:00
standardci
4757cc8dae chore(release): publish new version
- @standardnotes/syncing-server@1.8.2
2022-09-15 08:27:49 +00:00
Karol Sójko
ecdfe9ecc0 fix(syncing-server): files count stats 2022-09-15 10:25:55 +02:00
standardci
d19cb08e9c chore(release): publish new version
- @standardnotes/auth-server@1.26.0
2022-09-13 13:48:14 +00:00
Karol Sójko
f45320e5ed feat(auth): add subscription sharing permission 2022-09-13 15:46:11 +02:00
standardci
93ded34de9 chore(release): publish new version
- @standardnotes/auth-server@1.25.13
2022-09-12 18:08:27 +00:00
Karol Sójko
dd13e2eaf7 fix(auth): add debug logs for canceling shared subscription invitations 2022-09-12 20:06:36 +02:00
standardci
1405c6f260 chore(release): publish new version
- @standardnotes/auth-server@1.25.12
2022-09-12 12:26:19 +00:00
Karol Sójko
0dab31f993 fix(auth): allow canceling shared subscription invitation before it was accepted 2022-09-12 14:24:52 +02:00
standardci
8070c70152 chore(release): publish new version
- @standardnotes/api-gateway@1.19.1
 - @standardnotes/auth-server@1.25.11
 - @standardnotes/common@1.32.0
 - @standardnotes/domain-events-infra@1.8.9
 - @standardnotes/domain-events@2.60.3
 - @standardnotes/event-store@1.3.14
 - @standardnotes/files-server@1.5.51
 - @standardnotes/predicates@1.4.1
 - @standardnotes/scheduler-server@1.10.28
 - @standardnotes/security@1.3.1
 - @standardnotes/syncing-server@1.8.1
2022-09-09 12:04:24 +00:00
Karol Sójko
c3ebb321cf feat(common): add either and only types 2022-09-09 14:02:25 +02:00
standardci
e54deb594a chore(release): publish new version
- @standardnotes/event-store@1.3.13
2022-09-09 10:13:14 +00:00
Karol Sójko
432d071ec8 fix(event-store): add missing event subscriptions 2022-09-09 12:11:45 +02:00
standardci
b9c06f1f5d chore(release): publish new version
- @standardnotes/analytics@1.28.0
 - @standardnotes/api-gateway@1.19.0
 - @standardnotes/auth-server@1.25.10
 - @standardnotes/syncing-server@1.8.0
2022-09-09 09:46:00 +00:00
Karol Sójko
52cc6462a6 feat(syncing-server): add tracking files count in stats 2022-09-09 11:44:02 +02:00
standardci
35c2afef67 chore(release): publish new version
- @standardnotes/analytics@1.27.0
 - @standardnotes/api-gateway@1.18.0
 - @standardnotes/auth-server@1.25.9
 - @standardnotes/syncing-server@1.7.1
2022-09-09 09:02:40 +00:00
Karol Sójko
339c86fca0 fix(api-gateway): add general activity breakdown to yesterdays report stats 2022-09-09 11:01:06 +02:00
Karol Sójko
0afd3de977 feat(api-gateway): add tracking general activity for free and paid users breakdown 2022-09-09 10:59:46 +02:00
standardci
e699569d46 chore(release): publish new version
- @standardnotes/api-gateway@1.17.4
2022-09-09 08:51:10 +00:00
Karol Sójko
ced852d9db fix(api-gateway): add notes count statistics to report 2022-09-09 10:49:15 +02:00
standardci
a63612613e chore(release): publish new version
- @standardnotes/analytics@1.26.0
 - @standardnotes/api-gateway@1.17.3
 - @standardnotes/auth-server@1.25.8
 - @standardnotes/syncing-server@1.7.0
2022-09-09 08:44:23 +00:00
Karol Sójko
c9ec7b492a feat(syncing-server): add statistics for notes count for free and paid users 2022-09-09 10:42:12 +02:00
standardci
bf8ffc07ee chore(release): publish new version
- @standardnotes/event-store@1.3.12
2022-09-08 14:11:09 +00:00
Karol Sójko
73e1ea7f93 fix(event-store): add listening to refund processed event 2022-09-08 16:08:57 +02:00
standardci
5979b99398 chore(release): publish new version
- @standardnotes/api-gateway@1.17.2
 - @standardnotes/auth-server@1.25.7
 - @standardnotes/domain-events-infra@1.8.8
 - @standardnotes/domain-events@2.60.2
 - @standardnotes/event-store@1.3.11
 - @standardnotes/files-server@1.5.50
 - @standardnotes/scheduler-server@1.10.27
 - @standardnotes/syncing-server@1.6.70
2022-09-08 13:27:38 +00:00
Karol Sójko
50ddb918cc fix(api-gateway): retention data structure to include both period keys 2022-09-08 15:25:41 +02:00
standardci
6b19eb8876 chore(release): publish new version
- @standardnotes/api-gateway@1.17.1
 - @standardnotes/auth-server@1.25.6
 - @standardnotes/domain-events-infra@1.8.7
 - @standardnotes/domain-events@2.60.1
 - @standardnotes/event-store@1.3.10
 - @standardnotes/files-server@1.5.49
 - @standardnotes/scheduler-server@1.10.26
 - @standardnotes/syncing-server@1.6.69
2022-09-08 13:13:13 +00:00
Karol Sójko
47be0841fc fix(api-gateway): retention data structure 2022-09-08 15:11:12 +02:00
standardci
99c7bb70fc chore(release): publish new version
- @standardnotes/api-gateway@1.17.0
 - @standardnotes/auth-server@1.25.5
 - @standardnotes/domain-events-infra@1.8.6
 - @standardnotes/domain-events@2.60.0
 - @standardnotes/event-store@1.3.9
 - @standardnotes/files-server@1.5.48
 - @standardnotes/scheduler-server@1.10.25
 - @standardnotes/syncing-server@1.6.68
2022-09-08 09:54:52 +00:00
Karol Sójko
f139bb0036 feat(api-gateway): add registration-to-activity retention analytics to report 2022-09-08 11:52:44 +02:00
standardci
23f592ca24 chore(release): publish new version
- @standardnotes/api-gateway@1.16.8
 - @standardnotes/auth-server@1.25.4
 - @standardnotes/domain-events-infra@1.8.5
 - @standardnotes/domain-events@2.59.3
 - @standardnotes/event-store@1.3.8
 - @standardnotes/files-server@1.5.47
 - @standardnotes/scheduler-server@1.10.24
 - @standardnotes/syncing-server@1.6.67
2022-09-08 08:33:27 +00:00
Karol Sójko
fe4821d4f7 Revert "fix(domain-events): add boolean for sending emails on refund processed"
This reverts commit d7e6758089.
2022-09-08 10:32:00 +02:00
standardci
c338d4fec5 chore(release): publish new version
- @standardnotes/api-gateway@1.16.7
 - @standardnotes/auth-server@1.25.3
 - @standardnotes/domain-events-infra@1.8.4
 - @standardnotes/domain-events@2.59.2
 - @standardnotes/event-store@1.3.7
 - @standardnotes/files-server@1.5.46
 - @standardnotes/scheduler-server@1.10.23
 - @standardnotes/syncing-server@1.6.66
2022-09-08 08:05:47 +00:00
Karol Sójko
d7e6758089 fix(domain-events): add boolean for sending emails on refund processed 2022-09-08 10:03:41 +02:00
standardci
0ad62636b9 chore(release): publish new version
- @standardnotes/analytics@1.25.0
 - @standardnotes/api-gateway@1.16.6
 - @standardnotes/auth-server@1.25.2
 - @standardnotes/syncing-server@1.6.65
2022-09-07 14:24:28 +00:00
Karol Sójko
f872c7dfe9 feat(analytics): add discrete period key generation for last 7 days 2022-09-07 16:22:40 +02:00
standardci
c5fdd59eb1 chore(release): publish new version
- @standardnotes/analytics@1.24.0
 - @standardnotes/api-gateway@1.16.5
 - @standardnotes/auth-server@1.25.1
 - @standardnotes/syncing-server@1.6.64
2022-09-07 14:18:45 +00:00
Karol Sójko
7132dc3ac0 feat(analytics): add calculation retention for two activities 2022-09-07 16:16:27 +02:00
standardci
956d5be959 chore(release): publish new version
- @standardnotes/api-gateway@1.16.4
2022-09-07 13:43:04 +00:00
Karol Sójko
936591d40b fix(api-gateway): add registration-to-subscription time to analytics report 2022-09-07 15:41:02 +02:00
standardci
686e4f8ddf chore(release): publish new version
- @standardnotes/analytics@1.23.0
 - @standardnotes/api-gateway@1.16.3
 - @standardnotes/auth-server@1.25.0
 - @standardnotes/syncing-server@1.6.63
2022-09-07 12:36:46 +00:00
Karol Sójko
b61825235e feat(auth): add measuring registration to subscription time statistics 2022-09-07 14:34:45 +02:00
standardci
8157f324a0 chore(release): publish new version
- @standardnotes/auth-server@1.24.4
2022-09-07 08:37:22 +00:00
Karol Sójko
132b617aaa fix(auth): forbid users on shared subscription to send out invitations 2022-09-07 10:35:06 +02:00
standardci
25b1f3e9ea chore(release): publish new version
- @standardnotes/api-gateway@1.16.2
 - @standardnotes/auth-server@1.24.3
 - @standardnotes/domain-events-infra@1.8.3
 - @standardnotes/domain-events@2.59.1
 - @standardnotes/event-store@1.3.6
 - @standardnotes/files-server@1.5.45
 - @standardnotes/scheduler-server@1.10.22
 - @standardnotes/syncing-server@1.6.62
2022-09-06 10:30:52 +00:00
Karol Sójko
f94c8fc26e fix(api-gateway): period types on analytics report 2022-09-06 12:28:48 +02:00
Karol Sójko
d149f46cf6 fix(api-gateway): include period key in statistics measures 2022-09-06 12:16:07 +02:00
93 changed files with 1692 additions and 330 deletions

110
.pnp.cjs generated
View File

@@ -2484,16 +2484,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["@standardnotes/api", [\
["npm:1.1.19", {\
"packageLocation": "./.yarn/cache/@standardnotes-api-npm-1.1.19-6a6d650ec9-cca168245a.zip/node_modules/@standardnotes/api/",\
["npm:1.7.2", {\
"packageLocation": "./.yarn/cache/@standardnotes-api-npm-1.7.2-e68e7d4e63-bdfc414e6d.zip/node_modules/@standardnotes/api/",\
"packageDependencies": [\
["@standardnotes/api", "npm:1.1.19"],\
["@standardnotes/auth", "npm:3.19.4"],\
["@standardnotes/api", "npm:1.7.2"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/encryption", "npm:1.12.0"],\
["@standardnotes/responses", "npm:1.6.39"],\
["@standardnotes/services", "npm:1.15.0"],\
["@standardnotes/utils", "npm:1.6.12"]\
["@standardnotes/encryption", "npm:1.15.2"],\
["@standardnotes/models", "npm:1.18.2"],\
["@standardnotes/responses", "npm:1.10.1"],\
["@standardnotes/security", "workspace:packages/security"],\
["@standardnotes/utils", "npm:1.9.0"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}]\
@@ -2506,6 +2507,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@newrelic/winston-enricher", "virtual:04783e12400851b8a3d76e71495851cc94959db6e62f04cb0a31190080629440b182d8c8eb4d7f2b04e281912f2783a5fd4d2c3c6ab68d38b7097246c93f4c19#npm:4.0.0"],\
["@sentry/node", "npm:7.5.0"],\
["@standardnotes/analytics", "workspace:packages/analytics"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/domain-events", "workspace:packages/domain-events"],\
["@standardnotes/domain-events-infra", "workspace:packages/domain-events-infra"],\
["@standardnotes/security", "workspace:packages/security"],\
@@ -2561,7 +2563,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@newrelic/winston-enricher", "virtual:04783e12400851b8a3d76e71495851cc94959db6e62f04cb0a31190080629440b182d8c8eb4d7f2b04e281912f2783a5fd4d2c3c6ab68d38b7097246c93f4c19#npm:4.0.0"],\
["@sentry/node", "npm:7.5.0"],\
["@standardnotes/analytics", "workspace:packages/analytics"],\
["@standardnotes/api", "npm:1.1.19"],\
["@standardnotes/api", "npm:1.7.2"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/domain-events", "workspace:packages/domain-events"],\
["@standardnotes/domain-events-infra", "workspace:packages/domain-events-infra"],\
@@ -2686,16 +2688,15 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["@standardnotes/encryption", [\
["npm:1.12.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-encryption-npm-1.12.0-eb2342c675-1a28653b1e.zip/node_modules/@standardnotes/encryption/",\
["npm:1.15.2", {\
"packageLocation": "./.yarn/cache/@standardnotes-encryption-npm-1.15.2-ef86a8281d-6e8336f1e7.zip/node_modules/@standardnotes/encryption/",\
"packageDependencies": [\
["@standardnotes/encryption", "npm:1.12.0"],\
["@standardnotes/encryption", "npm:1.15.2"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/models", "npm:1.14.0"],\
["@standardnotes/responses", "npm:1.6.39"],\
["@standardnotes/services", "npm:1.15.0"],\
["@standardnotes/sncrypto-common", "npm:1.9.0"],\
["@standardnotes/utils", "npm:1.6.12"],\
["@standardnotes/models", "npm:1.18.2"],\
["@standardnotes/responses", "npm:1.10.1"],\
["@standardnotes/sncrypto-common", "npm:1.11.1"],\
["@standardnotes/utils", "npm:1.9.0"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
@@ -2741,6 +2742,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}],\
["npm:1.52.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-features-npm-1.52.0-8c1adf7881-3e6014272f.zip/node_modules/@standardnotes/features/",\
"packageDependencies": [\
["@standardnotes/features", "npm:1.52.0"],\
["@standardnotes/auth", "npm:3.19.4"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/security", "workspace:packages/security"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}]\
]],\
["@standardnotes/files-server", [\
@@ -2796,14 +2808,14 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["@standardnotes/models", [\
["npm:1.14.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-models-npm-1.14.0-6f064d99e7-bfb9d517b6.zip/node_modules/@standardnotes/models/",\
["npm:1.18.2", {\
"packageLocation": "./.yarn/cache/@standardnotes-models-npm-1.18.2-56f35bb72d-88180a93e5.zip/node_modules/@standardnotes/models/",\
"packageDependencies": [\
["@standardnotes/models", "npm:1.14.0"],\
["@standardnotes/models", "npm:1.18.2"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/features", "npm:1.50.0"],\
["@standardnotes/responses", "npm:1.6.39"],\
["@standardnotes/utils", "npm:1.6.12"],\
["@standardnotes/features", "npm:1.52.0"],\
["@standardnotes/responses", "npm:1.10.1"],\
["@standardnotes/utils", "npm:1.9.0"],\
["lodash", "npm:4.17.21"],\
["reflect-metadata", "npm:0.1.13"]\
],\
@@ -2839,6 +2851,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["@standardnotes/responses", [\
["npm:1.10.1", {\
"packageLocation": "./.yarn/cache/@standardnotes-responses-npm-1.10.1-9f82fff6c1-b84fb3f71c.zip/node_modules/@standardnotes/responses/",\
"packageDependencies": [\
["@standardnotes/responses", "npm:1.10.1"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/features", "npm:1.52.0"],\
["@standardnotes/security", "workspace:packages/security"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}],\
["npm:1.6.39", {\
"packageLocation": "./.yarn/cache/@standardnotes-responses-npm-1.6.39-395f4c2d65-0ea1d4d5b8.zip/node_modules/@standardnotes/responses/",\
"packageDependencies": [\
@@ -2931,21 +2954,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
"linkType": "SOFT"\
}]\
]],\
["@standardnotes/services", [\
["npm:1.15.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-services-npm-1.15.0-acab3bc6a3-1028a5b4c1.zip/node_modules/@standardnotes/services/",\
"packageDependencies": [\
["@standardnotes/services", "npm:1.15.0"],\
["@standardnotes/auth", "npm:3.19.4"],\
["@standardnotes/common", "workspace:packages/common"],\
["@standardnotes/models", "npm:1.14.0"],\
["@standardnotes/responses", "npm:1.6.39"],\
["@standardnotes/utils", "npm:1.6.12"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}]\
]],\
["@standardnotes/settings", [\
["workspace:packages/settings", {\
"packageLocation": "./packages/settings/",\
@@ -2959,6 +2967,14 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["@standardnotes/sncrypto-common", [\
["npm:1.11.1", {\
"packageLocation": "./.yarn/cache/@standardnotes-sncrypto-common-npm-1.11.1-58d12d6912-69d698abb7.zip/node_modules/@standardnotes/sncrypto-common/",\
"packageDependencies": [\
["@standardnotes/sncrypto-common", "npm:1.11.1"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}],\
["npm:1.9.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-sncrypto-common-npm-1.9.0-48773f745a-42252d7198.zip/node_modules/@standardnotes/sncrypto-common/",\
"packageDependencies": [\
@@ -3070,6 +3086,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["lodash", "npm:4.17.21"]\
],\
"linkType": "HARD"\
}],\
["npm:1.9.0", {\
"packageLocation": "./.yarn/cache/@standardnotes-utils-npm-1.9.0-da939553f6-4591aff48d.zip/node_modules/@standardnotes/utils/",\
"packageDependencies": [\
["@standardnotes/utils", "npm:1.9.0"],\
["@standardnotes/common", "workspace:packages/common"],\
["dompurify", "npm:2.4.0"],\
["lodash", "npm:4.17.21"],\
["reflect-metadata", "npm:0.1.13"]\
],\
"linkType": "HARD"\
}]\
]],\
["@szmarczak/http-timer", [\
@@ -5843,6 +5870,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["dompurify", "npm:2.3.8"]\
],\
"linkType": "HARD"\
}],\
["npm:2.4.0", {\
"packageLocation": "./.yarn/cache/dompurify-npm-2.4.0-0ffecf22ef-c93ea73cf8.zip/node_modules/dompurify/",\
"packageDependencies": [\
["dompurify", "npm:2.4.0"]\
],\
"linkType": "HARD"\
}]\
]],\
["dot-prop", [\

Binary file not shown.

Binary file not shown.

View File

@@ -3,6 +3,54 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.29.1](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.29.0...@standardnotes/analytics@1.29.1) (2022-09-16)
### Bug Fixes
* **auth:** change remaining subscription time stats to percentage ([5eb957c](https://github.com/standardnotes/server/commit/5eb957c82a8cc5fdcb6815e2cd30e49cd2b1e8ac))
# [1.29.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.28.0...@standardnotes/analytics@1.29.0) (2022-09-15)
### Features
* **auth:** add remaining subscription time stats ([a59ba08](https://github.com/standardnotes/server/commit/a59ba083397c75960af0e8a102b617bf5baa287f))
# [1.28.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.27.0...@standardnotes/analytics@1.28.0) (2022-09-09)
### Features
* **syncing-server:** add tracking files count in stats ([52cc646](https://github.com/standardnotes/server/commit/52cc6462a66dae3bd6c05f551d4ba661c8a9b8c8))
# [1.27.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.26.0...@standardnotes/analytics@1.27.0) (2022-09-09)
### Features
* **api-gateway:** add tracking general activity for free and paid users breakdown ([0afd3de](https://github.com/standardnotes/server/commit/0afd3de9779e2abe10deede24626a3cbe6b15e6c))
# [1.26.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.25.0...@standardnotes/analytics@1.26.0) (2022-09-09)
### Features
* **syncing-server:** add statistics for notes count for free and paid users ([c9ec7b4](https://github.com/standardnotes/server/commit/c9ec7b492aea1911e441ed8ad9a155f871be2ef7))
# [1.25.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.24.0...@standardnotes/analytics@1.25.0) (2022-09-07)
### Features
* **analytics:** add discrete period key generation for last 7 days ([f872c7d](https://github.com/standardnotes/server/commit/f872c7dfe9f120f40dd0c28a9e0f5749eb251643))
# [1.24.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.23.0...@standardnotes/analytics@1.24.0) (2022-09-07)
### Features
* **analytics:** add calculation retention for two activities ([7132dc3](https://github.com/standardnotes/server/commit/7132dc3ac0cf878d2c326243747343e8a6746e2f))
# [1.23.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.22.0...@standardnotes/analytics@1.23.0) (2022-09-07)
### Features
* **auth:** add measuring registration to subscription time statistics ([b618252](https://github.com/standardnotes/server/commit/b61825235eebaf5eddb55cbda173176ca43c0099))
# [1.22.0](https://github.com/standardnotes/server/compare/@standardnotes/analytics@1.21.1...@standardnotes/analytics@1.22.0) (2022-09-06)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/analytics",
"version": "1.22.0",
"version": "1.29.1",
"engines": {
"node": ">=14.0.0 <17.0.0"
},

View File

@@ -1,6 +1,9 @@
export enum AnalyticsActivity {
GeneralActivity = 'general-activity',
GeneralActivityFreeUsers = 'general-activity-free-users',
GeneralActivityPaidUsers = 'general-activity-paid-users',
EditingItems = 'editing-items',
CheckingIntegrity = 'checking-integrity',
Login = 'login',
Register = 'register',
DeleteAccount = 'DeleteAccount',

View File

@@ -6,6 +6,12 @@ export interface AnalyticsStoreInterface {
markActivity(activities: AnalyticsActivity[], analyticsId: number, periods: Period[]): Promise<void>
wasActivityDone(activity: AnalyticsActivity, analyticsId: number, period: Period): Promise<boolean>
calculateActivityRetention(activity: AnalyticsActivity, firstPeriod: Period, secondPeriod: Period): Promise<number>
calculateActivitiesRetention(parameters: {
firstActivity: AnalyticsActivity
firstActivityPeriodKey: string
secondActivity: AnalyticsActivity
secondActivityPeriodKey: string
}): Promise<number>
calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number>
calculateActivityChangesTotalCount(
activity: AnalyticsActivity,

View File

@@ -2,5 +2,10 @@ export enum StatisticsMeasure {
Income = 'income',
SubscriptionLength = 'subscription-length',
RegistrationLength = 'registration-length',
RegistrationToSubscriptionTime = 'registration-to-subscription-time',
RemainingSubscriptionTimePercentage = 'remaining-subscription-time-percentage',
Refunds = 'refunds',
NotesCountFreeUsers = 'notes-count-free-users',
NotesCountPaidUsers = 'notes-count-paid-users',
FilesCount = 'files-count',
}

View File

@@ -8,6 +8,7 @@ export enum Period {
ThisMonth,
LastMonth,
Last30Days,
Last7Days,
Q1ThisYear,
Q2ThisYear,
Q3ThisYear,

View File

@@ -48,6 +48,18 @@ describe('PeriodKeyGenerator', () => {
])
})
it('should generate period keys for last 7 days', () => {
expect(createGenerator().getDiscretePeriodKeys(Period.Last7Days)).toEqual([
'2022-5-17',
'2022-5-18',
'2022-5-19',
'2022-5-20',
'2022-5-21',
'2022-5-22',
'2022-5-23',
])
})
it('should generate period keys for Q1', () => {
expect(createGenerator().getDiscretePeriodKeys(Period.Q1ThisYear)).toEqual(['2022-1', '2022-2', '2022-3'])
})

View File

@@ -11,6 +11,12 @@ export class PeriodKeyGenerator implements PeriodKeyGeneratorInterface {
periodKeys.unshift(this.getDailyKey(this.getDateNDaysBefore(i)))
}
return periodKeys
case Period.Last7Days:
for (let i = 1; i <= 7; i++) {
periodKeys.unshift(this.getDailyKey(this.getDateNDaysBefore(i)))
}
return periodKeys
case Period.Q1ThisYear:
return this.generateMonthlyKeysRange(0, 3)

View File

@@ -125,7 +125,7 @@ describe('RedisAnalyticsStore', () => {
expect(redisClient.bitop).toHaveBeenCalledWith(
'AND',
'bitmap:action:editing-items:timespan:period-key-period-key',
'bitmap:action:editing-items-editing-items:timespan:period-key',
'bitmap:action:editing-items:timespan:period-key',
'bitmap:action:editing-items:timespan:period-key',
)

View File

@@ -95,21 +95,19 @@ export class RedisAnalyticsStore implements AnalyticsStoreInterface {
return bitValue === 1
}
async calculateActivityRetention(
activity: AnalyticsActivity,
firstPeriod: Period,
secondPeriod: Period,
): Promise<number> {
const initialPeriodKey = this.periodKeyGenerator.getPeriodKey(firstPeriod)
const subsequentPeriodKey = this.periodKeyGenerator.getPeriodKey(secondPeriod)
const diffKey = `bitmap:action:${activity}:timespan:${initialPeriodKey}-${subsequentPeriodKey}`
async calculateActivitiesRetention(parameters: {
firstActivity: AnalyticsActivity
firstActivityPeriodKey: string
secondActivity: AnalyticsActivity
secondActivityPeriodKey: string
}): Promise<number> {
const diffKey = `bitmap:action:${parameters.firstActivity}-${parameters.secondActivity}:timespan:${parameters.secondActivityPeriodKey}`
await this.redisClient.bitop(
'AND',
diffKey,
`bitmap:action:${activity}:timespan:${initialPeriodKey}`,
`bitmap:action:${activity}:timespan:${subsequentPeriodKey}`,
`bitmap:action:${parameters.firstActivity}:timespan:${parameters.firstActivityPeriodKey}`,
`bitmap:action:${parameters.secondActivity}:timespan:${parameters.secondActivityPeriodKey}`,
)
await this.redisClient.expire(diffKey, 3600)
@@ -117,12 +115,25 @@ export class RedisAnalyticsStore implements AnalyticsStoreInterface {
const retainedTotalInActivity = await this.redisClient.bitcount(diffKey)
const initialTotalInActivity = await this.redisClient.bitcount(
`bitmap:action:${activity}:timespan:${initialPeriodKey}`,
`bitmap:action:${parameters.firstActivity}:timespan:${parameters.firstActivityPeriodKey}`,
)
return Math.ceil((retainedTotalInActivity * 100) / initialTotalInActivity)
}
async calculateActivityRetention(
activity: AnalyticsActivity,
firstPeriod: Period,
secondPeriod: Period,
): Promise<number> {
return this.calculateActivitiesRetention({
firstActivity: activity,
firstActivityPeriodKey: this.periodKeyGenerator.getPeriodKey(firstPeriod),
secondActivity: activity,
secondActivityPeriodKey: this.periodKeyGenerator.getPeriodKey(secondPeriod),
})
}
async calculateActivityTotalCount(activity: AnalyticsActivity, period: Period): Promise<number> {
return this.redisClient.bitcount(
`bitmap:action:${activity}:timespan:${this.periodKeyGenerator.getPeriodKey(period)}`,

View File

@@ -93,7 +93,7 @@ describe('RedisStatisticsStore', () => {
})
it('should increment measure by a value', async () => {
await createStore().incrementMeasure(StatisticsMeasure.PaymentSuccess, 2, [Period.Today, Period.ThisMonth])
await createStore().incrementMeasure(StatisticsMeasure.Income, 2, [Period.Today, Period.ThisMonth])
expect(pipeline.incr).toHaveBeenCalledTimes(2)
expect(pipeline.incrbyfloat).toHaveBeenCalledTimes(2)
@@ -103,18 +103,18 @@ describe('RedisStatisticsStore', () => {
it('should count a measurement average', async () => {
redisClient.get = jest.fn().mockReturnValueOnce('5').mockReturnValueOnce('2')
expect(await createStore().getMeasureAverage(StatisticsMeasure.PaymentSuccess, Period.Today)).toEqual(2 / 5)
expect(await createStore().getMeasureAverage(StatisticsMeasure.Income, Period.Today)).toEqual(2 / 5)
})
it('should count a measurement average - 0 increments', async () => {
redisClient.get = jest.fn().mockReturnValueOnce(null).mockReturnValueOnce(null)
expect(await createStore().getMeasureAverage(StatisticsMeasure.PaymentSuccess, Period.Today)).toEqual(0)
expect(await createStore().getMeasureAverage(StatisticsMeasure.Income, Period.Today)).toEqual(0)
})
it('should count a measurement average - 0 total value', async () => {
redisClient.get = jest.fn().mockReturnValueOnce(5).mockReturnValueOnce(null)
expect(await createStore().getMeasureAverage(StatisticsMeasure.PaymentSuccess, Period.Today)).toEqual(0)
expect(await createStore().getMeasureAverage(StatisticsMeasure.Income, Period.Today)).toEqual(0)
})
})

View File

@@ -3,6 +3,107 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.19.5](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.19.4...@standardnotes/api-gateway@1.19.5) (2022-09-16)
### Bug Fixes
* **auth:** change remaining subscription time stats to percentage ([5eb957c](https://github.com/standardnotes/api-gateway/commit/5eb957c82a8cc5fdcb6815e2cd30e49cd2b1e8ac))
## [1.19.4](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.19.3...@standardnotes/api-gateway@1.19.4) (2022-09-16)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.19.3](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.19.2...@standardnotes/api-gateway@1.19.3) (2022-09-15)
### Bug Fixes
* **api-gateway:** add remaining subscription time to stats ([89334c9](https://github.com/standardnotes/api-gateway/commit/89334c90221045308d83fce9e97c146185d21389))
## [1.19.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.19.1...@standardnotes/api-gateway@1.19.2) (2022-09-15)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.19.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.19.0...@standardnotes/api-gateway@1.19.1) (2022-09-09)
**Note:** Version bump only for package @standardnotes/api-gateway
# [1.19.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.18.0...@standardnotes/api-gateway@1.19.0) (2022-09-09)
### Features
* **syncing-server:** add tracking files count in stats ([52cc646](https://github.com/standardnotes/api-gateway/commit/52cc6462a66dae3bd6c05f551d4ba661c8a9b8c8))
# [1.18.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.17.4...@standardnotes/api-gateway@1.18.0) (2022-09-09)
### Bug Fixes
* **api-gateway:** add general activity breakdown to yesterdays report stats ([339c86f](https://github.com/standardnotes/api-gateway/commit/339c86fca073b02054260417b7519c08874e1e4e))
### Features
* **api-gateway:** add tracking general activity for free and paid users breakdown ([0afd3de](https://github.com/standardnotes/api-gateway/commit/0afd3de9779e2abe10deede24626a3cbe6b15e6c))
## [1.17.4](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.17.3...@standardnotes/api-gateway@1.17.4) (2022-09-09)
### Bug Fixes
* **api-gateway:** add notes count statistics to report ([ced852d](https://github.com/standardnotes/api-gateway/commit/ced852d9dbf8cab4c235b94a834968a5fc5e7d36))
## [1.17.3](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.17.2...@standardnotes/api-gateway@1.17.3) (2022-09-09)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.17.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.17.1...@standardnotes/api-gateway@1.17.2) (2022-09-08)
### Bug Fixes
* **api-gateway:** retention data structure to include both period keys ([50ddb91](https://github.com/standardnotes/api-gateway/commit/50ddb918ccc52bee4caad82504cb899bc5936150))
## [1.17.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.17.0...@standardnotes/api-gateway@1.17.1) (2022-09-08)
### Bug Fixes
* **api-gateway:** retention data structure ([47be084](https://github.com/standardnotes/api-gateway/commit/47be0841fc6d5fa00892e775bb3a40f404a6382b))
# [1.17.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.8...@standardnotes/api-gateway@1.17.0) (2022-09-08)
### Features
* **api-gateway:** add registration-to-activity retention analytics to report ([f139bb0](https://github.com/standardnotes/api-gateway/commit/f139bb003669bb41f98ad4bb59a036c489f43606))
## [1.16.8](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.7...@standardnotes/api-gateway@1.16.8) (2022-09-08)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.16.7](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.6...@standardnotes/api-gateway@1.16.7) (2022-09-08)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.16.6](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.5...@standardnotes/api-gateway@1.16.6) (2022-09-07)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.16.5](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.4...@standardnotes/api-gateway@1.16.5) (2022-09-07)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.16.4](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.3...@standardnotes/api-gateway@1.16.4) (2022-09-07)
### Bug Fixes
* **api-gateway:** add registration-to-subscription time to analytics report ([936591d](https://github.com/standardnotes/api-gateway/commit/936591d40b5f5beb5c0a824c92cdfa20fff51c97))
## [1.16.3](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.2...@standardnotes/api-gateway@1.16.3) (2022-09-07)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.16.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.1...@standardnotes/api-gateway@1.16.2) (2022-09-06)
### Bug Fixes
* **api-gateway:** include period key in statistics measures ([d149f46](https://github.com/standardnotes/api-gateway/commit/d149f46cf6456201dd8690977f64ed32a75f3459))
* **api-gateway:** period types on analytics report ([f94c8fc](https://github.com/standardnotes/api-gateway/commit/f94c8fc26e684a07101cc5282ebb9cda3c8c6961))
## [1.16.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.0...@standardnotes/api-gateway@1.16.1) (2022-09-06)
**Note:** Version bump only for package @standardnotes/api-gateway

View File

@@ -16,6 +16,7 @@ import {
AnalyticsActivity,
AnalyticsStoreInterface,
Period,
PeriodKeyGeneratorInterface,
StatisticsMeasure,
StatisticsStoreInterface,
} from '@standardnotes/analytics'
@@ -24,6 +25,7 @@ const requestReport = async (
analyticsStore: AnalyticsStoreInterface,
statisticsStore: StatisticsStoreInterface,
domainEventPublisher: DomainEventPublisherInterface,
periodKeyGenerator: PeriodKeyGeneratorInterface,
): Promise<void> => {
const analyticsOverTime = []
@@ -68,6 +70,8 @@ const requestReport = async (
const yesterdayActivityNames = [
AnalyticsActivity.LimitedDiscountOfferPurchased,
AnalyticsActivity.GeneralActivity,
AnalyticsActivity.GeneralActivityFreeUsers,
AnalyticsActivity.GeneralActivityPaidUsers,
AnalyticsActivity.PaymentFailed,
AnalyticsActivity.PaymentSuccess,
]
@@ -89,18 +93,43 @@ const requestReport = async (
StatisticsMeasure.Refunds,
StatisticsMeasure.RegistrationLength,
StatisticsMeasure.SubscriptionLength,
StatisticsMeasure.RegistrationToSubscriptionTime,
StatisticsMeasure.RemainingSubscriptionTimePercentage,
StatisticsMeasure.NotesCountFreeUsers,
StatisticsMeasure.NotesCountPaidUsers,
StatisticsMeasure.FilesCount,
]
const statisticMeasures = []
for (const statisticMeasureName of statisticMeasureNames) {
for (const period of [Period.Yesterday, Period.ThisMonth]) {
statisticMeasures.push({
name: statisticMeasureName,
period,
totalValue: await statisticsStore.getMeasureTotal(statisticMeasureName, period),
average: await statisticsStore.getMeasureAverage(statisticMeasureName, period),
})
}
}
const periodKeys = periodKeyGenerator.getDiscretePeriodKeys(Period.Last7Days)
const retentionOverDays = []
for (let i = 0; i < periodKeys.length; i++) {
for (let j = 0; j < periodKeys.length - i; j++) {
const dailyRetention = await analyticsStore.calculateActivitiesRetention({
firstActivity: AnalyticsActivity.Register,
firstActivityPeriodKey: periodKeys[i],
secondActivity: AnalyticsActivity.GeneralActivity,
secondActivityPeriodKey: periodKeys[i + j],
})
retentionOverDays.push({
firstPeriodKey: periodKeys[i],
secondPeriodKey: periodKeys[i + j],
value: dailyRetention,
})
}
}
const event: DailyAnalyticsReportGeneratedEvent = {
type: 'DAILY_ANALYTICS_REPORT_GENERATED',
createdAt: new Date(),
@@ -118,6 +147,16 @@ const requestReport = async (
activityStatistics: yesterdayActivityStatistics,
activityStatisticsOverTime: analyticsOverTime,
statisticMeasures,
retentionStatistics: [
{
firstActivity: AnalyticsActivity.Register,
secondActivity: AnalyticsActivity.GeneralActivity,
retention: {
periodKeys,
values: retentionOverDays,
},
},
],
},
}
@@ -136,8 +175,9 @@ void container.load().then((container) => {
const analyticsStore: AnalyticsStoreInterface = container.get(TYPES.AnalyticsStore)
const statisticsStore: StatisticsStoreInterface = container.get(TYPES.StatisticsStore)
const domainEventPublisher: DomainEventPublisherInterface = container.get(TYPES.DomainEventPublisher)
const periodKeyGenerator: PeriodKeyGeneratorInterface = container.get(TYPES.PeriodKeyGenerator)
Promise.resolve(requestReport(analyticsStore, statisticsStore, domainEventPublisher))
Promise.resolve(requestReport(analyticsStore, statisticsStore, domainEventPublisher, periodKeyGenerator))
.then(() => {
logger.info('Usage report generation complete')

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.16.1",
"version": "1.19.5",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
@@ -25,6 +25,7 @@
"@newrelic/winston-enricher": "^4.0.0",
"@sentry/node": "^7.3.0",
"@standardnotes/analytics": "workspace:*",
"@standardnotes/common": "workspace:^",
"@standardnotes/domain-events": "workspace:*",
"@standardnotes/domain-events-infra": "workspace:*",
"@standardnotes/security": "workspace:*",

View File

@@ -6,6 +6,7 @@ import * as AWS from 'aws-sdk'
import {
AnalyticsStoreInterface,
PeriodKeyGenerator,
PeriodKeyGeneratorInterface,
RedisAnalyticsStore,
RedisStatisticsStore,
StatisticsStoreInterface,
@@ -91,13 +92,13 @@ export class ContainerConfigLoader {
// Services
container.bind<HttpServiceInterface>(TYPES.HTTPService).to(HttpService)
const periodKeyGenerator = new PeriodKeyGenerator()
container.bind<PeriodKeyGeneratorInterface>(TYPES.PeriodKeyGenerator).toConstantValue(new PeriodKeyGenerator())
container
.bind<AnalyticsStoreInterface>(TYPES.AnalyticsStore)
.toConstantValue(new RedisAnalyticsStore(periodKeyGenerator, container.get(TYPES.Redis)))
.toConstantValue(new RedisAnalyticsStore(container.get(TYPES.PeriodKeyGenerator), container.get(TYPES.Redis)))
container
.bind<StatisticsStoreInterface>(TYPES.StatisticsStore)
.toConstantValue(new RedisStatisticsStore(periodKeyGenerator, container.get(TYPES.Redis)))
.toConstantValue(new RedisStatisticsStore(container.get(TYPES.PeriodKeyGenerator), container.get(TYPES.Redis)))
container.bind<CrossServiceTokenCacheInterface>(TYPES.CrossServiceTokenCache).to(RedisCrossServiceTokenCache)
container.bind<TimerInterface>(TYPES.Timer).toConstantValue(new Timer())

View File

@@ -26,6 +26,7 @@ const TYPES = {
StatisticsStore: Symbol.for('StatisticsStore'),
DomainEventPublisher: Symbol.for('DomainEventPublisher'),
Timer: Symbol.for('Timer'),
PeriodKeyGenerator: Symbol.for('PeriodKeyGenerator'),
}
export default TYPES

View File

@@ -1,4 +1,5 @@
import { CrossServiceTokenData } from '@standardnotes/security'
import { RoleName } from '@standardnotes/common'
import { AnalyticsActivity, AnalyticsStoreInterface, Period } from '@standardnotes/analytics'
import { TimerInterface } from '@standardnotes/time'
import { NextFunction, Request, Response } from 'express'
@@ -75,9 +76,20 @@ export class AuthMiddleware extends BaseMiddleware {
const decodedToken = <CrossServiceTokenData>verify(crossServiceToken, this.jwtSecret, { algorithms: ['HS256'] })
await this.analyticsStore.markActivity([AnalyticsActivity.GeneralActivity], decodedToken.analyticsId as number, [
Period.Today,
])
response.locals.freeUser =
decodedToken.roles.length === 1 &&
decodedToken.roles.find((role) => role.name === RoleName.CoreUser) !== undefined
await this.analyticsStore.markActivity(
[
AnalyticsActivity.GeneralActivity,
response.locals.freeUser
? AnalyticsActivity.GeneralActivityFreeUsers
: AnalyticsActivity.GeneralActivityPaidUsers,
],
decodedToken.analyticsId as number,
[Period.Today],
)
if (this.crossServiceTokenCacheTTL && !crossServiceTokenFetchedFromCache) {
await this.crossServiceTokenCache.set({

View File

@@ -3,6 +3,120 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.28.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.28.2...@standardnotes/auth-server@1.28.3) (2022-09-16)
### Bug Fixes
* **auth:** change remaining subscription time stats to percentage ([5eb957c](https://github.com/standardnotes/server/commit/5eb957c82a8cc5fdcb6815e2cd30e49cd2b1e8ac))
## [1.28.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.28.1...@standardnotes/auth-server@1.28.2) (2022-09-16)
### Bug Fixes
* **files:** add verifying permitted operation on valet token ([377d32c](https://github.com/standardnotes/server/commit/377d32c4498305f0f59ff59e7357f0d2f10ce3a2))
## [1.28.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.28.0...@standardnotes/auth-server@1.28.1) (2022-09-15)
### Bug Fixes
* **auth:** missing injectable annotation ([d851524](https://github.com/standardnotes/server/commit/d85152429ca379d3d0314a9864cc46ebee541958))
# [1.28.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.27.0...@standardnotes/auth-server@1.28.0) (2022-09-15)
### Features
* **auth:** add remaining subscription time stats ([a59ba08](https://github.com/standardnotes/server/commit/a59ba083397c75960af0e8a102b617bf5baa287f))
# [1.27.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.26.1...@standardnotes/auth-server@1.27.0) (2022-09-15)
### Features
* **auth:** implement subscription server interface on server side ([5d812be](https://github.com/standardnotes/server/commit/5d812befc4733954919eef0d3718ae6f8eb81654))
## [1.26.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.26.0...@standardnotes/auth-server@1.26.1) (2022-09-15)
### Bug Fixes
* **auth:** disallow duplicating subscription invites ([531f13f](https://github.com/standardnotes/server/commit/531f13fe1f4bdfb8d27f5e3c07ec0b15d36ad413))
# [1.26.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.13...@standardnotes/auth-server@1.26.0) (2022-09-13)
### Features
* **auth:** add subscription sharing permission ([f45320e](https://github.com/standardnotes/server/commit/f45320e5ed8948a432029586c05284f4d640de5b))
## [1.25.13](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.12...@standardnotes/auth-server@1.25.13) (2022-09-12)
### Bug Fixes
* **auth:** add debug logs for canceling shared subscription invitations ([dd13e2e](https://github.com/standardnotes/server/commit/dd13e2eaf74de56a3c8c30c236c32c6dc0c560f2))
## [1.25.12](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.11...@standardnotes/auth-server@1.25.12) (2022-09-12)
### Bug Fixes
* **auth:** allow canceling shared subscription invitation before it was accepted ([0dab31f](https://github.com/standardnotes/server/commit/0dab31f9936bfd5081a87eef9701a268b8dec88c))
## [1.25.11](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.10...@standardnotes/auth-server@1.25.11) (2022-09-09)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.10](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.9...@standardnotes/auth-server@1.25.10) (2022-09-09)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.9](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.8...@standardnotes/auth-server@1.25.9) (2022-09-09)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.8](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.7...@standardnotes/auth-server@1.25.8) (2022-09-09)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.7](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.6...@standardnotes/auth-server@1.25.7) (2022-09-08)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.6](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.5...@standardnotes/auth-server@1.25.6) (2022-09-08)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.5](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.4...@standardnotes/auth-server@1.25.5) (2022-09-08)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.4](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.3...@standardnotes/auth-server@1.25.4) (2022-09-08)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.2...@standardnotes/auth-server@1.25.3) (2022-09-08)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.1...@standardnotes/auth-server@1.25.2) (2022-09-07)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.25.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.25.0...@standardnotes/auth-server@1.25.1) (2022-09-07)
**Note:** Version bump only for package @standardnotes/auth-server
# [1.25.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.4...@standardnotes/auth-server@1.25.0) (2022-09-07)
### Features
* **auth:** add measuring registration to subscription time statistics ([b618252](https://github.com/standardnotes/server/commit/b61825235eebaf5eddb55cbda173176ca43c0099))
## [1.24.4](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.3...@standardnotes/auth-server@1.24.4) (2022-09-07)
### Bug Fixes
* **auth:** forbid users on shared subscription to send out invitations ([132b617](https://github.com/standardnotes/server/commit/132b617aaa8a703877fd7e8d23711fb1ec234524))
## [1.24.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.2...@standardnotes/auth-server@1.24.3) (2022-09-06)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.24.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.1...@standardnotes/auth-server@1.24.2) (2022-09-06)
**Note:** Version bump only for package @standardnotes/auth-server

View File

@@ -17,10 +17,10 @@ import '../src/Controller/SubscriptionTokensController'
import '../src/Controller/OfflineController'
import '../src/Controller/ValetTokenController'
import '../src/Controller/ListedController'
import '../src/Controller/SubscriptionInvitesController'
import '../src/Controller/SubscriptionSettingsController'
import '../src/Infra/InversifyExpressUtils/InversifyExpressAuthController'
import '../src/Infra/InversifyExpressUtils/InversifyExpressSubscriptionInvitesController'
import * as cors from 'cors'
import { urlencoded, json, Request, Response, NextFunction, RequestHandler, ErrorRequestHandler } from 'express'

View File

@@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class addSubscriptionSharingPermission1663073954000 implements MigrationInterface {
name = 'addSubscriptionSharingPermission1663073954000'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'INSERT INTO `permissions` (uuid, name) VALUES ("3aeaf12e-380f-4f21-97b9-d862d63874f6", "server:subscription-sharing")',
)
// Pro User Permissions
await queryRunner.query(
'INSERT INTO `role_permissions` (role_uuid, permission_uuid) VALUES \
("8047edbb-a10a-4ff8-8d53-c2cae600a8e8", "3aeaf12e-380f-4f21-97b9-d862d63874f6") \
',
)
}
public async down(): Promise<void> {
return
}
}

View File

@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class addRenewedAtColumn1663321030000 implements MigrationInterface {
name = 'addRenewedAtColumn1663321030000'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('ALTER TABLE `user_subscriptions` ADD `renewed_at` bigint NULL')
}
public async down(): Promise<void> {
return
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.24.2",
"version": "1.28.3",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
@@ -34,7 +34,7 @@
"@newrelic/winston-enricher": "^4.0.0",
"@sentry/node": "^7.3.0",
"@standardnotes/analytics": "workspace:*",
"@standardnotes/api": "^1.1.19",
"@standardnotes/api": "^1.7.2",
"@standardnotes/common": "workspace:*",
"@standardnotes/domain-events": "workspace:*",
"@standardnotes/domain-events-infra": "workspace:*",

View File

@@ -200,6 +200,7 @@ import { MuteMarketingEmails } from '../Domain/UseCase/MuteMarketingEmails/MuteM
import { PaymentFailedEventHandler } from '../Domain/Handler/PaymentFailedEventHandler'
import { PaymentSuccessEventHandler } from '../Domain/Handler/PaymentSuccessEventHandler'
import { RefundProcessedEventHandler } from '../Domain/Handler/RefundProcessedEventHandler'
import { SubscriptionInvitesController } from '../Controller/SubscriptionInvitesController'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelicFormatter = require('@newrelic/winston-enricher')
@@ -262,6 +263,7 @@ export class ContainerConfigLoader {
// Controller
container.bind<AuthController>(TYPES.AuthController).to(AuthController)
container.bind<SubscriptionInvitesController>(TYPES.SubscriptionInvitesController).to(SubscriptionInvitesController)
// Repositories
container.bind<SessionRepositoryInterface>(TYPES.SessionRepository).to(MySQLSessionRepository)

View File

@@ -5,6 +5,7 @@ const TYPES = {
SQS: Symbol.for('SQS'),
// Controller
AuthController: Symbol.for('AuthController'),
SubscriptionInvitesController: Symbol.for('SubscriptionInvitesController'),
// Repositories
UserRepository: Symbol.for('UserRepository'),
SessionRepository: Symbol.for('SessionRepository'),

View File

@@ -1,16 +1,13 @@
import 'reflect-metadata'
import * as express from 'express'
import { SubscriptionInvitesController } from './SubscriptionInvitesController'
import { results } from 'inversify-express-utils'
import { User } from '../Domain/User/User'
import { InviteToSharedSubscription } from '../Domain/UseCase/InviteToSharedSubscription/InviteToSharedSubscription'
import { AcceptSharedSubscriptionInvitation } from '../Domain/UseCase/AcceptSharedSubscriptionInvitation/AcceptSharedSubscriptionInvitation'
import { DeclineSharedSubscriptionInvitation } from '../Domain/UseCase/DeclineSharedSubscriptionInvitation/DeclineSharedSubscriptionInvitation'
import { CancelSharedSubscriptionInvitation } from '../Domain/UseCase/CancelSharedSubscriptionInvitation/CancelSharedSubscriptionInvitation'
import { RoleName } from '@standardnotes/common'
import { ListSharedSubscriptionInvitations } from '../Domain/UseCase/ListSharedSubscriptionInvitations/ListSharedSubscriptionInvitations'
import { ApiVersion } from '@standardnotes/api'
describe('SubscriptionInvitesController', () => {
let inviteToSharedSubscription: InviteToSharedSubscription
@@ -19,8 +16,6 @@ describe('SubscriptionInvitesController', () => {
let cancelSharedSubscriptionInvitation: CancelSharedSubscriptionInvitation
let listSharedSubscriptionInvitations: ListSharedSubscriptionInvitations
let request: express.Request
let response: express.Response
let user: User
const createController = () =>
@@ -51,25 +46,6 @@ describe('SubscriptionInvitesController', () => {
listSharedSubscriptionInvitations = {} as jest.Mocked<ListSharedSubscriptionInvitations>
listSharedSubscriptionInvitations.execute = jest.fn()
request = {
headers: {},
body: {},
params: {},
} as jest.Mocked<express.Request>
response = {
locals: {},
} as jest.Mocked<express.Response>
response.locals.user = {
email: 'test@test.te',
}
response.locals.roles = [
{
uuid: '1-2-3',
name: RoleName.CoreUser,
},
]
})
it('should get invitations to subscription sharing', async () => {
@@ -77,128 +53,127 @@ describe('SubscriptionInvitesController', () => {
invitations: [],
})
const httpResponse = <results.JsonResult>await createController().listInvites(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().listInvites({ api: ApiVersion.v0, inviterEmail: 'test@test.te' })
expect(listSharedSubscriptionInvitations.execute).toHaveBeenCalledWith({
inviterEmail: 'test@test.te',
})
expect(result.statusCode).toEqual(200)
expect(result.status).toEqual(200)
})
it('should cancel invitation to subscription sharing', async () => {
request.params.inviteUuid = '1-2-3'
cancelSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: true,
})
const httpResponse = <results.JsonResult>await createController().cancelSubscriptionSharing(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().cancelInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
inviterEmail: 'test@test.te',
})
expect(cancelSharedSubscriptionInvitation.execute).toHaveBeenCalledWith({
sharedSubscriptionInvitationUuid: '1-2-3',
inviterEmail: 'test@test.te',
})
expect(result.statusCode).toEqual(200)
expect(result.status).toEqual(200)
})
it('should not cancel invitation to subscription sharing if the workflow fails', async () => {
request.params.inviteUuid = '1-2-3'
cancelSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: false,
})
const httpResponse = <results.JsonResult>await createController().cancelSubscriptionSharing(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().cancelInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
})
expect(result.statusCode).toEqual(400)
expect(result.status).toEqual(400)
})
it('should decline invitation to subscription sharing', async () => {
request.params.inviteUuid = '1-2-3'
declineSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: true,
})
const httpResponse = <results.JsonResult>await createController().declineInvite(request)
const result = await httpResponse.executeAsync()
const result = await createController().declineInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
})
expect(declineSharedSubscriptionInvitation.execute).toHaveBeenCalledWith({
sharedSubscriptionInvitationUuid: '1-2-3',
})
expect(result.statusCode).toEqual(200)
expect(result.status).toEqual(200)
})
it('should not decline invitation to subscription sharing if the workflow fails', async () => {
request.params.inviteUuid = '1-2-3'
declineSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: false,
})
const httpResponse = <results.JsonResult>await createController().declineInvite(request)
const result = await httpResponse.executeAsync()
const result = await createController().declineInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
})
expect(declineSharedSubscriptionInvitation.execute).toHaveBeenCalledWith({
sharedSubscriptionInvitationUuid: '1-2-3',
})
expect(result.statusCode).toEqual(400)
expect(result.status).toEqual(400)
})
it('should accept invitation to subscription sharing', async () => {
request.params.inviteUuid = '1-2-3'
acceptSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: true,
})
const httpResponse = <results.JsonResult>await createController().acceptInvite(request)
const result = await httpResponse.executeAsync()
const result = await createController().acceptInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
})
expect(acceptSharedSubscriptionInvitation.execute).toHaveBeenCalledWith({
sharedSubscriptionInvitationUuid: '1-2-3',
})
expect(result.statusCode).toEqual(200)
expect(result.status).toEqual(200)
})
it('should not accept invitation to subscription sharing if the workflow fails', async () => {
request.params.inviteUuid = '1-2-3'
acceptSharedSubscriptionInvitation.execute = jest.fn().mockReturnValue({
success: false,
})
const httpResponse = <results.JsonResult>await createController().acceptInvite(request)
const result = await httpResponse.executeAsync()
const result = await createController().acceptInvite({
api: ApiVersion.v0,
inviteUuid: '1-2-3',
})
expect(acceptSharedSubscriptionInvitation.execute).toHaveBeenCalledWith({
sharedSubscriptionInvitationUuid: '1-2-3',
})
expect(result.statusCode).toEqual(400)
expect(result.status).toEqual(400)
})
it('should invite to user subscription', async () => {
request.body.identifier = 'invitee@test.te'
response.locals.user = {
uuid: '1-2-3',
email: 'test@test.te',
}
inviteToSharedSubscription.execute = jest.fn().mockReturnValue({
success: true,
})
const httpResponse = <results.JsonResult>await createController().inviteToSubscriptionSharing(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().invite({
api: ApiVersion.v0,
identifier: 'invitee@test.te',
inviterUuid: '1-2-3',
inviterEmail: 'test@test.te',
inviterRoles: ['CORE_USER'],
})
expect(inviteToSharedSubscription.execute).toHaveBeenCalledWith({
inviterEmail: 'test@test.te',
@@ -207,37 +182,36 @@ describe('SubscriptionInvitesController', () => {
inviterRoles: ['CORE_USER'],
})
expect(result.statusCode).toEqual(200)
expect(result.status).toEqual(200)
})
it('should not invite to user subscription if the identifier is missing in request', async () => {
response.locals.user = {
uuid: '1-2-3',
email: 'test@test.te',
}
const httpResponse = <results.JsonResult>await createController().inviteToSubscriptionSharing(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().invite({
api: ApiVersion.v0,
identifier: '',
inviterUuid: '1-2-3',
inviterEmail: 'test@test.te',
inviterRoles: ['CORE_USER'],
})
expect(inviteToSharedSubscription.execute).not.toHaveBeenCalled()
expect(result.statusCode).toEqual(400)
expect(result.status).toEqual(400)
})
it('should not invite to user subscription if the workflow does not run', async () => {
request.body.identifier = 'invitee@test.te'
response.locals.user = {
uuid: '1-2-3',
email: 'test@test.te',
}
inviteToSharedSubscription.execute = jest.fn().mockReturnValue({
success: false,
})
const httpResponse = <results.JsonResult>await createController().inviteToSubscriptionSharing(request, response)
const result = await httpResponse.executeAsync()
const result = await createController().invite({
api: ApiVersion.v0,
identifier: 'invitee@test.te',
inviterUuid: '1-2-3',
inviterEmail: 'test@test.te',
inviterRoles: ['CORE_USER'],
})
expect(result.statusCode).toEqual(400)
expect(result.status).toEqual(400)
})
})

View File

@@ -1,15 +1,19 @@
import { Role } from '@standardnotes/security'
import { Request, Response } from 'express'
import { inject } from 'inversify'
import {
BaseHttpController,
controller,
httpDelete,
httpGet,
httpPost,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
results,
} from 'inversify-express-utils'
HttpStatusCode,
SubscriptionInviteAcceptRequestParams,
SubscriptionInviteAcceptResponse,
SubscriptionInviteCancelRequestParams,
SubscriptionInviteCancelResponse,
SubscriptionInviteDeclineRequestParams,
SubscriptionInviteDeclineResponse,
SubscriptionInviteListRequestParams,
SubscriptionInviteListResponse,
SubscriptionInviteRequestParams,
SubscriptionInviteResponse,
SubscriptionServerInterface,
} from '@standardnotes/api'
import { RoleName } from '@standardnotes/common'
import { inject, injectable } from 'inversify'
import TYPES from '../Bootstrap/Types'
import { AcceptSharedSubscriptionInvitation } from '../Domain/UseCase/AcceptSharedSubscriptionInvitation/AcceptSharedSubscriptionInvitation'
@@ -18,8 +22,8 @@ import { DeclineSharedSubscriptionInvitation } from '../Domain/UseCase/DeclineSh
import { InviteToSharedSubscription } from '../Domain/UseCase/InviteToSharedSubscription/InviteToSharedSubscription'
import { ListSharedSubscriptionInvitations } from '../Domain/UseCase/ListSharedSubscriptionInvitations/ListSharedSubscriptionInvitations'
@controller('/subscription-invites')
export class SubscriptionInvitesController extends BaseHttpController {
@injectable()
export class SubscriptionInvitesController implements SubscriptionServerInterface {
constructor(
@inject(TYPES.InviteToSharedSubscription) private inviteToSharedSubscription: InviteToSharedSubscription,
@inject(TYPES.AcceptSharedSubscriptionInvitation)
@@ -30,75 +34,103 @@ export class SubscriptionInvitesController extends BaseHttpController {
private cancelSharedSubscriptionInvitation: CancelSharedSubscriptionInvitation,
@inject(TYPES.ListSharedSubscriptionInvitations)
private listSharedSubscriptionInvitations: ListSharedSubscriptionInvitations,
) {
super()
}
) {}
@httpGet('/:inviteUuid/accept')
async acceptInvite(request: Request): Promise<results.JsonResult> {
async acceptInvite(params: SubscriptionInviteAcceptRequestParams): Promise<SubscriptionInviteAcceptResponse> {
const result = await this.acceptSharedSubscriptionInvitation.execute({
sharedSubscriptionInvitationUuid: request.params.inviteUuid,
sharedSubscriptionInvitationUuid: params.inviteUuid,
})
if (result.success) {
return this.json(result)
return {
status: HttpStatusCode.Success,
data: result,
}
}
return this.json(result, 400)
return {
status: HttpStatusCode.BadRequest,
data: result,
}
}
@httpGet('/:inviteUuid/decline')
async declineInvite(request: Request): Promise<results.JsonResult> {
async declineInvite(params: SubscriptionInviteDeclineRequestParams): Promise<SubscriptionInviteDeclineResponse> {
const result = await this.declineSharedSubscriptionInvitation.execute({
sharedSubscriptionInvitationUuid: request.params.inviteUuid,
sharedSubscriptionInvitationUuid: params.inviteUuid,
})
if (result.success) {
return this.json(result)
return {
status: HttpStatusCode.Success,
data: result,
}
}
return this.json(result, 400)
return {
status: HttpStatusCode.BadRequest,
data: result,
}
}
@httpPost('/', TYPES.ApiGatewayAuthMiddleware)
async inviteToSubscriptionSharing(request: Request, response: Response): Promise<results.JsonResult> {
if (!request.body.identifier) {
return this.json({ error: { message: 'Missing invitee identifier' } }, 400)
async invite(params: SubscriptionInviteRequestParams): Promise<SubscriptionInviteResponse> {
if (!params.identifier) {
return {
status: HttpStatusCode.BadRequest,
data: {
error: {
message: 'Missing invitee identifier',
},
},
}
}
const result = await this.inviteToSharedSubscription.execute({
inviterEmail: response.locals.user.email,
inviterUuid: response.locals.user.uuid,
inviteeIdentifier: request.body.identifier,
inviterRoles: response.locals.roles.map((role: Role) => role.name),
inviterEmail: params.inviterEmail as string,
inviterUuid: params.inviterUuid as string,
inviteeIdentifier: params.identifier,
inviterRoles: params.inviterRoles as RoleName[],
})
if (result.success) {
return this.json(result)
return {
status: HttpStatusCode.Success,
data: result,
}
}
return this.json(result, 400)
return {
status: HttpStatusCode.BadRequest,
data: result,
}
}
@httpDelete('/:inviteUuid', TYPES.ApiGatewayAuthMiddleware)
async cancelSubscriptionSharing(request: Request, response: Response): Promise<results.JsonResult> {
async cancelInvite(params: SubscriptionInviteCancelRequestParams): Promise<SubscriptionInviteCancelResponse> {
const result = await this.cancelSharedSubscriptionInvitation.execute({
sharedSubscriptionInvitationUuid: request.params.inviteUuid,
inviterEmail: response.locals.user.email,
sharedSubscriptionInvitationUuid: params.inviteUuid,
inviterEmail: params.inviterEmail as string,
})
if (result.success) {
return this.json(result)
return {
status: HttpStatusCode.Success,
data: result,
}
}
return this.json(result, 400)
return {
status: HttpStatusCode.BadRequest,
data: result,
}
}
@httpGet('/', TYPES.ApiGatewayAuthMiddleware)
async listInvites(_request: Request, response: Response): Promise<results.JsonResult> {
async listInvites(params: SubscriptionInviteListRequestParams): Promise<SubscriptionInviteListResponse> {
const result = await this.listSharedSubscriptionInvitations.execute({
inviterEmail: response.locals.user.email,
inviterEmail: params.inviterEmail as string,
})
return this.json(result)
return {
status: HttpStatusCode.Success,
data: result,
}
}
}

View File

@@ -12,6 +12,7 @@ import { CreateValetTokenPayload } from '@standardnotes/responses'
import TYPES from '../Bootstrap/Types'
import { CreateValetToken } from '../Domain/UseCase/CreateValetToken/CreateValetToken'
import { ErrorTag } from '@standardnotes/common'
import { ValetTokenOperation } from '@standardnotes/security'
@controller('/valet-tokens', TYPES.ApiGatewayAuthMiddleware)
export class ValetTokenController extends BaseHttpController {
@@ -37,7 +38,7 @@ export class ValetTokenController extends BaseHttpController {
const createValetKeyResponse = await this.createValetKey.execute({
userUuid: response.locals.user.uuid,
operation: payload.operation,
operation: payload.operation as ValetTokenOperation,
resources: payload.resources,
})

View File

@@ -13,7 +13,6 @@ import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyti
import { UserRepositoryInterface } from '../User/UserRepositoryInterface'
import { User } from '../User/User'
import { UserSubscription } from '../Subscription/UserSubscription'
import { Logger } from 'winston'
describe('SubscriptionCancelledEventHandler', () => {
let userSubscriptionRepository: UserSubscriptionRepositoryInterface
@@ -24,7 +23,6 @@ describe('SubscriptionCancelledEventHandler', () => {
let analyticsStore: AnalyticsStoreInterface
let statisticsStore: StatisticsStoreInterface
let timestamp: number
let logger: Logger
const createHandler = () =>
new SubscriptionCancelledEventHandler(
@@ -34,7 +32,6 @@ describe('SubscriptionCancelledEventHandler', () => {
getUserAnalyticsId,
analyticsStore,
statisticsStore,
logger,
)
beforeEach(() => {
@@ -75,9 +72,6 @@ describe('SubscriptionCancelledEventHandler', () => {
offline: false,
replaced: false,
}
logger = {} as jest.Mocked<Logger>
logger.info = jest.fn()
})
it('should update subscription cancelled', async () => {

View File

@@ -14,7 +14,6 @@ import { OfflineUserSubscriptionRepositoryInterface } from '../Subscription/Offl
import { UserRepositoryInterface } from '../User/UserRepositoryInterface'
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
import { UserSubscription } from '../Subscription/UserSubscription'
import { Logger } from 'winston'
@injectable()
export class SubscriptionCancelledEventHandler implements DomainEventHandlerInterface {
@@ -26,17 +25,8 @@ export class SubscriptionCancelledEventHandler implements DomainEventHandlerInte
@inject(TYPES.GetUserAnalyticsId) private getUserAnalyticsId: GetUserAnalyticsId,
@inject(TYPES.AnalyticsStore) private analyticsStore: AnalyticsStoreInterface,
@inject(TYPES.StatisticsStore) private statisticsStore: StatisticsStoreInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
async handle(event: SubscriptionCancelledEvent): Promise<void> {
if (event.payload.offline) {
await this.updateOfflineSubscriptionCancelled(event.payload.subscriptionId, event.payload.timestamp)
return
}
await this.updateSubscriptionCancelled(event.payload.subscriptionId, event.payload.timestamp)
const user = await this.userRepository.findOneByEmail(event.payload.userEmail)
if (user !== null) {
const { analyticsId } = await this.getUserAnalyticsId.execute({ userUuid: user.uuid })
@@ -50,16 +40,33 @@ export class SubscriptionCancelledEventHandler implements DomainEventHandlerInte
if (subscriptions.length !== 0) {
const lastSubscription = subscriptions.shift() as UserSubscription
const subscriptionLength = event.payload.timestamp - lastSubscription.createdAt
this.logger.info(
`Canceling subscription ${lastSubscription.uuid} - lasted for ${subscriptionLength} microseconds`,
)
await this.statisticsStore.incrementMeasure(StatisticsMeasure.SubscriptionLength, subscriptionLength, [
Period.Today,
Period.ThisWeek,
Period.ThisMonth,
])
const lastPurchaseTime = lastSubscription.renewedAt ?? lastSubscription.updatedAt
const remainingSubscriptionTime = lastSubscription.endsAt - event.payload.timestamp
const totalSubscriptionTime = lastSubscription.endsAt - lastPurchaseTime
const remainingSubscriptionPercentage = Math.floor((remainingSubscriptionTime / totalSubscriptionTime) * 100)
await this.statisticsStore.incrementMeasure(
StatisticsMeasure.RemainingSubscriptionTimePercentage,
remainingSubscriptionPercentage,
[Period.Today, Period.ThisWeek, Period.ThisMonth],
)
}
}
if (event.payload.offline) {
await this.updateOfflineSubscriptionCancelled(event.payload.subscriptionId, event.payload.timestamp)
return
}
await this.updateSubscriptionCancelled(event.payload.subscriptionId, event.payload.timestamp)
}
private async updateSubscriptionCancelled(subscriptionId: number, timestamp: number): Promise<void> {

View File

@@ -16,9 +16,10 @@ import { OfflineUserSubscriptionRepositoryInterface } from '../Subscription/Offl
import { OfflineUserSubscription } from '../Subscription/OfflineUserSubscription'
import { SubscriptionSettingServiceInterface } from '../Setting/SubscriptionSettingServiceInterface'
import { UserSubscriptionType } from '../Subscription/UserSubscriptionType'
import { AnalyticsStoreInterface, Period } from '@standardnotes/analytics'
import { AnalyticsStoreInterface, Period, StatisticsStoreInterface } from '@standardnotes/analytics'
import { AnalyticsEntity } from '../Analytics/AnalyticsEntity'
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
import { TimerInterface } from '@standardnotes/time'
describe('SubscriptionPurchasedEventHandler', () => {
let userRepository: UserRepositoryInterface
@@ -35,6 +36,8 @@ describe('SubscriptionPurchasedEventHandler', () => {
let getUserAnalyticsId: GetUserAnalyticsId
let analyticsStore: AnalyticsStoreInterface
let timestamp: number
let statisticsStore: StatisticsStoreInterface
let timer: TimerInterface
const createHandler = () =>
new SubscriptionPurchasedEventHandler(
@@ -45,6 +48,8 @@ describe('SubscriptionPurchasedEventHandler', () => {
subscriptionSettingService,
getUserAnalyticsId,
analyticsStore,
statisticsStore,
timer,
logger,
)
@@ -66,7 +71,14 @@ describe('SubscriptionPurchasedEventHandler', () => {
userRepository.findOneByEmail = jest.fn().mockReturnValue(user)
userRepository.save = jest.fn().mockReturnValue(user)
statisticsStore = {} as jest.Mocked<StatisticsStoreInterface>
statisticsStore.incrementMeasure = jest.fn()
timer = {} as jest.Mocked<TimerInterface>
timer.convertDateToMicroseconds = jest.fn().mockReturnValue(1)
userSubscriptionRepository = {} as jest.Mocked<UserSubscriptionRepositoryInterface>
userSubscriptionRepository.countByUserUuid = jest.fn().mockReturnValue(0)
userSubscriptionRepository.save = jest.fn().mockReturnValue(subscription)
offlineUserSubscription = {} as jest.Mocked<OfflineUserSubscription>
@@ -146,6 +158,15 @@ describe('SubscriptionPurchasedEventHandler', () => {
updatedAt: expect.any(Number),
cancelled: false,
})
expect(statisticsStore.incrementMeasure).toHaveBeenCalled()
})
it("should not measure registration to subscription time if this is not user's first subscription", async () => {
userSubscriptionRepository.countByUserUuid = jest.fn().mockReturnValue(1)
await createHandler().handle(event)
expect(statisticsStore.incrementMeasure).not.toHaveBeenCalled()
})
it('should update analytics on limited discount offer purchasing', async () => {

View File

@@ -13,8 +13,15 @@ import { OfflineUserSubscription } from '../Subscription/OfflineUserSubscription
import { OfflineUserSubscriptionRepositoryInterface } from '../Subscription/OfflineUserSubscriptionRepositoryInterface'
import { UserSubscriptionType } from '../Subscription/UserSubscriptionType'
import { SubscriptionSettingServiceInterface } from '../Setting/SubscriptionSettingServiceInterface'
import { AnalyticsActivity, AnalyticsStoreInterface, Period } from '@standardnotes/analytics'
import {
AnalyticsActivity,
AnalyticsStoreInterface,
Period,
StatisticsMeasure,
StatisticsStoreInterface,
} from '@standardnotes/analytics'
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
import { TimerInterface } from '@standardnotes/time'
@injectable()
export class SubscriptionPurchasedEventHandler implements DomainEventHandlerInterface {
@@ -27,6 +34,8 @@ export class SubscriptionPurchasedEventHandler implements DomainEventHandlerInte
@inject(TYPES.SubscriptionSettingService) private subscriptionSettingService: SubscriptionSettingServiceInterface,
@inject(TYPES.GetUserAnalyticsId) private getUserAnalyticsId: GetUserAnalyticsId,
@inject(TYPES.AnalyticsStore) private analyticsStore: AnalyticsStoreInterface,
@inject(TYPES.StatisticsStore) private statisticsStore: StatisticsStoreInterface,
@inject(TYPES.Timer) private timer: TimerInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
@@ -52,6 +61,8 @@ export class SubscriptionPurchasedEventHandler implements DomainEventHandlerInte
return
}
const previousSubscriptionCount = await this.userSubscriptionRepository.countByUserUuid(user.uuid)
const userSubscription = await this.createSubscription(
event.payload.subscriptionId,
event.payload.subscriptionName,
@@ -80,6 +91,14 @@ export class SubscriptionPurchasedEventHandler implements DomainEventHandlerInte
Period.Today,
])
}
if (previousSubscriptionCount === 0) {
await this.statisticsStore.incrementMeasure(
StatisticsMeasure.RegistrationToSubscriptionTime,
event.payload.timestamp - this.timer.convertDateToMicroseconds(user.createdAt),
[Period.Today, Period.ThisWeek, Period.ThisMonth],
)
}
}
private async addUserRole(user: User, subscriptionName: SubscriptionName): Promise<void> {

View File

@@ -7,5 +7,9 @@ export interface SharedSubscriptionInvitationRepositoryInterface {
findOneByUuidAndStatus(uuid: Uuid, status: InvitationStatus): Promise<SharedSubscriptionInvitation | null>
findOneByUuid(uuid: Uuid): Promise<SharedSubscriptionInvitation | null>
findByInviterEmail(inviterEmail: string): Promise<SharedSubscriptionInvitation[]>
findOneByInviteeAndInviterEmail(
inviteeEmail: string,
inviterEmail: string,
): Promise<SharedSubscriptionInvitation | null>
countByInviterEmailAndStatus(inviterEmail: Uuid, statuses: InvitationStatus[]): Promise<number>
}

View File

@@ -34,6 +34,13 @@ export class UserSubscription {
@Index('updated_at')
declare updatedAt: number
@Column({
name: 'renewed_at',
type: 'bigint',
nullable: true,
})
declare renewedAt: number | null
@Column({
type: 'tinyint',
width: 1,

View File

@@ -4,6 +4,7 @@ import { UserSubscriptionType } from './UserSubscriptionType'
export interface UserSubscriptionRepositoryInterface {
findOneByUuid(uuid: Uuid): Promise<UserSubscription | null>
countByUserUuid(userUuid: Uuid): Promise<number>
findOneByUserUuid(userUuid: Uuid): Promise<UserSubscription | null>
findOneByUserUuidAndSubscriptionId(userUuid: Uuid, subscriptionId: number): Promise<UserSubscription | null>
findBySubscriptionIdAndType(subscriptionId: number, type: UserSubscriptionType): Promise<UserSubscription[]>

View File

@@ -16,6 +16,7 @@ import { DomainEventPublisherInterface, SharedSubscriptionInvitationCanceledEven
import { DomainEventFactoryInterface } from '../../Event/DomainEventFactoryInterface'
import { InviterIdentifierType } from '../../SharedSubscription/InviterIdentifierType'
import { InviteeIdentifierType } from '../../SharedSubscription/InviteeIdentifierType'
import { Logger } from 'winston'
describe('CancelSharedSubscriptionInvitation', () => {
let sharedSubscriptionInvitationRepository: SharedSubscriptionInvitationRepositoryInterface
@@ -28,6 +29,7 @@ describe('CancelSharedSubscriptionInvitation', () => {
let invitation: SharedSubscriptionInvitation
let domainEventPublisher: DomainEventPublisherInterface
let domainEventFactory: DomainEventFactoryInterface
let logger: Logger
const createUseCase = () =>
new CancelSharedSubscriptionInvitation(
@@ -38,6 +40,7 @@ describe('CancelSharedSubscriptionInvitation', () => {
domainEventPublisher,
domainEventFactory,
timer,
logger,
)
beforeEach(() => {
@@ -60,6 +63,9 @@ describe('CancelSharedSubscriptionInvitation', () => {
inviteeIdentifierType: InviteeIdentifierType.Email,
} as jest.Mocked<SharedSubscriptionInvitation>
logger = {} as jest.Mocked<Logger>
logger.debug = jest.fn()
sharedSubscriptionInvitationRepository = {} as jest.Mocked<SharedSubscriptionInvitationRepositoryInterface>
sharedSubscriptionInvitationRepository.findOneByUuid = jest.fn().mockReturnValue(invitation)
sharedSubscriptionInvitationRepository.save = jest.fn()
@@ -126,7 +132,7 @@ describe('CancelSharedSubscriptionInvitation', () => {
})
})
it('should cancel a shared subscription invitation without subscription removal is subscription is not found', async () => {
it('should cancel a shared subscription invitation without subscription removal if subscription is not found', async () => {
userSubscriptionRepository.findOneByUserUuidAndSubscriptionId = jest.fn().mockReturnValue(null)
expect(
@@ -175,7 +181,7 @@ describe('CancelSharedSubscriptionInvitation', () => {
})
})
it('should not cancel a shared subscription invitation if invitee is not found', async () => {
it('should cancel a shared subscription invitation without subscription removal if invitee is not found', async () => {
userRepository.findOneByEmail = jest.fn().mockReturnValue(null)
expect(
await createUseCase().execute({
@@ -183,20 +189,21 @@ describe('CancelSharedSubscriptionInvitation', () => {
inviterEmail: 'test@test.te',
}),
).toEqual({
success: false,
success: true,
})
})
it('should not cancel a shared subscription invitation if invitee is not found', async () => {
userRepository.findOneByEmail = jest.fn().mockReturnValue(null)
expect(
await createUseCase().execute({
sharedSubscriptionInvitationUuid: '1-2-3',
inviterEmail: 'test@test.te',
}),
).toEqual({
success: false,
expect(sharedSubscriptionInvitationRepository.save).toHaveBeenCalledWith({
status: 'canceled',
subscriptionId: 3,
updatedAt: 1,
inviterIdentifier: 'test@test.te',
uuid: '1-2-3',
inviterIdentifierType: 'email',
inviteeIdentifier: 'invitee@test.te',
inviteeIdentifierType: 'email',
})
expect(userSubscriptionRepository.save).not.toHaveBeenCalled()
expect(roleService.removeUserRole).not.toHaveBeenCalled()
})
it('should not cancel a shared subscription invitation if inviter subscription is not found', async () => {

View File

@@ -2,6 +2,7 @@ import { SubscriptionName } from '@standardnotes/common'
import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
import { TimerInterface } from '@standardnotes/time'
import { inject, injectable } from 'inversify'
import { Logger } from 'winston'
import TYPES from '../../../Bootstrap/Types'
import { DomainEventFactoryInterface } from '../../Event/DomainEventFactoryInterface'
@@ -29,6 +30,7 @@ export class CancelSharedSubscriptionInvitation implements UseCaseInterface {
@inject(TYPES.DomainEventPublisher) private domainEventPublisher: DomainEventPublisherInterface,
@inject(TYPES.DomainEventFactory) private domainEventFactory: DomainEventFactoryInterface,
@inject(TYPES.Timer) private timer: TimerInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
async execute(dto: CancelSharedSubscriptionInvitationDTO): Promise<CancelSharedSubscriptionInvitationResponse> {
@@ -36,29 +38,34 @@ export class CancelSharedSubscriptionInvitation implements UseCaseInterface {
dto.sharedSubscriptionInvitationUuid,
)
if (sharedSubscriptionInvitation === null) {
this.logger.debug(
`Could not find a shared subscription invitation with uuid ${dto.sharedSubscriptionInvitationUuid}`,
)
return {
success: false,
}
}
if (dto.inviterEmail !== sharedSubscriptionInvitation.inviterIdentifier) {
this.logger.debug(
`Subscription belongs to a different inviter (${sharedSubscriptionInvitation.inviterIdentifier}). Modifier: ${dto.inviterEmail}`,
)
return {
success: false,
}
}
const invitee = await this.userRepository.findOneByEmail(sharedSubscriptionInvitation.inviteeIdentifier)
if (invitee === null) {
return {
success: false,
}
}
const inviterUserSubscriptions = await this.userSubscriptionRepository.findBySubscriptionIdAndType(
sharedSubscriptionInvitation.subscriptionId,
UserSubscriptionType.Regular,
)
if (inviterUserSubscriptions.length !== 1) {
if (inviterUserSubscriptions.length === 0) {
this.logger.debug(`Could not find a regular subscription with id ${sharedSubscriptionInvitation.subscriptionId}`)
return {
success: false,
}
@@ -70,20 +77,22 @@ export class CancelSharedSubscriptionInvitation implements UseCaseInterface {
await this.sharedSubscriptionInvitationRepository.save(sharedSubscriptionInvitation)
await this.removeSharedSubscription(sharedSubscriptionInvitation.subscriptionId, invitee)
if (invitee !== null) {
await this.removeSharedSubscription(sharedSubscriptionInvitation.subscriptionId, invitee)
await this.roleService.removeUserRole(invitee, inviterUserSubscription.planName as SubscriptionName)
await this.roleService.removeUserRole(invitee, inviterUserSubscription.planName as SubscriptionName)
await this.domainEventPublisher.publish(
this.domainEventFactory.createSharedSubscriptionInvitationCanceledEvent({
inviteeIdentifier: invitee.uuid,
inviteeIdentifierType: InviteeIdentifierType.Uuid,
inviterEmail: sharedSubscriptionInvitation.inviterIdentifier,
inviterSubscriptionId: sharedSubscriptionInvitation.subscriptionId,
inviterSubscriptionUuid: inviterUserSubscription.uuid,
sharedSubscriptionInvitationUuid: sharedSubscriptionInvitation.uuid,
}),
)
await this.domainEventPublisher.publish(
this.domainEventFactory.createSharedSubscriptionInvitationCanceledEvent({
inviteeIdentifier: invitee.uuid,
inviteeIdentifierType: InviteeIdentifierType.Uuid,
inviterEmail: sharedSubscriptionInvitation.inviterIdentifier,
inviterSubscriptionId: sharedSubscriptionInvitation.subscriptionId,
inviterSubscriptionUuid: inviterUserSubscription.uuid,
sharedSubscriptionInvitationUuid: sharedSubscriptionInvitation.uuid,
}),
)
}
return {
success: true,

View File

@@ -1,6 +1,6 @@
import 'reflect-metadata'
import { TokenEncoderInterface, ValetTokenData } from '@standardnotes/security'
import { TokenEncoderInterface, ValetTokenData, ValetTokenOperation } from '@standardnotes/security'
import { CreateValetToken } from './CreateValetToken'
import { TimerInterface } from '@standardnotes/time'
import { UserSubscription } from '../../Subscription/UserSubscription'
@@ -70,7 +70,7 @@ describe('CreateValetToken', () => {
it('should create a read valet token', async () => {
const response = await createUseCase().execute({
operation: 'read',
operation: ValetTokenOperation.Read,
userUuid: '1-2-3',
resources: [
{
@@ -92,7 +92,7 @@ describe('CreateValetToken', () => {
.mockReturnValue({ regularSubscription: null, sharedSubscription: null })
const response = await createUseCase().execute({
operation: 'read',
operation: ValetTokenOperation.Read,
userUuid: '1-2-3',
resources: [
{
@@ -117,7 +117,7 @@ describe('CreateValetToken', () => {
timer.getTimestampInMicroseconds = jest.fn().mockReturnValue(150)
const response = await createUseCase().execute({
operation: 'read',
operation: ValetTokenOperation.Read,
userUuid: '1-2-3',
resources: [
{
@@ -135,7 +135,7 @@ describe('CreateValetToken', () => {
it('should not create a write valet token if unencrypted file size has not been provided for a resource', async () => {
const response = await createUseCase().execute({
operation: 'write',
operation: ValetTokenOperation.Write,
resources: [
{
remoteIdentifier: '2-3-4',
@@ -152,7 +152,7 @@ describe('CreateValetToken', () => {
it('should create a write valet token', async () => {
const response = await createUseCase().execute({
operation: 'write',
operation: ValetTokenOperation.Write,
resources: [
{
remoteIdentifier: '2-3-4',
@@ -192,7 +192,7 @@ describe('CreateValetToken', () => {
.mockReturnValue({ regularSubscription, sharedSubscription })
const response = await createUseCase().execute({
operation: 'write',
operation: ValetTokenOperation.Write,
resources: [
{
remoteIdentifier: '2-3-4',
@@ -232,7 +232,7 @@ describe('CreateValetToken', () => {
.mockReturnValue({ regularSubscription: null, sharedSubscription })
const response = await createUseCase().execute({
operation: 'write',
operation: ValetTokenOperation.Write,
resources: [
{
remoteIdentifier: '2-3-4',
@@ -252,7 +252,7 @@ describe('CreateValetToken', () => {
subscriptionSettingService.findSubscriptionSettingWithDecryptedValue = jest.fn().mockReturnValue(null)
const response = await createUseCase().execute({
operation: 'write',
operation: ValetTokenOperation.Write,
userUuid: '1-2-3',
resources: [
{

View File

@@ -1,5 +1,10 @@
import { CreateValetTokenPayload } from '@standardnotes/responses'
import { ValetTokenOperation } from '@standardnotes/security'
export type CreateValetTokenDTO = CreateValetTokenPayload & {
export type CreateValetTokenDTO = {
operation: ValetTokenOperation
resources: Array<{
remoteIdentifier: string
unencryptedFileSize?: number
}>
userUuid: string
}

View File

@@ -9,6 +9,8 @@ import { InviteToSharedSubscription } from './InviteToSharedSubscription'
import { UserSubscriptionRepositoryInterface } from '../../Subscription/UserSubscriptionRepositoryInterface'
import { UserSubscription } from '../../Subscription/UserSubscription'
import { RoleName } from '@standardnotes/common'
import { UserSubscriptionType } from '../../Subscription/UserSubscriptionType'
import { SharedSubscriptionInvitation } from '../../SharedSubscription/SharedSubscriptionInvitation'
describe('InviteToSharedSubscription', () => {
let userSubscriptionRepository: UserSubscriptionRepositoryInterface
@@ -28,9 +30,10 @@ describe('InviteToSharedSubscription', () => {
beforeEach(() => {
userSubscriptionRepository = {} as jest.Mocked<UserSubscriptionRepositoryInterface>
userSubscriptionRepository.findOneByUserUuid = jest
.fn()
.mockReturnValue({ subscriptionId: 2 } as jest.Mocked<UserSubscription>)
userSubscriptionRepository.findOneByUserUuid = jest.fn().mockReturnValue({
subscriptionId: 2,
subscriptionType: UserSubscriptionType.Regular,
} as jest.Mocked<UserSubscription>)
timer = {} as jest.Mocked<TimerInterface>
timer.getTimestampInMicroseconds = jest.fn().mockReturnValue(1)
@@ -38,6 +41,7 @@ describe('InviteToSharedSubscription', () => {
sharedSubscriptionInvitationRepository = {} as jest.Mocked<SharedSubscriptionInvitationRepositoryInterface>
sharedSubscriptionInvitationRepository.save = jest.fn().mockImplementation((same) => ({ ...same, uuid: '1-2-3' }))
sharedSubscriptionInvitationRepository.countByInviterEmailAndStatus = jest.fn().mockReturnValue(2)
sharedSubscriptionInvitationRepository.findOneByInviteeAndInviterEmail = jest.fn().mockReturnValue(null)
domainEventPublisher = {} as jest.Mocked<DomainEventPublisherInterface>
domainEventPublisher.publish = jest.fn()
@@ -159,4 +163,46 @@ describe('InviteToSharedSubscription', () => {
})
expect(domainEventPublisher.publish).toHaveBeenCalled()
})
it('should not create an inivitation for sharing the subscription if the inviter is on a shared subscription', async () => {
userSubscriptionRepository.findOneByUserUuid = jest.fn().mockReturnValue({
subscriptionId: 2,
subscriptionType: UserSubscriptionType.Shared,
} as jest.Mocked<UserSubscription>)
await createUseCase().execute({
inviteeIdentifier: 'invitee@test.te',
inviterUuid: '1-2-3',
inviterEmail: 'inviter@test.te',
inviterRoles: [RoleName.ProUser],
})
expect(sharedSubscriptionInvitationRepository.save).not.toHaveBeenCalled()
expect(domainEventFactory.createSharedSubscriptionInvitationCreatedEvent).not.toHaveBeenCalled()
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
})
it('should not create an invitation if it already exists', async () => {
sharedSubscriptionInvitationRepository.findOneByInviteeAndInviterEmail = jest
.fn()
.mockReturnValue({} as jest.Mocked<SharedSubscriptionInvitation>)
expect(
await createUseCase().execute({
inviteeIdentifier: 'invitee@test.te',
inviterUuid: '1-2-3',
inviterEmail: 'inviter@test.te',
inviterRoles: [RoleName.ProUser],
}),
).toEqual({
success: false,
})
expect(sharedSubscriptionInvitationRepository.save).not.toHaveBeenCalled()
expect(domainEventFactory.createSharedSubscriptionInvitationCreatedEvent).not.toHaveBeenCalled()
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
})
})

View File

@@ -11,6 +11,7 @@ import { InviterIdentifierType } from '../../SharedSubscription/InviterIdentifie
import { SharedSubscriptionInvitation } from '../../SharedSubscription/SharedSubscriptionInvitation'
import { SharedSubscriptionInvitationRepositoryInterface } from '../../SharedSubscription/SharedSubscriptionInvitationRepositoryInterface'
import { UserSubscriptionRepositoryInterface } from '../../Subscription/UserSubscriptionRepositoryInterface'
import { UserSubscriptionType } from '../../Subscription/UserSubscriptionType'
import { UseCaseInterface } from '../UseCaseInterface'
import { InviteToSharedSubscriptionDTO } from './InviteToSharedSubscriptionDTO'
@@ -35,6 +36,13 @@ export class InviteToSharedSubscription implements UseCaseInterface {
}
}
const inviterUserSubscription = await this.userSubscriptionRepository.findOneByUserUuid(dto.inviterUuid)
if (inviterUserSubscription === null || inviterUserSubscription.subscriptionType === UserSubscriptionType.Shared) {
return {
success: false,
}
}
const numberOfUsedInvites = await this.sharedSubscriptionInvitationRepository.countByInviterEmailAndStatus(
dto.inviterEmail,
[InvitationStatus.Sent, InvitationStatus.Accepted],
@@ -45,8 +53,11 @@ export class InviteToSharedSubscription implements UseCaseInterface {
}
}
const inviterUserSubscription = await this.userSubscriptionRepository.findOneByUserUuid(dto.inviterUuid)
if (inviterUserSubscription === null) {
const existingInvitation = await this.sharedSubscriptionInvitationRepository.findOneByInviteeAndInviterEmail(
dto.inviteeIdentifier,
dto.inviterEmail,
)
if (existingInvitation !== null) {
return {
success: false,
}

View File

@@ -0,0 +1,77 @@
import { ApiVersion } from '@standardnotes/api'
import { Role } from '@standardnotes/security'
import { Request, Response } from 'express'
import { inject } from 'inversify'
import {
BaseHttpController,
controller,
httpDelete,
httpGet,
httpPost,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
results,
} from 'inversify-express-utils'
import TYPES from '../../Bootstrap/Types'
import { SubscriptionInvitesController } from '../../Controller/SubscriptionInvitesController'
@controller('/subscription-invites')
export class InversifyExpressSubscriptionInvitesController extends BaseHttpController {
constructor(
@inject(TYPES.SubscriptionInvitesController) private subscriptionInvitesController: SubscriptionInvitesController,
) {
super()
}
@httpGet('/:inviteUuid/accept')
async acceptInvite(request: Request): Promise<results.JsonResult> {
const response = await this.subscriptionInvitesController.acceptInvite({
api: request.query.api as ApiVersion,
inviteUuid: request.params.inviteUuid,
})
return this.json(response.data, response.status)
}
@httpGet('/:inviteUuid/decline')
async declineInvite(request: Request): Promise<results.JsonResult> {
const response = await this.subscriptionInvitesController.declineInvite({
api: request.query.api as ApiVersion,
inviteUuid: request.params.inviteUuid,
})
return this.json(response.data, response.status)
}
@httpPost('/', TYPES.ApiGatewayAuthMiddleware)
async inviteToSubscriptionSharing(request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.subscriptionInvitesController.invite({
...request.body,
inviterEmail: response.locals.user.email,
inviterUuid: response.locals.user.uuid,
inviterRoles: response.locals.roles.map((role: Role) => role.name),
})
return this.json(result.data, result.status)
}
@httpDelete('/:inviteUuid', TYPES.ApiGatewayAuthMiddleware)
async cancelSubscriptionSharing(request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.subscriptionInvitesController.cancelInvite({
...request.body,
inviteUuid: request.params.inviteUuid,
inviterEmail: response.locals.user.email,
})
return this.json(result.data, result.status)
}
@httpGet('/', TYPES.ApiGatewayAuthMiddleware)
async listInvites(request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.subscriptionInvitesController.listInvites({
...request.body,
inviterEmail: response.locals.user.email,
})
return this.json(result.data, result.status)
}
}

View File

@@ -70,6 +70,23 @@ describe('MySQLSharedSubscriptionInvitationRepository', () => {
expect(result).toEqual(invitation)
})
it('should find one invitation by invitee and inviter email', async () => {
queryBuilder.where = jest.fn().mockReturnThis()
queryBuilder.getOne = jest.fn().mockReturnValue(invitation)
const result = await createRepository().findOneByInviteeAndInviterEmail('invitee@test.te', 'inviter@test.te')
expect(queryBuilder.where).toHaveBeenCalledWith(
'invitation.inviter_identifier = :inviterEmail AND invitation.invitee_identifier = :inviteeEmail',
{
inviterEmail: 'inviter@test.te',
inviteeEmail: 'invitee@test.te',
},
)
expect(result).toEqual(invitation)
})
it('should find one invitation by uuid', async () => {
queryBuilder.where = jest.fn().mockReturnThis()
queryBuilder.getOne = jest.fn().mockReturnValue(invitation)

View File

@@ -13,6 +13,19 @@ export class MySQLSharedSubscriptionInvitationRepository implements SharedSubscr
private ormRepository: Repository<SharedSubscriptionInvitation>,
) {}
async findOneByInviteeAndInviterEmail(
inviteeEmail: string,
inviterEmail: string,
): Promise<SharedSubscriptionInvitation | null> {
return this.ormRepository
.createQueryBuilder('invitation')
.where('invitation.inviter_identifier = :inviterEmail AND invitation.invitee_identifier = :inviteeEmail', {
inviterEmail,
inviteeEmail,
})
.getOne()
}
async save(sharedSubscriptionInvitation: SharedSubscriptionInvitation): Promise<SharedSubscriptionInvitation> {
return this.ormRepository.save(sharedSubscriptionInvitation)
}

View File

@@ -75,6 +75,21 @@ describe('MySQLUserSubscriptionRepository', () => {
expect(result).toEqual(subscription)
})
it('should count by user uuid', async () => {
ormRepository.createQueryBuilder = jest.fn().mockImplementation(() => selectQueryBuilder)
selectQueryBuilder.where = jest.fn().mockReturnThis()
selectQueryBuilder.getCount = jest.fn().mockReturnValue(2)
const result = await createRepository().countByUserUuid('123')
expect(selectQueryBuilder.where).toHaveBeenCalledWith('user_uuid = :user_uuid', {
user_uuid: '123',
})
expect(selectQueryBuilder.getCount).toHaveBeenCalled()
expect(result).toEqual(2)
})
it('should find one, longest lasting subscription by user uuid if there are no ucanceled ones', async () => {
subscription.cancelled = true
@@ -123,7 +138,8 @@ describe('MySQLUserSubscriptionRepository', () => {
expect(updateQueryBuilder.update).toHaveBeenCalled()
expect(updateQueryBuilder.set).toHaveBeenCalledWith({
updatedAt: expect.any(Number),
updatedAt: 1000,
renewedAt: 1000,
endsAt: 1000,
})
expect(updateQueryBuilder.where).toHaveBeenCalledWith('subscription_id = :subscriptionId', {
@@ -174,6 +190,7 @@ describe('MySQLUserSubscriptionRepository', () => {
ormRepository.createQueryBuilder = jest.fn().mockImplementation(() => selectQueryBuilder)
selectQueryBuilder.where = jest.fn().mockReturnThis()
selectQueryBuilder.orderBy = jest.fn().mockReturnThis()
selectQueryBuilder.getMany = jest.fn().mockReturnValue([subscription])
const result = await createRepository().findBySubscriptionIdAndType(123, UserSubscriptionType.Regular)
@@ -185,6 +202,7 @@ describe('MySQLUserSubscriptionRepository', () => {
type: 'regular',
},
)
expect(selectQueryBuilder.orderBy).toHaveBeenCalledWith('created_at', 'DESC')
expect(selectQueryBuilder.getMany).toHaveBeenCalled()
expect(result).toEqual([subscription])
})

View File

@@ -14,6 +14,15 @@ export class MySQLUserSubscriptionRepository implements UserSubscriptionReposito
private ormRepository: Repository<UserSubscription>,
) {}
async countByUserUuid(userUuid: Uuid): Promise<number> {
return await this.ormRepository
.createQueryBuilder()
.where('user_uuid = :user_uuid', {
user_uuid: userUuid,
})
.getCount()
}
async save(subscription: UserSubscription): Promise<UserSubscription> {
return this.ormRepository.save(subscription)
}
@@ -35,6 +44,7 @@ export class MySQLUserSubscriptionRepository implements UserSubscriptionReposito
subscriptionId,
type,
})
.orderBy('created_at', 'DESC')
.getMany()
}
@@ -78,13 +88,14 @@ export class MySQLUserSubscriptionRepository implements UserSubscriptionReposito
return null
}
async updateEndsAt(subscriptionId: number, endsAt: number, updatedAt: number): Promise<void> {
async updateEndsAt(subscriptionId: number, endsAt: number, timestamp: number): Promise<void> {
await this.ormRepository
.createQueryBuilder()
.update()
.set({
endsAt,
updatedAt,
updatedAt: timestamp,
renewedAt: timestamp,
})
.where('subscription_id = :subscriptionId', {
subscriptionId,

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.32.0](https://github.com/standardnotes/server/compare/@standardnotes/common@1.31.0...@standardnotes/common@1.32.0) (2022-09-09)
### Features
* **common:** add either and only types ([c3ebb32](https://github.com/standardnotes/server/commit/c3ebb321cfacd20769ebfd99413e283859b6e260))
# [1.31.0](https://github.com/standardnotes/server/compare/@standardnotes/common@1.30.0...@standardnotes/common@1.31.0) (2022-09-05)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/common",
"version": "1.31.0",
"version": "1.32.0",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -0,0 +1,3 @@
import { Only } from './Only'
export type Either<T, U> = Only<T, U> | Only<U, T>

View File

@@ -0,0 +1,5 @@
export type Only<T, U> = {
[P in keyof T]: T[P]
} & {
[P in keyof U]?: never
}

View File

@@ -18,3 +18,5 @@ export * from './Protocol/ProtocolVersion'
export * from './Role/PaidRoles'
export * from './Role/RoleName'
export * from './Subscription/SubscriptionName'
export * from './Type/Either'
export * from './Type/Only'

View File

@@ -3,6 +3,38 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.8.10](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.9...@standardnotes/domain-events-infra@1.8.10) (2022-09-16)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.9](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.8...@standardnotes/domain-events-infra@1.8.9) (2022-09-09)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.8](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.7...@standardnotes/domain-events-infra@1.8.8) (2022-09-08)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.7](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.6...@standardnotes/domain-events-infra@1.8.7) (2022-09-08)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.6](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.5...@standardnotes/domain-events-infra@1.8.6) (2022-09-08)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.5](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.4...@standardnotes/domain-events-infra@1.8.5) (2022-09-08)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.4](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.3...@standardnotes/domain-events-infra@1.8.4) (2022-09-08)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.2...@standardnotes/domain-events-infra@1.8.3) (2022-09-06)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.1...@standardnotes/domain-events-infra@1.8.2) (2022-09-06)
**Note:** Version bump only for package @standardnotes/domain-events-infra

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events-infra",
"version": "1.8.2",
"version": "1.8.10",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,51 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.60.4](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.60.3...@standardnotes/domain-events@2.60.4) (2022-09-16)
**Note:** Version bump only for package @standardnotes/domain-events
## [2.60.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.60.2...@standardnotes/domain-events@2.60.3) (2022-09-09)
**Note:** Version bump only for package @standardnotes/domain-events
## [2.60.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.60.1...@standardnotes/domain-events@2.60.2) (2022-09-08)
### Bug Fixes
* **api-gateway:** retention data structure to include both period keys ([50ddb91](https://github.com/standardnotes/server/commit/50ddb918ccc52bee4caad82504cb899bc5936150))
## [2.60.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.60.0...@standardnotes/domain-events@2.60.1) (2022-09-08)
### Bug Fixes
* **api-gateway:** retention data structure ([47be084](https://github.com/standardnotes/server/commit/47be0841fc6d5fa00892e775bb3a40f404a6382b))
# [2.60.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.59.3...@standardnotes/domain-events@2.60.0) (2022-09-08)
### Features
* **api-gateway:** add registration-to-activity retention analytics to report ([f139bb0](https://github.com/standardnotes/server/commit/f139bb003669bb41f98ad4bb59a036c489f43606))
## [2.59.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.59.2...@standardnotes/domain-events@2.59.3) (2022-09-08)
### Reverts
* Revert "fix(domain-events): add boolean for sending emails on refund processed" ([fe4821d](https://github.com/standardnotes/server/commit/fe4821d4f7df38297cb92314b9cd3fde3d2c58b6))
## [2.59.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.59.1...@standardnotes/domain-events@2.59.2) (2022-09-08)
### Bug Fixes
* **domain-events:** add boolean for sending emails on refund processed ([d7e6758](https://github.com/standardnotes/server/commit/d7e6758089c5e9485fda345949ec8d58732afa90))
## [2.59.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.59.0...@standardnotes/domain-events@2.59.1) (2022-09-06)
### Bug Fixes
* **api-gateway:** include period key in statistics measures ([d149f46](https://github.com/standardnotes/server/commit/d149f46cf6456201dd8690977f64ed32a75f3459))
* **api-gateway:** period types on analytics report ([f94c8fc](https://github.com/standardnotes/server/commit/f94c8fc26e684a07101cc5282ebb9cda3c8c6961))
# [2.59.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.58.0...@standardnotes/domain-events@2.59.0) (2022-09-06)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events",
"version": "2.59.0",
"version": "2.60.4",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -16,6 +16,7 @@ export interface DailyAnalyticsReportGeneratedEventPayload {
name: string
totalValue: number
average: number
period: number
}>
activityStatisticsOverTime: Array<{
name: string
@@ -27,4 +28,16 @@ export interface DailyAnalyticsReportGeneratedEventPayload {
totalCount: number
}>
outOfSyncIncidents: number
retentionStatistics: Array<{
firstActivity: string
secondActivity: string
retention: {
periodKeys: Array<string>
values: Array<{
firstPeriodKey: string
secondPeriodKey: string
value: number
}>
}
}>
}

View File

@@ -3,6 +3,50 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.3.15](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.14...@standardnotes/event-store@1.3.15) (2022-09-16)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.14](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.13...@standardnotes/event-store@1.3.14) (2022-09-09)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.13](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.12...@standardnotes/event-store@1.3.13) (2022-09-09)
### Bug Fixes
* **event-store:** add missing event subscriptions ([432d071](https://github.com/standardnotes/server/commit/432d071ec88a49f90513be6c55a06005a471b174))
## [1.3.12](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.11...@standardnotes/event-store@1.3.12) (2022-09-08)
### Bug Fixes
* **event-store:** add listening to refund processed event ([73e1ea7](https://github.com/standardnotes/server/commit/73e1ea7f93b7d7956dd4a82298098e81ff9c85b1))
## [1.3.11](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.10...@standardnotes/event-store@1.3.11) (2022-09-08)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.10](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.9...@standardnotes/event-store@1.3.10) (2022-09-08)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.9](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.8...@standardnotes/event-store@1.3.9) (2022-09-08)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.8](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.7...@standardnotes/event-store@1.3.8) (2022-09-08)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.7](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.6...@standardnotes/event-store@1.3.7) (2022-09-08)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.6](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.5...@standardnotes/event-store@1.3.6) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.5](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.4...@standardnotes/event-store@1.3.5) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/event-store",
"version": "1.3.5",
"version": "1.3.15",
"description": "Event Store Service",
"private": true,
"main": "dist/src/index.js",

View File

@@ -80,6 +80,12 @@ export class ContainerConfigLoader {
['PAYMENT_SUCCESS', container.get(TYPES.EventHandler)],
['ACCOUNT_CLAIM_REQUESTED', container.get(TYPES.EventHandler)],
['SUBSCRIPTION_REVERT_REQUESTED', container.get(TYPES.EventHandler)],
['REFUND_PROCESSED', container.get(TYPES.EventHandler)],
['ACCOUNT_RESET_REQUESTED', container.get(TYPES.EventHandler)],
['DISCOUNT_APPLIED', container.get(TYPES.EventHandler)],
['SUBSCRIPTION_RATE_ADJUSTED', container.get(TYPES.EventHandler)],
['REFUND_REQUESTED', container.get(TYPES.EventHandler)],
['INVOICE_GENERATED', container.get(TYPES.EventHandler)],
])
container

View File

@@ -3,6 +3,40 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.5.52](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.51...@standardnotes/files-server@1.5.52) (2022-09-16)
### Bug Fixes
* **files:** add verifying permitted operation on valet token ([377d32c](https://github.com/standardnotes/files/commit/377d32c4498305f0f59ff59e7357f0d2f10ce3a2))
## [1.5.51](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.50...@standardnotes/files-server@1.5.51) (2022-09-09)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.50](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.49...@standardnotes/files-server@1.5.50) (2022-09-08)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.49](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.48...@standardnotes/files-server@1.5.49) (2022-09-08)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.48](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.47...@standardnotes/files-server@1.5.48) (2022-09-08)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.47](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.46...@standardnotes/files-server@1.5.47) (2022-09-08)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.46](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.45...@standardnotes/files-server@1.5.46) (2022-09-08)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.45](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.44...@standardnotes/files-server@1.5.45) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.44](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.43...@standardnotes/files-server@1.5.44) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/files-server",
"version": "1.5.44",
"version": "1.5.52",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -11,6 +11,8 @@ import { FilesController } from './FilesController'
import { GetFileMetadata } from '../Domain/UseCase/GetFileMetadata/GetFileMetadata'
import { results } from 'inversify-express-utils'
import { RemoveFile } from '../Domain/UseCase/RemoveFile/RemoveFile'
import { ValetTokenOperation } from '@standardnotes/security'
import { BadRequestErrorMessageResult } from 'inversify-express-utils/lib/results'
describe('FilesController', () => {
let uploadFileChunk: UploadFileChunk
@@ -75,6 +77,8 @@ describe('FilesController', () => {
})
it('should return a writable stream upon file download', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['range'] = 'bytes=0-'
const result = (await createController().download(request, response)) as () => Writable
@@ -89,7 +93,19 @@ describe('FilesController', () => {
expect(result()).toBeInstanceOf(Writable)
})
it('should not allow download on invalid operation in the valet token', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
request.headers['range'] = 'bytes=0-'
const result = await createController().download(request, response)
expect(result).toBeInstanceOf(BadRequestErrorMessageResult)
})
it('should return proper byte range on consecutive calls', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['range'] = 'bytes=0-'
;(await createController().download(request, response)) as () => Writable
@@ -112,6 +128,8 @@ describe('FilesController', () => {
})
it('should return a writable stream with custom chunk size', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['x-chunk-size'] = '50000'
request.headers['range'] = 'bytes=0-'
@@ -128,6 +146,8 @@ describe('FilesController', () => {
})
it('should default to maximum chunk size if custom chunk size is too large', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['x-chunk-size'] = '200000'
request.headers['range'] = 'bytes=0-'
@@ -144,12 +164,16 @@ describe('FilesController', () => {
})
it('should not return a writable stream if bytes range is not provided', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
const httpResponse = await createController().download(request, response)
expect(httpResponse).toBeInstanceOf(results.BadRequestErrorMessageResult)
})
it('should not return a writable stream if getting file metadata fails', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['range'] = 'bytes=0-'
getFileMetadata.execute = jest.fn().mockReturnValue({ success: false, message: 'error' })
@@ -160,6 +184,8 @@ describe('FilesController', () => {
})
it('should not return a writable stream if creating download stream fails', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
request.headers['range'] = 'bytes=0-'
streamDownloadFile.execute = jest.fn().mockReturnValue({ success: false, message: 'error' })
@@ -170,6 +196,8 @@ describe('FilesController', () => {
})
it('should create an upload session', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
await createController().startUpload(request, response)
expect(createUploadSession.execute).toHaveBeenCalledWith({
@@ -178,7 +206,17 @@ describe('FilesController', () => {
})
})
it('should not create an upload session on invalid operation in the valet token', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
const result = await createController().startUpload(request, response)
expect(result).toBeInstanceOf(BadRequestErrorMessageResult)
})
it('should return bad request if upload session could not be created', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
createUploadSession.execute = jest.fn().mockReturnValue({ success: false })
const httpResponse = await createController().startUpload(request, response)
@@ -188,6 +226,8 @@ describe('FilesController', () => {
})
it('should finish an upload session', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
await createController().finishUpload(request, response)
expect(finishUploadSession.execute).toHaveBeenCalledWith({
@@ -196,7 +236,17 @@ describe('FilesController', () => {
})
})
it('should not finish an upload session on invalid operation in the valet token', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
const result = await createController().finishUpload(request, response)
expect(result).toBeInstanceOf(BadRequestErrorMessageResult)
})
it('should return bad request if upload session could not be finished', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
finishUploadSession.execute = jest.fn().mockReturnValue({ success: false })
const httpResponse = await createController().finishUpload(request, response)
@@ -206,6 +256,8 @@ describe('FilesController', () => {
})
it('should remove a file', async () => {
response.locals.permittedOperation = ValetTokenOperation.Delete
await createController().remove(request, response)
expect(removeFile.execute).toHaveBeenCalledWith({
@@ -215,6 +267,8 @@ describe('FilesController', () => {
})
it('should return bad request if file removal could not be completed', async () => {
response.locals.permittedOperation = ValetTokenOperation.Delete
removeFile.execute = jest.fn().mockReturnValue({ success: false })
const httpResponse = await createController().remove(request, response)
@@ -223,7 +277,18 @@ describe('FilesController', () => {
expect(result.statusCode).toEqual(400)
})
it('should return bad request if file removal is not permitted on valet token', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
const httpResponse = await createController().remove(request, response)
const result = await httpResponse.executeAsync()
expect(result.statusCode).toEqual(400)
})
it('should upload a chunk to an upload session', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
request.headers['x-chunk-id'] = '2'
request.body = Buffer.from([123])
@@ -238,6 +303,8 @@ describe('FilesController', () => {
})
it('should return bad request if chunk could not be uploaded', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
request.headers['x-chunk-id'] = '2'
request.body = Buffer.from([123])
uploadFileChunk.execute = jest.fn().mockReturnValue({ success: false })
@@ -248,7 +315,18 @@ describe('FilesController', () => {
expect(result.statusCode).toEqual(400)
})
it('should return bad request if valet token is not permitted', async () => {
response.locals.permittedOperation = ValetTokenOperation.Read
const httpResponse = await createController().uploadChunk(request, response)
const result = await httpResponse.executeAsync()
expect(result.statusCode).toEqual(400)
})
it('should return bad request if chunk id is missing', async () => {
response.locals.permittedOperation = ValetTokenOperation.Write
request.body = Buffer.from([123])
const httpResponse = await createController().uploadChunk(request, response)

View File

@@ -9,6 +9,7 @@ import { CreateUploadSession } from '../Domain/UseCase/CreateUploadSession/Creat
import { FinishUploadSession } from '../Domain/UseCase/FinishUploadSession/FinishUploadSession'
import { GetFileMetadata } from '../Domain/UseCase/GetFileMetadata/GetFileMetadata'
import { RemoveFile } from '../Domain/UseCase/RemoveFile/RemoveFile'
import { ValetTokenOperation } from '@standardnotes/security'
@controller('/v1/files', TYPES.ValetTokenAuthMiddleware)
export class FilesController extends BaseHttpController {
@@ -29,6 +30,10 @@ export class FilesController extends BaseHttpController {
_request: Request,
response: Response,
): Promise<results.BadRequestErrorMessageResult | results.JsonResult> {
if (response.locals.permittedOperation !== ValetTokenOperation.Write) {
return this.badRequest('Not permitted for this operation')
}
const result = await this.createUploadSession.execute({
userUuid: response.locals.userUuid,
resourceRemoteIdentifier: response.locals.permittedResources[0].remoteIdentifier,
@@ -46,6 +51,10 @@ export class FilesController extends BaseHttpController {
request: Request,
response: Response,
): Promise<results.BadRequestErrorMessageResult | results.JsonResult> {
if (response.locals.permittedOperation !== ValetTokenOperation.Write) {
return this.badRequest('Not permitted for this operation')
}
const chunkId = +(request.headers['x-chunk-id'] as string)
if (!chunkId) {
return this.badRequest('Missing x-chunk-id header in request.')
@@ -70,6 +79,10 @@ export class FilesController extends BaseHttpController {
_request: Request,
response: Response,
): Promise<results.BadRequestErrorMessageResult | results.JsonResult> {
if (response.locals.permittedOperation !== ValetTokenOperation.Write) {
return this.badRequest('Not permitted for this operation')
}
const result = await this.finishUploadSession.execute({
userUuid: response.locals.userUuid,
resourceRemoteIdentifier: response.locals.permittedResources[0].remoteIdentifier,
@@ -89,6 +102,10 @@ export class FilesController extends BaseHttpController {
_request: Request,
response: Response,
): Promise<results.BadRequestErrorMessageResult | results.JsonResult> {
if (response.locals.permittedOperation !== ValetTokenOperation.Delete) {
return this.badRequest('Not permitted for this operation')
}
const result = await this.removeFile.execute({
userUuid: response.locals.userUuid,
resourceRemoteIdentifier: response.locals.permittedResources[0].remoteIdentifier,
@@ -107,6 +124,10 @@ export class FilesController extends BaseHttpController {
request: Request,
response: Response,
): Promise<results.BadRequestErrorMessageResult | (() => Writable)> {
if (response.locals.permittedOperation !== ValetTokenOperation.Read) {
return this.badRequest('Not permitted for this operation')
}
const range = request.headers['range']
if (!range) {
return this.badRequest('File download requires range header to be set.')

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.4.1](https://github.com/standardnotes/server/compare/@standardnotes/predicates@1.4.0...@standardnotes/predicates@1.4.1) (2022-09-09)
**Note:** Version bump only for package @standardnotes/predicates
# [1.4.0](https://github.com/standardnotes/server/compare/@standardnotes/predicates@1.3.0...@standardnotes/predicates@1.4.0) (2022-09-05)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/predicates",
"version": "1.4.0",
"version": "1.4.1",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,38 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.10.29](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.28...@standardnotes/scheduler-server@1.10.29) (2022-09-16)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.28](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.27...@standardnotes/scheduler-server@1.10.28) (2022-09-09)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.27](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.26...@standardnotes/scheduler-server@1.10.27) (2022-09-08)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.26](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.25...@standardnotes/scheduler-server@1.10.26) (2022-09-08)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.25](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.24...@standardnotes/scheduler-server@1.10.25) (2022-09-08)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.24](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.23...@standardnotes/scheduler-server@1.10.24) (2022-09-08)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.23](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.22...@standardnotes/scheduler-server@1.10.23) (2022-09-08)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.22](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.21...@standardnotes/scheduler-server@1.10.22) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.21](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.20...@standardnotes/scheduler-server@1.10.21) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/scheduler-server",
"version": "1.10.21",
"version": "1.10.29",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.3.2](https://github.com/standardnotes/server/compare/@standardnotes/security@1.3.1...@standardnotes/security@1.3.2) (2022-09-16)
### Bug Fixes
* **files:** add verifying permitted operation on valet token ([377d32c](https://github.com/standardnotes/server/commit/377d32c4498305f0f59ff59e7357f0d2f10ce3a2))
## [1.3.1](https://github.com/standardnotes/server/compare/@standardnotes/security@1.3.0...@standardnotes/security@1.3.1) (2022-09-09)
**Note:** Version bump only for package @standardnotes/security
# [1.3.0](https://github.com/standardnotes/server/compare/@standardnotes/security@1.2.6...@standardnotes/security@1.3.0) (2022-09-05)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/security",
"version": "1.3.0",
"version": "1.3.2",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -1,10 +1,12 @@
import { Uuid } from '@standardnotes/common'
import { ValetTokenOperation } from './ValetTokenOperation'
export type ValetTokenData = {
userUuid: Uuid
sharedSubscriptionUuid: Uuid | undefined
regularSubscriptionUuid: Uuid
permittedOperation: 'read' | 'write' | 'delete'
permittedOperation: ValetTokenOperation
permittedResources: Array<{
remoteIdentifier: string
unencryptedFileSize?: number

View File

@@ -0,0 +1,5 @@
export enum ValetTokenOperation {
Read = 'read',
Write = 'write',
Delete = 'delete',
}

View File

@@ -11,3 +11,4 @@ export * from './Token/OfflineFeaturesTokenData'
export * from './Token/OfflineUserTokenData'
export * from './Token/SessionTokenData'
export * from './Token/ValetTokenData'
export * from './Token/ValetTokenOperation'

View File

@@ -3,6 +3,80 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.8.5](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.8.4...@standardnotes/syncing-server@1.8.5) (2022-09-16)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.8.4](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.8.3...@standardnotes/syncing-server@1.8.4) (2022-09-16)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.8.3](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.8.2...@standardnotes/syncing-server@1.8.3) (2022-09-15)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.8.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.8.1...@standardnotes/syncing-server@1.8.2) (2022-09-15)
### Bug Fixes
* **syncing-server:** files count stats ([ecdfe9e](https://github.com/standardnotes/syncing-server-js/commit/ecdfe9ecc0bce882c1e3c6984f67b76862d76836))
## [1.8.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.8.0...@standardnotes/syncing-server@1.8.1) (2022-09-09)
**Note:** Version bump only for package @standardnotes/syncing-server
# [1.8.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.7.1...@standardnotes/syncing-server@1.8.0) (2022-09-09)
### Features
* **syncing-server:** add tracking files count in stats ([52cc646](https://github.com/standardnotes/syncing-server-js/commit/52cc6462a66dae3bd6c05f551d4ba661c8a9b8c8))
## [1.7.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.7.0...@standardnotes/syncing-server@1.7.1) (2022-09-09)
**Note:** Version bump only for package @standardnotes/syncing-server
# [1.7.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.70...@standardnotes/syncing-server@1.7.0) (2022-09-09)
### Features
* **syncing-server:** add statistics for notes count for free and paid users ([c9ec7b4](https://github.com/standardnotes/syncing-server-js/commit/c9ec7b492aea1911e441ed8ad9a155f871be2ef7))
## [1.6.70](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.69...@standardnotes/syncing-server@1.6.70) (2022-09-08)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.69](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.68...@standardnotes/syncing-server@1.6.69) (2022-09-08)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.68](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.67...@standardnotes/syncing-server@1.6.68) (2022-09-08)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.67](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.66...@standardnotes/syncing-server@1.6.67) (2022-09-08)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.66](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.65...@standardnotes/syncing-server@1.6.66) (2022-09-08)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.65](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.64...@standardnotes/syncing-server@1.6.65) (2022-09-07)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.64](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.63...@standardnotes/syncing-server@1.6.64) (2022-09-07)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.63](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.62...@standardnotes/syncing-server@1.6.63) (2022-09-07)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.62](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.61...@standardnotes/syncing-server@1.6.62) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.61](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.60...@standardnotes/syncing-server@1.6.61) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.6.61",
"version": "1.8.5",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -35,7 +35,7 @@ describe('AuthMiddleware', () => {
next = jest.fn()
})
it('should authorize user from an auth JWT token if present', async () => {
it('should authorize a paid user from an auth JWT token if present', async () => {
const authToken = sign(
{
user: { uuid: '123' },
@@ -66,6 +66,34 @@ describe('AuthMiddleware', () => {
expect(response.locals.session).toEqual({ uuid: '234' })
expect(response.locals.readOnlyAccess).toBeFalsy()
expect(response.locals.analyticsId).toEqual(123)
expect(response.locals.freeUser).toEqual(false)
expect(next).toHaveBeenCalled()
})
it('should authorize a free user from an auth JWT token if present', async () => {
const authToken = sign(
{
user: { uuid: '123' },
session: { uuid: '234' },
roles: [
{
uuid: '1-2-3',
name: RoleName.CoreUser,
},
],
analyticsId: 123,
permissions: [],
},
jwtSecret,
{ algorithm: 'HS256' },
)
request.header = jest.fn().mockReturnValue(authToken)
await createMiddleware().handler(request, response, next)
expect(response.locals.freeUser).toEqual(true)
expect(next).toHaveBeenCalled()
})

View File

@@ -5,6 +5,7 @@ import { verify } from 'jsonwebtoken'
import { CrossServiceTokenData } from '@standardnotes/security'
import * as winston from 'winston'
import TYPES from '../Bootstrap/Types'
import { RoleName } from '@standardnotes/common'
@injectable()
export class AuthMiddleware extends BaseMiddleware {
@@ -27,6 +28,8 @@ export class AuthMiddleware extends BaseMiddleware {
response.locals.user = decodedToken.user
response.locals.roleNames = decodedToken.roles.map((role) => role.name)
response.locals.freeUser =
response.locals.roleNames.length === 1 && response.locals.roleNames[0] === RoleName.CoreUser
response.locals.session = decodedToken.session
response.locals.readOnlyAccess = decodedToken.session?.readonly_access ?? false
response.locals.analyticsId = decodedToken.analyticsId

View File

@@ -75,6 +75,7 @@ describe('ItemsController', () => {
uuid: '123',
}
response.locals.analyticsId = 123
response.locals.freeUser = false
syncResponse = {} as jest.Mocked<SyncResponse20200115>
@@ -132,6 +133,8 @@ describe('ItemsController', () => {
},
],
userUuid: '123',
analyticsId: 123,
freeUser: false,
})
expect(result.statusCode).toEqual(200)
@@ -147,6 +150,8 @@ describe('ItemsController', () => {
expect(checkIntegrity.execute).toHaveBeenCalledWith({
integrityPayloads: [],
userUuid: '123',
analyticsId: 123,
freeUser: false,
})
expect(result.statusCode).toEqual(200)

View File

@@ -62,6 +62,8 @@ export class ItemsController extends BaseHttpController {
const result = await this.checkIntegrity.execute({
userUuid: response.locals.user.uuid,
integrityPayloads,
analyticsId: response.locals.analyticsId,
freeUser: response.locals.freeUser,
})
return this.json(result)

View File

@@ -1,6 +1,6 @@
import 'reflect-metadata'
import { StatisticsStoreInterface } from '@standardnotes/analytics'
import { AnalyticsStoreInterface, Period, StatisticsStoreInterface } from '@standardnotes/analytics'
import { ItemRepositoryInterface } from '../../Item/ItemRepositoryInterface'
@@ -10,8 +10,9 @@ import { ContentType } from '@standardnotes/common'
describe('CheckIntegrity', () => {
let itemRepository: ItemRepositoryInterface
let statisticsStore: StatisticsStoreInterface
let analyticsStore: AnalyticsStoreInterface
const createUseCase = () => new CheckIntegrity(itemRepository, statisticsStore)
const createUseCase = () => new CheckIntegrity(itemRepository, statisticsStore, analyticsStore)
beforeEach(() => {
itemRepository = {} as jest.Mocked<ItemRepositoryInterface>
@@ -36,16 +37,28 @@ describe('CheckIntegrity', () => {
updated_at_timestamp: 4,
content_type: ContentType.ItemsKey,
},
{
uuid: '5-6-7',
updated_at_timestamp: 5,
content_type: ContentType.File,
},
])
statisticsStore = {} as jest.Mocked<StatisticsStoreInterface>
statisticsStore.incrementOutOfSyncIncidents = jest.fn()
statisticsStore.incrementMeasure = jest.fn()
analyticsStore = {} as jest.Mocked<AnalyticsStoreInterface>
analyticsStore.wasActivityDone = jest.fn().mockReturnValue(false)
analyticsStore.markActivity = jest.fn()
})
it('should return an empty result if there are no integrity mismatches', async () => {
expect(
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: false,
integrityPayloads: [
{
uuid: '1-2-3',
@@ -59,6 +72,10 @@ describe('CheckIntegrity', () => {
uuid: '3-4-5',
updated_at_timestamp: 3,
},
{
uuid: '5-6-7',
updated_at_timestamp: 5,
},
],
}),
).toEqual({
@@ -70,6 +87,8 @@ describe('CheckIntegrity', () => {
expect(
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: false,
integrityPayloads: [
{
uuid: '1-2-3',
@@ -83,6 +102,10 @@ describe('CheckIntegrity', () => {
uuid: '3-4-5',
updated_at_timestamp: 3,
},
{
uuid: '5-6-7',
updated_at_timestamp: 5,
},
],
}),
).toEqual({
@@ -101,6 +124,8 @@ describe('CheckIntegrity', () => {
expect(
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: false,
integrityPayloads: [
{
uuid: '1-2-3',
@@ -110,6 +135,10 @@ describe('CheckIntegrity', () => {
uuid: '2-3-4',
updated_at_timestamp: 2,
},
{
uuid: '5-6-7',
updated_at_timestamp: 5,
},
],
}),
).toEqual({
@@ -121,4 +150,87 @@ describe('CheckIntegrity', () => {
],
})
})
it('should count notes for statistics of free users', async () => {
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: true,
integrityPayloads: [
{
uuid: '1-2-3',
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
updated_at_timestamp: 1,
},
{
uuid: '3-4-5',
updated_at_timestamp: 3,
},
],
})
expect(statisticsStore.incrementMeasure).toHaveBeenCalledWith('notes-count-free-users', 3, [
Period.Today,
Period.ThisMonth,
])
expect(analyticsStore.markActivity).toHaveBeenCalledWith(['checking-integrity'], 1, [Period.Today])
})
it('should count notes for statistics of paid users', async () => {
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: false,
integrityPayloads: [
{
uuid: '1-2-3',
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
updated_at_timestamp: 1,
},
{
uuid: '3-4-5',
updated_at_timestamp: 3,
},
],
})
expect(statisticsStore.incrementMeasure).toHaveBeenCalledWith('notes-count-paid-users', 3, [
Period.Today,
Period.ThisMonth,
])
expect(analyticsStore.markActivity).toHaveBeenCalledWith(['checking-integrity'], 1, [Period.Today])
})
it('should not count notes for statistics if they were already counted today', async () => {
analyticsStore.wasActivityDone = jest.fn().mockReturnValue(true)
await createUseCase().execute({
userUuid: '1-2-3',
analyticsId: 1,
freeUser: false,
integrityPayloads: [
{
uuid: '1-2-3',
updated_at_timestamp: 1,
},
{
uuid: '2-3-4',
updated_at_timestamp: 1,
},
{
uuid: '3-4-5',
updated_at_timestamp: 3,
},
],
})
expect(statisticsStore.incrementMeasure).not.toHaveBeenCalled()
expect(analyticsStore.markActivity).not.toHaveBeenCalled()
})
})

View File

@@ -1,6 +1,12 @@
import { inject, injectable } from 'inversify'
import { IntegrityPayload } from '@standardnotes/payloads'
import { StatisticsStoreInterface } from '@standardnotes/analytics'
import {
AnalyticsActivity,
AnalyticsStoreInterface,
Period,
StatisticsMeasure,
StatisticsStoreInterface,
} from '@standardnotes/analytics'
import TYPES from '../../../Bootstrap/Types'
import { ItemRepositoryInterface } from '../../Item/ItemRepositoryInterface'
@@ -15,16 +21,27 @@ export class CheckIntegrity implements UseCaseInterface {
constructor(
@inject(TYPES.ItemRepository) private itemRepository: ItemRepositoryInterface,
@inject(TYPES.StatisticsStore) private statisticsStore: StatisticsStoreInterface,
@inject(TYPES.AnalyticsStore) private analyticsStore: AnalyticsStoreInterface,
) {}
async execute(dto: CheckIntegrityDTO): Promise<CheckIntegrityResponse> {
const serverItemIntegrityPayloads = await this.itemRepository.findItemsForComputingIntegrityPayloads(dto.userUuid)
let notesCount = 0
let filesCount = 0
const serverItemIntegrityPayloadsMap = new Map<string, ExtendedIntegrityPayload>()
for (const serverItemIntegrityPayload of serverItemIntegrityPayloads) {
serverItemIntegrityPayloadsMap.set(serverItemIntegrityPayload.uuid, serverItemIntegrityPayload)
if (serverItemIntegrityPayload.content_type === ContentType.Note) {
notesCount++
}
if (serverItemIntegrityPayload.content_type === ContentType.File) {
filesCount++
}
}
await this.saveNotesCountStatistics(dto.freeUser, dto.analyticsId, { notes: notesCount, files: filesCount })
const clientItemIntegrityPayloadsMap = new Map<string, number>()
for (const clientItemIntegrityPayload of dto.integrityPayloads) {
clientItemIntegrityPayloadsMap.set(
@@ -74,4 +91,33 @@ export class CheckIntegrity implements UseCaseInterface {
mismatches,
}
}
private async saveNotesCountStatistics(
freeUser: boolean,
analyticsId: number,
counts: { notes: number; files: number },
) {
const integrityWasCheckedToday = await this.analyticsStore.wasActivityDone(
AnalyticsActivity.CheckingIntegrity,
analyticsId,
Period.Today,
)
if (!integrityWasCheckedToday) {
await this.analyticsStore.markActivity([AnalyticsActivity.CheckingIntegrity], analyticsId, [Period.Today])
await this.statisticsStore.incrementMeasure(
freeUser ? StatisticsMeasure.NotesCountFreeUsers : StatisticsMeasure.NotesCountPaidUsers,
counts.notes,
[Period.Today, Period.ThisMonth],
)
if (!freeUser) {
await this.statisticsStore.incrementMeasure(StatisticsMeasure.FilesCount, counts.files, [
Period.Today,
Period.ThisMonth,
])
}
}
}
}

View File

@@ -4,4 +4,6 @@ import { IntegrityPayload } from '@standardnotes/payloads'
export type CheckIntegrityDTO = {
userUuid: Uuid
integrityPayloads: IntegrityPayload[]
freeUser: boolean
analyticsId: number
}

133
yarn.lock
View File

@@ -1767,6 +1767,7 @@ __metadata:
"@newrelic/winston-enricher": ^4.0.0
"@sentry/node": ^7.3.0
"@standardnotes/analytics": "workspace:*"
"@standardnotes/common": "workspace:^"
"@standardnotes/domain-events": "workspace:*"
"@standardnotes/domain-events-infra": "workspace:*"
"@standardnotes/security": "workspace:*"
@@ -1802,17 +1803,18 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/api@npm:^1.1.19":
version: 1.1.19
resolution: "@standardnotes/api@npm:1.1.19"
"@standardnotes/api@npm:^1.7.2":
version: 1.7.2
resolution: "@standardnotes/api@npm:1.7.2"
dependencies:
"@standardnotes/auth": ^3.19.4
"@standardnotes/common": ^1.23.1
"@standardnotes/encryption": ^1.8.23
"@standardnotes/responses": ^1.6.39
"@standardnotes/services": ^1.13.23
"@standardnotes/utils": ^1.6.12
checksum: cca168245a80d333ca6433799a7cbe4a233956cace92b9e9ec45b3f67e4e907ef4f08a9573008bdf2b11a09100dc0381cff820ee5bea384407c2107c494913ba
"@standardnotes/common": ^1.32.0
"@standardnotes/encryption": 1.15.2
"@standardnotes/models": 1.18.2
"@standardnotes/responses": 1.10.1
"@standardnotes/security": ^1.1.0
"@standardnotes/utils": 1.9.0
reflect-metadata: ^0.1.13
checksum: bdfc414e6d01620fd047979255a43eb447afbb69d1bb694015b162ad236431273cd234bba4129d13ba94791271aaff71895d726357491d6ab984c7d5a7a8a3f7
languageName: node
linkType: hard
@@ -1823,7 +1825,7 @@ __metadata:
"@newrelic/winston-enricher": ^4.0.0
"@sentry/node": ^7.3.0
"@standardnotes/analytics": "workspace:*"
"@standardnotes/api": ^1.1.19
"@standardnotes/api": ^1.7.2
"@standardnotes/common": "workspace:*"
"@standardnotes/domain-events": "workspace:*"
"@standardnotes/domain-events-infra": "workspace:*"
@@ -1884,7 +1886,7 @@ __metadata:
languageName: node
linkType: hard
"@standardnotes/common@^1.19.1, @standardnotes/common@^1.23.1, @standardnotes/common@workspace:*, @standardnotes/common@workspace:packages/common":
"@standardnotes/common@^1.19.1, @standardnotes/common@^1.23.1, @standardnotes/common@^1.32.0, @standardnotes/common@workspace:*, @standardnotes/common@workspace:^, @standardnotes/common@workspace:packages/common":
version: 0.0.0-use.local
resolution: "@standardnotes/common@workspace:packages/common"
dependencies:
@@ -1949,18 +1951,17 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/encryption@npm:^1.8.23":
version: 1.12.0
resolution: "@standardnotes/encryption@npm:1.12.0"
"@standardnotes/encryption@npm:1.15.2":
version: 1.15.2
resolution: "@standardnotes/encryption@npm:1.15.2"
dependencies:
"@standardnotes/common": ^1.23.1
"@standardnotes/models": 1.14.0
"@standardnotes/responses": ^1.6.39
"@standardnotes/services": 1.15.0
"@standardnotes/sncrypto-common": ^1.9.0
"@standardnotes/utils": ^1.6.12
"@standardnotes/common": ^1.32.0
"@standardnotes/models": 1.18.2
"@standardnotes/responses": 1.10.1
"@standardnotes/sncrypto-common": 1.11.1
"@standardnotes/utils": 1.9.0
reflect-metadata: ^0.1.13
checksum: 1a28653b1e75c8c728fc7e68a64950eea2a291b339c7cd9f8672061ab9768ae7895fb75184b98e9046c296a96bb40d835dda7706ace973a948232f0f0655fcf7
checksum: 6e8336f1e7e961fbd42c4890458dca877da62dcc1987f7e9a7fb6ca230821276fce6a33652669bcc1752a80ffc55e4cf82b8631f7902d9714f4a07a7956092b0
languageName: node
linkType: hard
@@ -1992,7 +1993,19 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/features@npm:1.50.0, @standardnotes/features@npm:^1.36.3, @standardnotes/features@npm:^1.47.0":
"@standardnotes/features@npm:1.52.0":
version: 1.52.0
resolution: "@standardnotes/features@npm:1.52.0"
dependencies:
"@standardnotes/auth": ^3.19.4
"@standardnotes/common": ^1.32.0
"@standardnotes/security": ^1.2.0
reflect-metadata: ^0.1.13
checksum: 3e6014272f72ed33bc7de3cefb33a63a02866c01bfd4a54bc95426e2719f4997940de382cfd83982eaeafdbdf9afac558aecb9139117facfe9c7479089e2952d
languageName: node
linkType: hard
"@standardnotes/features@npm:^1.36.3, @standardnotes/features@npm:^1.47.0":
version: 1.50.0
resolution: "@standardnotes/features@npm:1.50.0"
dependencies:
@@ -2053,17 +2066,17 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/models@npm:1.14.0":
version: 1.14.0
resolution: "@standardnotes/models@npm:1.14.0"
"@standardnotes/models@npm:1.18.2":
version: 1.18.2
resolution: "@standardnotes/models@npm:1.18.2"
dependencies:
"@standardnotes/common": ^1.23.1
"@standardnotes/features": 1.50.0
"@standardnotes/responses": ^1.6.39
"@standardnotes/utils": ^1.6.12
"@standardnotes/common": ^1.32.0
"@standardnotes/features": 1.52.0
"@standardnotes/responses": 1.10.1
"@standardnotes/utils": 1.9.0
lodash: ^4.17.21
reflect-metadata: ^0.1.13
checksum: bfb9d517b6569d39e3f7bb700a644e430c7c88a2ce84c24d649efd8aac1fa94f222258fe08e1afa2614ffd73ac414911bbe39a597c1f6e9bfce6852a2c7ac776
checksum: 88180a93e5acdc349e1f96159c40610d7f52d49f0566386d9d6db8767d5ac4ba73af3131c8e433afa253557349e3f96238f6b2060e94df51ceedb5d378b3dd1f
languageName: node
linkType: hard
@@ -2092,6 +2105,18 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/responses@npm:1.10.1":
version: 1.10.1
resolution: "@standardnotes/responses@npm:1.10.1"
dependencies:
"@standardnotes/common": ^1.32.0
"@standardnotes/features": 1.52.0
"@standardnotes/security": ^1.1.0
reflect-metadata: ^0.1.13
checksum: b84fb3f71cc32286fc757280e01c2da7fd0576e96455bfd53c5e55f807875d7201a23e727a7c702277b90f1959837a9a0cbda94ca6a4f4ad6a4896e306ed851c
languageName: node
linkType: hard
"@standardnotes/responses@npm:^1.6.39":
version: 1.6.39
resolution: "@standardnotes/responses@npm:1.6.39"
@@ -2137,7 +2162,7 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/security@workspace:*, @standardnotes/security@workspace:packages/security":
"@standardnotes/security@^1.1.0, @standardnotes/security@^1.2.0, @standardnotes/security@workspace:*, @standardnotes/security@workspace:packages/security":
version: 0.0.0-use.local
resolution: "@standardnotes/security@workspace:packages/security"
dependencies:
@@ -2178,20 +2203,6 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/services@npm:1.15.0, @standardnotes/services@npm:^1.13.23":
version: 1.15.0
resolution: "@standardnotes/services@npm:1.15.0"
dependencies:
"@standardnotes/auth": ^3.19.4
"@standardnotes/common": ^1.23.1
"@standardnotes/models": 1.14.0
"@standardnotes/responses": ^1.6.39
"@standardnotes/utils": ^1.6.12
reflect-metadata: ^0.1.13
checksum: 1028a5b4c1372f13044115b3dea510a7e32479567161007472116f8a6168570735beeb32a5e795259f461bc983e75c4a4be72b8a927c60225c4057594ce139b2
languageName: node
linkType: hard
"@standardnotes/settings@workspace:*, @standardnotes/settings@workspace:packages/settings":
version: 0.0.0-use.local
resolution: "@standardnotes/settings@workspace:packages/settings"
@@ -2202,6 +2213,15 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/sncrypto-common@npm:1.11.1":
version: 1.11.1
resolution: "@standardnotes/sncrypto-common@npm:1.11.1"
dependencies:
reflect-metadata: ^0.1.13
checksum: 69d698abb7ffc2aecfffd9ccf3e023adca73e5b27cfa1106dfdf10a13d6455b9581c9bf854b333f00255317ec62c384c516b218f40a55ee84fd4f659b8aef16b
languageName: node
linkType: hard
"@standardnotes/sncrypto-common@npm:^1.9.0":
version: 1.9.0
resolution: "@standardnotes/sncrypto-common@npm:1.9.0"
@@ -2296,7 +2316,19 @@ __metadata:
languageName: unknown
linkType: soft
"@standardnotes/utils@npm:^1.4.6, @standardnotes/utils@npm:^1.6.12":
"@standardnotes/utils@npm:1.9.0":
version: 1.9.0
resolution: "@standardnotes/utils@npm:1.9.0"
dependencies:
"@standardnotes/common": ^1.32.0
dompurify: ^2.3.8
lodash: ^4.17.21
reflect-metadata: ^0.1.13
checksum: 4591aff48d074b30b911f96c63eaaf521ab49563507672fbd4d7fe460e51f88a45effb002d1c82cca3513d2199c0cdb720556b03ec3e0266f593317c8efa764a
languageName: node
linkType: hard
"@standardnotes/utils@npm:^1.4.6":
version: 1.6.12
resolution: "@standardnotes/utils@npm:1.6.12"
dependencies:
@@ -4470,6 +4502,13 @@ __metadata:
languageName: node
linkType: hard
"dompurify@npm:^2.3.8":
version: 2.4.0
resolution: "dompurify@npm:2.4.0"
checksum: c93ea73cf8e3ba044588450198563e56ce6902e36d0e16e3699df2fa59e82c4fdd11d4ad04ef5024569ce96a35b46f29d0bbea522516add33cd39a7f56a8a675
languageName: node
linkType: hard
"dot-prop@npm:^5.1.0":
version: 5.3.0
resolution: "dot-prop@npm:5.3.0"