Commit Graph

629 Commits

Author SHA1 Message Date
Renovate Bot
4a1da452e9 Update Test & linting packages 2021-09-22 14:29:23 +00:00
Naz
b428648665 Published new versions
- @tryghost/adapter-manager@0.2.15
 - @tryghost/bootstrap-socket@0.2.10
 - @tryghost/config-url-helpers@0.1.1
 - @tryghost/constants@0.1.9
 - @tryghost/errors@0.2.14
 - @tryghost/image-transform@1.0.14
 - @tryghost/job-manager@0.8.8
 - @tryghost/limit-service@0.6.2
 - @tryghost/moleculer-service-from-class@0.2.18
 - @tryghost/mw-session-from-token@0.1.23
 - @tryghost/package-json@1.0.3
 - @tryghost/pretty-cli@1.2.19
 - @tryghost/promise@0.1.10
 - @tryghost/release-utils@0.6.16
 - @tryghost/security@0.2.10
 - @tryghost/session-service@0.1.25
 - @tryghost/tpl@0.1.4
 - @tryghost/vhost-middleware@1.0.16
 - @tryghost/zip@1.1.15
2021-09-22 11:59:35 +02:00
Naz
ceb2b7e5ea Moved error messages to "messages" hash
refs https://linear.app/tryghost/issue/CORE-49/fix-errors-in-utils-repo-limit-service

- As I've touched these files did a little refactor and changed where the error messages are stored to keep it up with our lates coding standard - having "messages" hash defined in the module storing all messages that have pottential for i18y in the future.
2021-09-22 11:57:49 +02:00
Naz
ee43133dd9 Fixed error initialization syntax
refs https://linear.app/tryghost/issue/CORE-9/remove-eslint-warnings

- Used an incorrect string parameter constructor for ghost errors previously. The errors should be initialized with an object containing a "message" property
2021-09-22 11:51:37 +02:00
Naz
4b70c7e0c0 Removed use of native JS Error objects
closes https://linear.app/tryghost/issue/CORE-55/fix-errors-in-utils-repo-job-manager

- The latest ESLint rules forbid use of native JS errors, updated the codebase before bumping the ESLint version
2021-09-22 11:50:21 +02:00
Naz
be6c8ea390 Removed use of native JS Error objects
closes https://linear.app/tryghost/issue/CORE-54/fix-errors-in-utils-repo-release-utils

- The latest ESLint rules forbid use of native JS errors, updated the codebase before bumping the ESLint version
2021-09-22 11:49:02 +02:00
Naz
2b82d2afce Removed use of native JS Error objects
refs https://linear.app/tryghost/issue/CORE-49/fix-errors-in-utils-repo-limit-service

- The latest ESLint rules forbid use of native JS errors, updated the codebase before bumping the ESLint version
2021-09-22 11:32:02 +02:00
Renovate Bot
a28a2a23a5 Update dependency date-fns to v2.24.0 2021-09-17 07:39:17 +00:00
Renovate Bot
ced3a5251c Update dependency @sinonjs/fake-timers to v8 2021-09-15 11:49:45 +00:00
Renovate Bot
ff5ee78825 Update dependency c8 to v7.9.0 2021-09-10 04:03:35 +00:00
Renovate Bot
65760e061e Update dependency sharp to ^0.29.0 2021-08-23 09:13:58 +02:00
Renovate Bot
daab0d1f5d Update dependency supertest to v6.1.6 2021-08-17 22:28:32 +00:00
Renovate Bot
92a531cb9c Update dependency supertest to v6.1.5 2021-08-11 17:38:29 +00:00
Renovate Bot
2b7e2676eb Update dependency c8 to v7.8.0 2021-07-28 17:56:14 +00:00
Renovate Bot
798f7d1421 Update dependency date-fns to v2.23.0 2021-07-23 07:26:46 +00:00
Renovate Bot
0ad9fcf8dd Update dependency supertest to v6.1.4 2021-07-21 05:00:25 +00:00
Daniel Lockyer
1d6b8c1875 Stopped type declaration files from being generated
refs https://github.com/TryGhost/Team/issues/870

- currently, a handful of packages in this repo generate type
  declarations when building
- we're aiming to go more in the direction of better inline jsdoc, and
  we want to clean up all generated files and use of external types
- this commit removes the `typescript` dependency, removes the pretest
  commands that run the builds, and cleans up anywhere where we
  configure types
2021-07-14 11:51:14 +01:00
Daniel Lockyer
f918398779 Added c8 test coverage to all packages
refs https://github.com/TryGhost/Team/issues/870

- using `c8` allows us to see test coverage for all packages in the repo
- this commit adds `c8` as a dev dependency and prepends the `mocha`
  command with `c8` so it runs on all tests
