Commit Graph

75 Commits

Author SHA1 Message Date
Hannah Wolfe
b06e2a4577 Published new versions
- @tryghost/adapter-manager@0.2.13
 - @tryghost/bootstrap-socket@0.2.9
 - @tryghost/constants@0.1.8
 - @tryghost/errors@0.2.12
 - @tryghost/image-transform@1.0.12
 - @tryghost/job-manager@0.8.7
 - @tryghost/limit-service@0.6.1
 - @tryghost/moleculer-service-from-class@0.2.16
 - @tryghost/mw-session-from-token@0.1.21
 - @tryghost/package-json@0.1.2
 - @tryghost/pretty-cli@1.2.18
 - @tryghost/promise@0.1.9
 - @tryghost/release-utils@0.6.15
 - @tryghost/security@0.2.9
 - @tryghost/session-service@0.1.23
 - @tryghost/tpl@0.1.0
 - @tryghost/vhost-middleware@1.0.15
 - @tryghost/zip@1.1.14
2021-06-09 12:10:10 +01:00
Renovate Bot
c72d090c97 Update dependency mocha to v9 2021-06-09 09:58:44 +00:00
Renovate Bot
80b56b8976 Update dependency sinon to v11 2021-05-24 22:37:15 +00:00
Naz
f2c1ee2263 Published new versions
- @tryghost/limit-service@0.6.0
2021-05-21 14:16:04 +04:00
Naz
ad0d1ab557 Fixed indescribable error in allowlist limit
https://github.com/TryGhost/Team/issues/663

-  When there is no parameter passed at all it was a generic 'Cannot read property 'value' of undefined' message which wasn't helpful in recognizing what the actual problem was
- Have added additional guarding logic to throw a descriptive error
2021-05-21 14:09:27 +04:00
Naz
f0a5fc975c Fixed error "swallowing"
no issue

- I've discovered the "IncorrectUsageError" error was silently swallowed and the method returned a false positibe when an allowlist limit type was called with incorrect parameters
- In cases like this it's best to surface the real error early otherwise the logic might produce unsafe results!
2021-05-21 14:02:35 +04:00
Naz
9632e98dd2 Added a convenience method checking if any limits are acceded
refs https://github.com/TryGhost/Team/issues/662

- There is a need to check if any of the current limits are over limit in Daisy. This method is the simplest possible implementation to check if any of them are over limit
- Possible future iterations might include a list of names of the limits that have been acceded and their error messages
- The `checkIfAnyOverLimit` method should be treated as a starter to work up the complexity as needed
2021-05-21 13:24:55 +04:00
Naz
6a08297c3a Published new versions
- @tryghost/job-manager@0.8.6
 - @tryghost/limit-service@0.5.1
2021-05-12 16:42:36 +04:00
Naz
88f0c332b4 Exposed additional "name" variable in error templates
refs https://github.com/TryGhost/Team/issues/587

- There was a need to be able to use the "name" of the limit inside of error templates like so: `{{name}}` (reference https://github.com/TryGhost/Team/issues/587#issuecomment-814281794)
- This change allows to form custom error messages using following variable: `{{name}}` which is the same as the `name` property provided in the configuration for the limit
2021-05-12 14:43:52 +04:00
Thibaut Patel
2b46145f88 Updated the example for the customThemes configuration
no issue
2021-05-12 11:56:41 +02:00
Naz
e26597e045 Added header to the section
no issue

- Made it clear what this part of the doc is about
2021-05-11 17:15:22 +04:00
Naz
7ec5e4bd72 Added documentation for names of limits
refs https://github.com/TryGhost/Team/issues/510

- There's a limited type of limit "names" supported by the limit service, so worth specifying them upfront. Also some limits are univerally aplicable like "flag" or "allowlist" and some are restricted like "max" and "maxPeriodic"
2021-05-11 17:14:58 +04:00
Naz
420ba250a3 Added documentation for types of limits
refs https://github.com/TryGhost/Team/issues/588
refs https://github.com/TryGhost/Team/issues/510

- There's a limited type of limits supported by the limit service and it's worth to have a conceptual description of how they work and how to use them
2021-05-11 17:13:18 +04:00
Naz
12b31a7b4b Added customThemes limit to config example
refs https://github.com/TryGhost/Team/issues/590

- The "allowList" type of configuration was missing from the example, added it for reference
2021-05-11 16:31:34 +04:00
Naz
37fa30fd6b Added emails limit to documentation example
refs https://github.com/TryGhost/Team/issues/588

- The "emails" limit was added with recent changes and could be configured as either "flag" or "maxPeridoci" type of limit
- More docs on different types of limits to follow
2021-05-11 16:29:10 +04:00
Naz
30f1194cf9 Published new versions
- @tryghost/limit-service@0.5.0
 - @tryghost/package-json@0.1.1
2021-05-07 18:23:35 +04:00
Naz
612cc2b513 Added addedCount to max and maxPeriodic limits
refs https://github.com/TryGhost/Team/issues/588

- The `addedCount` parameter in `errorIfWouldGoOverLimit` method allows to specify a custom resource count that is about to be added. Example usecase is when we'd want to send a 100 emails and current limit is 99, and none have been sent so far. With previous implementation the check would've passed because it only checked for single resource that would be added through "+1". Current implementation allows to specify the amount of recources to be added
2021-05-07 18:13:01 +04:00
Naz
4f0a7fa1d3 Fixed query counting total emails sent in a period
refs https://github.com/TryGhost/Team/issues/588

- The previous query was quickly copied from stats-service which was using incorrect table for the count
- Updated version sums up email_count values for emails in given period of time
2021-05-07 17:58:01 +04:00
Naz
763875a15b Published new versions
- @tryghost/job-manager@0.8.5
 - @tryghost/limit-service@0.4.4
 - @tryghost/mw-session-from-token@0.1.20
 - @tryghost/package-json@0.1.0
 - @tryghost/session-service@0.1.21
 - @tryghost/zip@1.1.13
2021-05-07 15:00:07 +04:00
Naz
bd360e620f Removed date-fns dev dependency
refs https://github.com/TryGhost/Team/issues/588
refs 6a1e722648

- date-fns proved to be unable to manipulate dates in consistent UTC format and was substitured with luxon in referenced commit. Removing it from tests for consistency
2021-05-07 14:56:40 +04:00
Naz
6a1e722648 Fixed time difference calculation in DST timezones
refs https://github.com/TryGhost/Team/issues/588

- date-fns proved to be unable to manipulate dates consistently in UTC timezone. Keeping all calculations and formatting in UTC is key to have consistency in dates when dealing in inter-system dates
- day.js also failed the test for correct UTC manipulation. See https://github.com/iamkun/dayjs/issues/1271 for example bug which prevents from consistent correct calculation
- luxon was the best option which WORKED. It's also a recommended successor for moment.js with really nice docs and active support
2021-05-07 14:41:52 +04:00
Naz
16e21236ba Clarified test name 2021-05-07 11:46:33 +04:00
Renovate Bot
3d4e65ebc3 Pin dependency date-fns to 2.21.2 2021-05-06 16:14:06 +00:00
Naz
9c738b13d1 Added added maxPeriodical checks
refs https://github.com/TryGhost/Team/issues/588

- This bit is putting together all the pieces for periodical limit checks. More tests are to come
2021-05-06 17:48:31 +04:00
Naz
ebfad4bea4 Added currentCountQuery for emails limit
refs https://github.com/TryGhost/Team/issues/588

- This is a basic implementation which needs a review. Implemented it to fix failing tests in main
- Start date is expected to come formatted for DB's needs
2021-05-06 17:37:50 +04:00
Naz
0d242b96ef Added maxPeriodic limit support to limit service
refs https://github.com/TryGhost/Team/issues/588

- The limit service can now be initialized with a config which has a 'maxPeriodic' key identifying it's a special type of limit taking subscription cycles into account
- Example configuration can be found in the included unit tests
2021-05-06 15:50:36 +04:00
Naz
1483a5c758 Fixed IncorrectUsageError initialization
no issue

- The error takes in an options object which should contain "message" property instead of a string
2021-05-06 15:50:36 +04:00
Naz
4f41c2a206 Added utility calculating date of last period start
refs https://github.com/TryGhost/Team/issues/588

- There's a need to calculate when the last period has started to be able to generate correct counting queries for the "maxPeriodical" limit
- It operatest on ISO strings as an input and output in UTC timezone to take timezone calculations out of the equation
- Refer to inclucded unit tests for example calculations
2021-05-06 15:50:36 +04:00
Naz
413549f9c0 Added "maxPeriodic" limit type
refs https://github.com/TryGhost/Team/issues/588

- This is a scaffolding for a new limit type which should allow to check limits based on periods (for example related to billing, subscription cycles)
2021-05-06 15:50:36 +04:00
Naz
a240582094 Fixed typos 2021-05-05 12:42:30 +04:00
Naz
9c668317de Published new versions
- @tryghost/limit-service@0.4.3
2021-05-03 12:05:01 +04:00
Naz
47a6956175 Added test coverage for flag type of limits
refs https://github.com/TryGhost/Team/issues/588

- This is by no means an thorought test coverage but ensures the basics work and provides examples of how the limit should be used. To be continued :)
2021-05-03 12:02:01 +04:00
Naz
a5eba60c23 Added flag limit support for "emails"
refs https://github.com/TryGhost/Team/issues/588