2021-07-14 11:26:06 +01:00
Renovate Bot
9979768591 Update dependency @types/mocha to v8.2.3 2021-07-07 01:36:51 +00:00
Renovate Bot
950689fb35 Update dependency @types/express to v4.17.13 2021-07-06 21:26:50 +00:00
Renovate Bot
b56dc030ea Update dependency typescript to v4.3.5 2021-07-01 01:11:31 +00:00
Renovate Bot
895c93ad46 Update dependency typescript to v4.3.4 2021-06-17 18:53:56 +00:00
Renovate Bot
ec7805b7f0 Pin dependency c8 to 7.7.3 2021-06-17 13:57:17 +00:00
Hannah Wolfe
d259fcc4c6 Published new versions
- @tryghost/config-url-helpers@0.1.0
2021-06-17 14:55:21 +01:00
Hannah Wolfe
5b43d82742 Improved types in config-url-helpers 2021-06-17 13:53:09 +01:00
Hannah Wolfe
eb829a050b Prepared config-url-helpers for their intended use
- added getSubdir, getSiteUrl and getAdminUrl methods from url-utils
- refactored them so they are designed to be bound by nconf
- exposed a bindAll method
- moved over the tests and refactor from a class instance to nconf bindings
2021-06-17 11:41:50 +01:00
Sam Lord
320e689ad4 Published new versions
- @tryghost/adapter-manager@0.2.14
 - @tryghost/config-url-helpers@0.0.1
 - @tryghost/errors@0.2.13
 - @tryghost/image-transform@1.0.13
 - @tryghost/moleculer-service-from-class@0.2.17
 - @tryghost/mw-session-from-token@0.1.22
 - @tryghost/package-json@1.0.2
 - @tryghost/session-service@0.1.24
 - @tryghost/tpl@0.1.3
2021-06-17 10:50:39 +01:00
Sam Lord
095d64b449 Switch to ES6 classes for errors, use @tryghost/ignition errors
no issue

Replaces the usage of ghost-ignition with @tryghost/ignition-errors,
and switched to using the more modern ES6 class syntax over the
`.call(this, ...)` syntax used previously in both Ignition and here.
2021-06-17 10:26:19 +01:00
Renovate Bot
e8f7a4c158 Update dependency typescript to v4.3.3 2021-06-16 23:47:07 +00:00
Hannah Wolfe
3927c9002c Fixed merge error for deduplicate subdirectory
- tried to move history and fucked up git filter-repo :(
2021-06-16 20:22:06 +01:00
Hannah Wolfe
f98bcf150c Merged deduplicate subdirectory util from SDK/url-utils 2021-06-16 17:55:14 +01:00
Hannah Wolfe
0d965276a1 Added new config-url-helpers package
- This will contain a small number of helpers for getting correctly formatted urls from config
2021-06-16 17:54:30 +01:00
Renovate Bot
ede081837b Update dependency c8 to v7.7.3 2021-06-15 13:11:52 +00:00
Daniel Lockyer
939d4d9591 Published new versions
- @tryghost/package-json@1.0.1
 - @tryghost/tpl@0.1.2
2021-06-15 14:10:54 +01:00
Renovate Bot
8bed51c7aa Pin dependency c8 to v7.7.2 2021-06-15 10:05:23 +00:00
Daniel Lockyer
e14beeb7d2 Moved c8 to devDependencies
no issue

- `c8` is only used to check coverage in testing and we don't directly
  use it from within `tpl`, so this can be moved to `devDependencies`
2021-06-15 11:04:14 +01:00
Renovate Bot
f248f0d347 Update dependency c8 to v7.7.3 2021-06-14 00:31:49 +00:00
Hannah Wolfe
9eed5d69ef Published new versions
- @tryghost/package-json@1.0.0
 - @tryghost/tpl@0.1.1
2021-06-09 15:50:58 +01:00
Hannah Wolfe
1daa6eda61 Improved typing in package-json
- fixed type warnings
- introduced explicit use of bluebird to help with type warnings and also make it clear when we're actually using Bluebird features
2021-06-09 15:44:04 +01:00
Hannah Wolfe
93e4577caf Removed class pattern
- removed the class pattern in the simplest possible way
- have package-json expose only the public methods
- move parse to an independent, not public file so that we can test it independently still
2021-06-09 14:39:41 +01:00
Hannah Wolfe
dd129e0920 Removed use of i18n in package-json
- We are going to get rid of the internal i18n tool because it doesn't solve a real use case
- Instead, we have a new tpl utility that does basic string interpolation
- This makes this module less complex as it no longer requires dependency injection to work
2021-06-09 14:10:04 +01:00
Hannah Wolfe
224c6996f1 Added new tests & missing return type to tpl
- Ensuring that various strings from en.json will work
- Added missing return type
2021-06-09 12:25:45 +01:00
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
Hannah Wolfe
1a0436b540 Added ts-ignore for lodash interpolate
- ts complains the value may be undefined but in reality it never is
- plus we don't care about this error in this context as the test is checking that the value is set to its default
2021-06-09 12:00:07 +01:00
Hannah Wolfe
f2b1d37cd4 Renamed package-json tests to use .test.js pattern
- all our modules use .test.js instead of the _spec.js pattern we use in Ghost
- updated for consistency
2021-06-09 11:57:52 +01:00
Hannah Wolfe
202e0a0bb6 Added coverage reporting for tpl package
- this is 100% already
2021-06-09 11:57:52 +01:00
Renovate Bot
c72d090c97 Update dependency mocha to v9 2021-06-09 09:58:44 +00:00
Hannah Wolfe
6d3a629690 Added minimal tpl() template helper
- This mini helper wraps lodash template and supports `{...}` as the delimiters
- It's designed to use and support the exact same patterns we already have in our en.json strings
E.g. The {flagName} flag must be enabled in labs if you wish to use the \\{\\{{helperName}\\}\\} helper.
- This allows us to get rid of our old, broken i18n helper and still keep some of the smart messaging we have setup
- It also keeps the refactor surface area minimal
2021-06-09 10:04:49 +01:00
Renovate Bot
899e3fb0d8 Update dependency @types/sinon to v10.0.2 2021-06-02 08:02:37 +00:00
Renovate Bot
4fbd1ac31f Update dependency @sinonjs/fake-timers to v7.1.2 2021-05-28 15:50:34 +00:00
Renovate Bot
b47312607d Update dependency date-fns to v2.22.1 2021-05-28 12:23:22 +00:00
Renovate Bot
f35a07f4cb Update dependency date-fns to v2.22.0 2021-05-28 08:51:25 +00:00
Renovate Bot
2f926c740d Update dependency @sinonjs/fake-timers to v7.1.1 2021-05-27 11:58:34 +00:00
Renovate Bot
773991c1e6 Update dependency typescript to v4.3.2 2021-05-26 19:12:39 +00:00
Renovate Bot
24161773f3 Update dependency @types/sinon to v10.0.1 2021-05-25 20:31:28 +00:00
Renovate Bot
95e93b82b6 Update dependency @types/express to v4.17.12 2021-05-25 17:31:48 +00:00
Renovate Bot
80b56b8976 Update dependency sinon to v11 2021-05-24 22:37:15 +00:00
Renovate Bot
b71fe10342 Update dependency @sinonjs/fake-timers to v7.1.0 2021-05-21 13:51:02 +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
Thibaut Patel
4b92e67334 Published new versions
- @tryghost/session-service@0.1.22
2021-05-14 18:03:17 +02:00
Thibaut Patel
6bfefa02ac Added a CSRF bypass to enable OAuth
issue https://github.com/TryGhost/Team/issues/614
2021-05-14 17:38:33 +02: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
Renovate Bot
e6343c985f Update dependency date-fns to v2.21.3 2021-05-10 01:34:46 +00: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
Daniel Lockyer
a81d90b126 Added c8 coverage to package-json tests
no issue

- this commit adds the c8 dependency to the `package-json`, and prepends
  it to the test alias so we can see the coverage in tests
- note: we're apparently already at 100%!
2021-05-07 12:36:36 +01: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
131011fad4 Update dependency extract-zip to v2.0.1 2021-05-06 20:06:06 +00:00
Renovate Bot
8b576d501a Update dependency @types/express to v4.17.11 2021-05-06 18:16:07 +00:00
Renovate Bot
3d4e65ebc3 Pin dependency date-fns to 2.21.2 2021-05-06 16:14:06 +00:00
Daniel Lockyer
e0a966d6af Fixed package-json test requires
no issue

- these tests have just been extracted from Ghost so the paths are wrong
  and they're missing the global utils import
2021-05-06 15:16:29 +01:00
Daniel Lockyer
e74c682cba Added export for package-json library contents
no issue

- our code is already in the `lib` folder so we just need to export it
2021-05-06 15:16:29 +01:00
Daniel Lockyer
3f1462296e Added required dependencies for package-json
no issue

- this package has just been extracted from Ghost and we need to add the
  dependencies it uses into the `package.json`
2021-05-06 15:16:29 +01:00
Daniel Lockyer
d2d4bbe8ed Merged package-json files and history from TryGhost/Ghost 2021-05-06 15:16:29 +01:00
Daniel Lockyer
a0e2c4d45f Added initial package-json package
no issue

- this adds the templated package from Slimer ready for pulling the
  history in from Ghost
2021-05-06 15:16:29 +01: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
Daniel Lockyer
95cfa97747 Changed Error to IncorrectUsageError in package-json
no issue

- `Error` is very generic for this case and `IncorrectUsageError`
  will populate the resulting error with the correct error code
- the `message` was pulled out to its own statement so we can avoid long
  lines
2021-05-06 13:22:59 +01:00
Daniel Lockyer
eea93d55f4 Moved package-json wrapper outside implementation folder
no issue

- we're preparing the `package-json` lib to be extracted out of Ghost into
  its own package so moving the initialization wrapper outside of the
  folder makes the process a lot easier
2021-05-06 12:56:21 +01: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
Renovate Bot
84fa478e0f Update dependency date-fns to v2.21.2 2021-05-05 09:35:35 +00:00
Naz
a240582094 Fixed typos 2021-05-05 12:42:30 +04:00
Hannah Wolfe
e1b18aba2c Moved i18n to shared
refs 90ca836cb6

- i18n is used everywhere but only requires shared or external packages, therefore it's a good candidate for living in shared
- this reduces invalid requires across frontend and server, and lets us use it everywhere until we come up with a better option
2021-05-04 13:03:38 +01:00