- This is a step 1 in the introduction of email limits. Next step would be allowing this limit to support "periodical limit checks"
2021-05-03 11:47:55 +04:00
Naz
d720851ec6 Fixed failing build
refs 8d97bdec6e

- Had a stray code commited in refed commit
2021-05-03 11:11:23 +04:00
Naz
8d97bdec6e Added notes about how config module works
no issue

- I was a little confused seeing an empty object in the config moduele -  `customThemes: {}` and initially thought we could get rid of it to reduce the amount of code. Afte quick dig found out that there's a purpuse behind it being there! It's an allowlist of the properites that can be defined within the limit service
- Added notes to clarify the usecase and avoid ambiguity in the future
2021-05-03 11:07:57 +04:00
Daniel Lockyer
098801de2c Published new versions
- @tryghost/adapter-manager@0.2.12
 - @tryghost/errors@0.2.11
 - @tryghost/image-transform@1.0.11
 - @tryghost/job-manager@0.8.4
 - @tryghost/limit-service@0.4.2
 - @tryghost/moleculer-service-from-class@0.2.15
 - @tryghost/mw-session-from-token@0.1.19
 - @tryghost/pretty-cli@1.2.17
 - @tryghost/promise@0.1.8
 - @tryghost/release-utils@0.6.14
 - @tryghost/security@0.2.8
 - @tryghost/session-service@0.1.20
 - @tryghost/zip@1.1.12
2021-04-19 10:25:57 +01:00
Naz
5c89a5bec2 Published new versions
- @tryghost/adapter-manager@0.2.11
 - @tryghost/job-manager@0.8.3
 - @tryghost/limit-service@0.4.1
 - @tryghost/moleculer-service-from-class@0.2.14
 - @tryghost/mw-session-from-token@0.1.18
 - @tryghost/session-service@0.1.19
2021-04-17 08:12:34 +12:00
Renovate Bot
3184ca584d Pin dependencies 2021-04-16 12:28:10 +00:00
Daniel Lockyer
713cbd3cc4 Unpinned all dependencies
no issue

- this Utils repo contains libraries, whose dependencies should not be
  pinned in order to reduce multiple versions of the same package
  appearing for consumers
2021-04-16 13:06:54 +01:00
Naz
1802d46c1d Added a limit reset when loadLimits called repeatedly
refs https://github.com/TryGhost/Team/issues/599

- There are cases when there'a a need to reload limits with a new set of configuration. For example, when Ghost is run in a test environment is a soft reboot is done
- Resetting previous value of limits avoids having conflicting state after multiple calls
2021-04-09 23:44:12 +12:00
Naz
6c0aabadea Added a not to flag limit "errorIfIsOverLimit" method
refs https://github.com/TryGhost/Team/issues/510

- Flag limits are impossible to check if they are "over a limit already" as they are just that - on/off flags. Therefore it should be directly noted that the method is there to keep the "Limit" interface and not be relied upon
2021-04-09 16:10:14 +12:00
Thibaut Patel
8381346dce Added allowlist limit (#144)
issue https://github.com/TryGhost/Team/issues/510
2021-04-08 17:29:53 +02:00
Thibaut Patel
8c6ec8b214 Added a test to confirm isLimited behavior of an unkown key
no issue
2021-04-08 15:07:30 +02:00
Naz
4d6733b927 Improved docs around {{max}} & {{count}}
refs https://github.com/TryGhost/Team/issues/587

- Improved description and provided example use of error message template variables that are available for "MaxLimit" types of limits
2021-04-07 18:14:18 +12:00
Naz
0f049fbb94 Improved query formatting
refs https://github.com/TryGhost/Team/issues/599

- Oneliners with lots of chained commands are hardly readable on small screens
2021-04-07 18:13:10 +12:00
Naz
e11c0f43cf Published new versions
- @tryghost/adapter-manager@0.2.10
 - @tryghost/bootstrap-socket@0.2.8
 - @tryghost/constants@0.1.7
 - @tryghost/errors@0.2.10
 - @tryghost/image-transform@1.0.10
 - @tryghost/job-manager@0.8.2
 - @tryghost/limit-service@0.4.0
 - @tryghost/moleculer-service-from-class@0.2.13
 - @tryghost/mw-session-from-token@0.1.17
 - @tryghost/pretty-cli@1.2.16
 - @tryghost/promise@0.1.7
 - @tryghost/release-utils@0.6.13
 - @tryghost/security@0.2.7
 - @tryghost/session-service@0.1.18
 - @tryghost/vhost-middleware@1.0.14
 - @tryghost/zip@1.1.11
2021-04-07 13:47:32 +12:00
Naz
01f18aa4fa Added test coverage for {{max}} and {{count}}
refs https://github.com/TryGhost/Team/issues/510

- {{max}} and {{count}} variable usage was not covered but had valid usecases in the library client's, so considered to "document" them through tests
- For more context these variables are available in custom `error` templates that are provided with each limit
2021-04-07 13:31:42 +12:00
Naz
36dd9219c9 Added docs for currentCountQuery usage
refs https://github.com/TryGhost/Team/issues/597

- Documented example usacase for currentCountQuery override intoruced in previous commit
2021-04-06 17:05:44 +12:00
Naz
f4f48712c5 Added custom count queries for "max" limits
refs https://github.com/TryGhost/Team/issues/597

- When the library is used on a client without a DB connection (e.g. frontend client running in a browser) the library needs to expose a way to override count queries.
- The way these can be used is giving a count based on a HTTP request or some other data provider
- Example use with max limit like "staff" would be loading the limit servcie if following way:
```
            const limitService = new LimitService();

            let limits = {
                staff: {
                    max: 2,
                    currentCountQuery: () => 5
                }
            };

            limitService.loadLimits({limits, errors});

            await limitService.checkIsOverLimit('staff')
```
2021-04-06 16:45:46 +12:00
Naz
326cbf0d34 Fixed test missing a whitespace
refs https://github.com/TryGhost/Team/issues/597
refs a1962f38cd
2021-04-05 16:29:07 +12:00