Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
256 commits
Select commit Hold shift + click to select a range
118a20c
Added proper number formatting for error messages
ErisDS Mar 4, 2021
10558c0
Published new versions
ErisDS Mar 4, 2021
05d28f0
Changed casing of limit names + fixed handling
ErisDS Mar 4, 2021
0c063a7
Published new versions
ErisDS Mar 4, 2021
e0769c3
Updated readme with module description
naz Mar 31, 2021
0656c27
Added test coverage for max limit class
naz Apr 1, 2021
999cc1a
Added incorrect 'max' usage error to MaxLimit
naz Apr 1, 2021
eda26ec
Added JSDoc to MaxLimit constructor
naz Apr 1, 2021
69feda0
Added optional max limit override to errorIfWouldGoOverLimit
naz Apr 1, 2021
a9be63f
Grouped MaxLimit test cases into describe groups
naz Apr 1, 2021
61e190e
Added test coverage for is over limit check
naz Apr 1, 2021
0336118
Added optional max limit override to errorIfIsOverLimit
naz Apr 1, 2021
8d4ae05
Update Test & linting packages
renovate-bot Apr 1, 2021
3d60ba4
Added docs for limit service common ussecases
naz Apr 1, 2021
556aa58
Update dependency sinon to v10
renovate-bot Apr 1, 2021
c6c3933
Added JSDoc to loadLimits method
naz Apr 5, 2021
e5a378f
Added JSDoc to FlagLimit constructor
naz Apr 5, 2021
da08169
Removed ghost-ignition's errors dependency
naz Apr 5, 2021
c4443f1
Updated docs/examples with errors parameter
naz Apr 5, 2021
5e0cd6c
Fixed test missing a whitespace
naz Apr 5, 2021
37964f3
✨ Added custom count queries for "max" limits
naz Apr 6, 2021
a18c86d
Added docs for currentCountQuery usage
naz Apr 6, 2021
e83b3c2
Added test coverage for {{max}} and {{count}}
naz Apr 7, 2021
5fb3249
Published new versions
naz Apr 7, 2021
a7e18e9
Improved query formatting
naz Apr 7, 2021
2ca465d
Improved docs around {{max}} & {{count}}
naz Apr 7, 2021
63b5e6a
Added a test to confirm `isLimited` behavior of an unkown key
tpatel Apr 8, 2021
905fee4
Added allowlist limit (#144)
tpatel Apr 8, 2021
22ba564
Added a not to flag limit "errorIfIsOverLimit" method
naz Apr 9, 2021
b76dea5
Added a limit reset when loadLimits called repeatedly
naz Apr 9, 2021
8fff6b3
Unpinned all dependencies
daniellockyer Apr 16, 2021
29205a9
Pin dependencies
renovate-bot Apr 16, 2021
6062a5e
Published new versions
naz Apr 9, 2021
ca0b66e
Published new versions
daniellockyer Apr 19, 2021
d41410a
Added notes about how config module works
naz May 3, 2021
e6fab25
Fixed failing build
naz May 3, 2021
a334722
Added flag limit support for "emails"
naz May 3, 2021
45e7144
Added test coverage for flag type of limits
naz May 3, 2021
cc7a3e2
Published new versions
naz May 3, 2021
d4455ca
Fixed typos
naz May 5, 2021
464de40
Added "maxPeriodic" limit type
naz May 6, 2021
996fb0c
Added utility calculating date of last period start
naz May 6, 2021
6f2c037
Fixed IncorrectUsageError initialization
naz May 6, 2021
15f59a9
Added maxPeriodic limit support to limit service
naz May 6, 2021
e7e0777
Added currentCountQuery for emails limit
naz May 6, 2021
7e4ab00
Added added maxPeriodical checks
naz May 6, 2021
3e10ee5
Pin dependency date-fns to 2.21.2
renovate-bot May 6, 2021
c55701a
Clarified test name
naz May 7, 2021
a7330ad
Fixed time difference calculation in DST timezones
naz May 7, 2021
417f13e
Removed date-fns dev dependency
naz May 7, 2021
682536f
Published new versions
naz May 7, 2021
307c8aa
Fixed query counting total emails sent in a period
naz May 7, 2021
b4efc37
Added addedCount to max and maxPeriodic limits
naz May 7, 2021
d7e7494
Published new versions
naz May 7, 2021
3631821
Added emails limit to documentation example
naz May 11, 2021
f745d60
Added customThemes limit to config example
naz May 11, 2021
8fb691b
Added documentation for types of limits
naz May 11, 2021
36066cc
Added documentation for names of limits
naz May 11, 2021
7fff5ce
Added header to the section
naz May 11, 2021
fa06b37
Updated the example for the customThemes configuration
tpatel May 12, 2021
2614071
Exposed additional "name" variable in error templates
naz May 12, 2021
8fdb5b6
Published new versions
naz May 12, 2021
685b0a5
Added a convenience method checking if any limits are acceded
naz May 21, 2021
fe1757e
Fixed error "swallowing"
naz May 21, 2021
cb4cb80
Fixed indescribable error in allowlist limit
naz May 21, 2021
d8386e0
Published new versions
naz May 21, 2021
318daa6
Update dependency sinon to v11
renovate-bot May 24, 2021
5538cb4
Update dependency mocha to v9
renovate-bot Jun 9, 2021
26ff925
Published new versions
ErisDS Jun 9, 2021
fa8545b
Added c8 test coverage to all packages
daniellockyer Jul 14, 2021
f8a17b7
Update dependency c8 to v7.8.0
renovate-bot Jul 28, 2021
758e183
Update dependency c8 to v7.9.0
renovate-bot Sep 10, 2021
c9836dd
Removed use of native JS Error objects
naz Sep 22, 2021
62ec08c
Fixed error initialization syntax
naz Sep 22, 2021
38ef7ae
Moved error messages to "messages" hash
naz Sep 22, 2021
579d7f8
Published new versions
naz Sep 22, 2021
fd2d94b
Update Test & linting packages
renovate-bot Sep 22, 2021
128f5bb
Update dependency mocha to v9.1.2
renovate-bot Sep 27, 2021
cd7bf31
Published new versions
naz Sep 30, 2021
3faaa7e
Updated repository links
daniellockyer Oct 1, 2021
0d726f2
Published new versions
daniellockyer Oct 1, 2021
ef3ae14
Update dependency c8 to v7.10.0
renovate-bot Oct 6, 2021
f7b0a2c
Update dependency mocha to v9.1.3
renovate-bot Oct 15, 2021
216a11f
Added codecov.io coverage uploader to CI
daniellockyer Oct 20, 2021
b4b0695
Published new versions
naz Oct 22, 2021
90b6e6b
Improved test coverage for limit-service module
naz Oct 25, 2021
a0cf437
Fixed returned value type
naz Oct 26, 2021
1084f14
Added JSDoc with types to the Limit base constructor
naz Oct 26, 2021
994b65e
Fixed typos
naz Oct 26, 2021
5654f9a
Improved JSDocs in limit package
naz Oct 26, 2021
08bf0d3
Fixed uses ov currentCountQuery
naz Oct 26, 2021
fdf8a95
Improved JSDocs in limit package
naz Oct 26, 2021
df33326
Added ability to pass in "currentCount" for limited resource
naz Oct 26, 2021
6fc5203
Added "uploads" limit type
naz Oct 26, 2021
6a33555
Added custom formatter functionality to MaxLimit
naz Oct 26, 2021
5906b1a
Added custom formatter to uploads limit
naz Oct 26, 2021
5da66ca
Added missing "should" imports
naz Oct 26, 2021
11e4f1c
Updated JSDocs for limit-service module
naz Oct 26, 2021
827d6be
Published new versions
naz Oct 26, 2021
31f58af
Combine @tryghost/ignition-errors with @tryghost/errors
sam-lord Nov 30, 2021
0ef1cc7
Published new versions
sam-lord Nov 30, 2021
39713b7
Published new versions
sam-lord Nov 30, 2021
c02361a
Published new versions
sam-lord Nov 30, 2021
e19e568
Published new versions
sam-lord Nov 30, 2021
1a3e387
Published new versions
sam-lord Nov 30, 2021
0452be7
Published new versions
sam-lord Dec 1, 2021
03f6dbd
Published new versions
sam-lord Dec 6, 2021
c30cbd2
Published new versions
sam-lord Dec 14, 2021
0ca654f
Update dependency c8 to v7.11.0
renovate-bot Dec 30, 2021
82581e4
2022
JohnONolan Jan 6, 2022
8ef50fd
Published new versions
daniellockyer Jan 18, 2022
11f8cd7
Added `--all` flag to c8 commands
daniellockyer Feb 21, 2022
16a36eb
Published new versions
daniellockyer Mar 1, 2022
e2bdc9a
Update dependency c8 to v7.11.2
renovate-bot Apr 20, 2022
e1653ad
Published new versions
naz Apr 21, 2022
3686df0
Added newsletter flag to limits service
allouis Apr 27, 2022
71def6d
Published new versions
allouis Apr 27, 2022
14fd3e2
Update Test & linting packages
renovate-bot May 2, 2022
ea645bc
Update Test & linting packages
renovate-bot May 2, 2022
49391a0
Published new versions
naz May 4, 2022
032de16
Added currentCountQuery for newsletters
aileen May 4, 2022
c89bf5e
Published new versions
naz May 5, 2022
dc161cc
Update dependency sinon to v14
renovate-bot May 9, 2022
89d5ded
Published new versions
naz May 9, 2022
0b08b91
Added transaction support to limit-service (#190)
SimonBackx May 12, 2022
5aad44d
Published new versions
May 12, 2022
cc1d0aa
Update dependency c8 to v7.11.3
renovate-bot May 16, 2022
397163c
Published new versions
daniellockyer May 24, 2022
74b92ce
Update dependency c8 to v7.12.0
renovate[bot] Jul 19, 2022
1f518b0
Published new versions
naz Jul 22, 2022
1608d8d
Updated repository links
daniellockyer Jul 26, 2022
e5ac9ab
Published new versions
rshbhgrg Aug 5, 2022
ae42565
Update dependency sinon to v14.0.1
renovate[bot] Oct 3, 2022
c674e77
Update dependency mocha to v10.1.0
renovate[bot] Oct 17, 2022
9a4dfb6
Update Test & linting packages
renovate[bot] Nov 14, 2022
d6547e7
Update dependency sinon to v15
renovate[bot] Nov 28, 2022
5cdcc00
Published new versions
kevinansfield Nov 29, 2022
6fc4a86
Update dependency mocha to v10.2.0
renovate[bot] Dec 12, 2022
81d250b
Update dependency sinon to v15.0.1
renovate[bot] Dec 15, 2022
0208fc8
Update dependency c8 to v7.13.0
renovate[bot] Feb 16, 2023
ac48a2b
Published new versions
daniellockyer Mar 9, 2023
f7e2dba
Update Test & linting packages
renovate[bot] Mar 13, 2023
39df35a
Published new versions
kevinansfield Mar 15, 2023
403f8aa
Update dependency sinon to v15.0.3
renovate[bot] Mar 27, 2023
ebfc93c
Published new versions
naz Apr 12, 2023
a8d643a
Update dependency sinon to v15.0.4
renovate[bot] Apr 20, 2023
2c8fe7f
Published new versions
daniellockyer May 8, 2023
18c38f8
2023
JohnONolan Aug 3, 2023
c086607
Bumped minimum version of `@tryghost/errors`
daniellockyer Sep 8, 2023
81edd56
Published new versions
daniellockyer Sep 8, 2023
0ed9c2b
Removed use of `lodash` import in favor of specific functions
daniellockyer Sep 8, 2023
a9aad75
Published new versions
daniellockyer Sep 8, 2023
5179fe1
Updated timezone-data package to use TypeScript (#480)
binary-koan Oct 26, 2023
15a76fc
Published new versions
binary-koan Oct 26, 2023
9398a3b
Update Test & linting packages
renovate[bot] Oct 26, 2023
210b956
Update Test & linting packages
renovate[bot] Oct 26, 2023
de9648e
Published new versions
binary-koan Oct 30, 2023
8324483
Update Test & linting packages
renovate[bot] Nov 1, 2023
ac7dd8b
Published new versions
9larsons Nov 15, 2023
cb9b669
Update dependency c8 to v9
renovate[bot] Jan 3, 2024
713b8c2
Update dependency c8 to v9.1.0
renovate[bot] Jan 12, 2024
ea9deec
Update dependency mocha to v10.3.0
renovate[bot] Feb 8, 2024
224ffe1
Update dependency mocha to v10.4.0
renovate[bot] Mar 27, 2024
ab56869
Published new versions
mike182uk Apr 25, 2024
70190b5
Update dependency sinon to v17.0.2
renovate[bot] May 7, 2024
cbec677
Update dependency sinon to v18
renovate[bot] May 15, 2024
f7c2ce8
Update dependency c8 to v10
renovate[bot] Jun 10, 2024
6c9bcd6
Update dependency c8 to v10.1.1
renovate[bot] Jun 12, 2024
f8ae1d5
Update dependency c8 to v10.1.2
renovate[bot] Jun 13, 2024
abc0c05
Update dependency mocha to v10.5.0
renovate[bot] Jun 24, 2024
e1454d1
Update dependency mocha to v10.5.1
renovate[bot] Jun 25, 2024
e489c6f
Update dependency mocha to v10.5.2
renovate[bot] Jun 26, 2024
dafbe75
Update dependency mocha to v10.6.0
renovate[bot] Jul 2, 2024
86be9d6
Update Test & linting packages
renovate[bot] Jul 22, 2024
404854e
Update dependency mocha to v10.7.3
renovate[bot] Aug 9, 2024
9abcc91
Update dependency sinon to v18.0.1
renovate[bot] Sep 10, 2024
5d1c8e5
Update dependency sinon to v19
renovate[bot] Sep 13, 2024
d61ae00
Update dependency sinon to v19.0.2
renovate[bot] Sep 13, 2024
569cb28
Update dependency mocha to v10.8.1
renovate[bot] Oct 29, 2024
f1be24e
Update dependency mocha to v10.8.2
renovate[bot] Oct 30, 2024
c00419c
Update dependency mocha to v11
renovate[bot] Dec 2, 2024
85acd7a
Update dependency c8 to v10.1.3
renovate[bot] Dec 10, 2024
30d6cd1
2025
JohnONolan Jan 6, 2025
e80a48d
Update dependency mocha to v11.1.0
renovate[bot] Jan 22, 2025
76793a8
Update dependency sinon to v19.0.4
renovate[bot] Mar 19, 2025
6a05194
Update dependency sinon to v19.0.5
renovate[bot] Mar 24, 2025
d8d206a
Update dependency sinon to v20
renovate[bot] Mar 25, 2025
e6cefc9
Published new versions
ronaldlangeveld Apr 16, 2025
add9904
Update dependency mocha to v11.2.2
renovate[bot] May 1, 2025
3040041
Published new versions
daniellockyer May 12, 2025
18ccd1c
Published new versions
daniellockyer May 12, 2025
75590f1
Updated repository in package.json
ErisDS May 18, 2025
d928f81
Published new versions
ErisDS May 25, 2025
94d3b45
Update dependency sinon to v21
renovate[bot] Jun 13, 2025
1842240
Removed `currentCountQuery` from limit service config for `customInte…
aileen Jun 25, 2025
e6650e6
Added new limits to Limit-Service config (#539)
aileen Jun 25, 2025
4f31cdd
Added CLAUDE.md file for AI assistant guidance
aileen Jun 25, 2025
f2653ab
Published new versions
9larsons Jun 25, 2025
165a5e0
Added currentCountQuery support for flag limits to grandfather usage
aileen Jun 25, 2025
29ce0b3
Removed `currentCountQuery` from `limitAnalytics`
aileen Jun 25, 2025
8a0afd8
Published new versions
aileen Jun 26, 2025
9a5a0b7
Renamed `limitActivityPub` to `limitSocialWeb`
aileen Jun 26, 2025
200767c
Published new versions
aileen Jun 26, 2025
11eed88
Reverted currentCountQuery support for flag limits
aileen Jun 27, 2025
f0e9c2e
Published new versions
aileen Jun 27, 2025
3ec7c95
Added .isDisabled() method to the Limit Service (#550)
sagzy Jul 8, 2025
8d96332
Published new versions (#560)
sagzy Jul 8, 2025
b7990b1
Published new versions
kevinansfield Jul 22, 2025
842098e
Update dependency mocha to v11.7.2 (#547)
renovate[bot] Sep 1, 2025
33b128b
Update dependency mocha to v11.7.3 (#628)
renovate[bot] Sep 30, 2025
023bfb6
Update dependency mocha to v11.7.4 (#631)
renovate[bot] Oct 2, 2025
9ba10e6
Update dependency mocha to v11.7.5 (#672)
renovate[bot] Nov 5, 2025
43756cc
Published new versions
allouis Nov 19, 2025
d5b1fa3
Published new versions
vershwal Nov 19, 2025
49ceb29
Pin dependency @tryghost/errors to 1.3.8 (#706)
renovate[bot] Nov 24, 2025
76af78b
Published new versions
vershwal Dec 17, 2025
f0049dd
Update dependency sinon to v21.0.1 (#729)
renovate[bot] Dec 22, 2025
4ef7d5c
Published new versions
rob-ghost Jan 12, 2026
0daa244
2026
JohnONolan Jan 21, 2026
0a48b85
Update dependency @tryghost/errors to v1.3.9 (#766)
renovate[bot] Feb 12, 2026
0ffb224
Update dependency @tryghost/errors to v1.3.10 (#772)
renovate[bot] Feb 20, 2026
4cc837e
Update dependency @tryghost/errors to v1.3.13 (#773)
renovate[bot] Feb 21, 2026
29e8bb4
Enforce test coverage thresholds across all packages (#776)
vershwal Feb 24, 2026
d643869
Enforce 100% line coverage threshold across all packages (#777)
vershwal Feb 24, 2026
943d54c
Pin dependencies (#707)
renovate[bot] Feb 24, 2026
6a35d8e
Update dependency luxon to v3 (#439)
renovate[bot] Feb 24, 2026
b682e13
Update dependency @tryghost/errors to v2 (#774)
renovate[bot] Feb 24, 2026
287b210
Update dependency c8 to v11 (#789)
renovate[bot] Feb 25, 2026
90fe96d
Published new versions
vershwal Feb 26, 2026
7a5b7d0
Published new versions
vershwal Feb 26, 2026
6638427
Update dependency sinon to v21.0.2 (#809)
renovate[bot] Mar 7, 2026
9abfbd4
Published new versions
cmraible Mar 18, 2026
059d4c4
Update dependency sinon to v21.0.3 (#828)
renovate[bot] Mar 19, 2026
3a0b57f
Update dependency lodash to v4.18.1 [SECURITY] (#847)
renovate[bot] Apr 2, 2026
9d423ac
Update dependency sinon to v21.1.0 (#865)
renovate[bot] Apr 12, 2026
6d72f3a
Update dependency sinon to v21.1.1 (#867)
renovate[bot] Apr 13, 2026
9506585
Update dependency sinon to v21.1.2 (#869)
renovate[bot] Apr 15, 2026
5360f3a
Published new versions
mike182uk Apr 27, 2026
bab4747
Update dependency sinon to v22 (#903)
renovate[bot] May 8, 2026
3ee1fc2
Published new versions
sam-lord May 12, 2026
fdb657c
Added publicSiteAccess flag limit (#918)
ErisDS May 15, 2026
3da593c
Published new versions
ErisDS May 15, 2026
b2963dc
Update dependency mocha to v11.7.6 (#928)
renovate[bot] May 24, 2026
c38c7de
Published new versions
9larsons Jun 8, 2026
91b4e24
Update dependency c8 to v12 (#1009)
renovate[bot] Jul 17, 2026
d5656c8
Update dependency sinon to v22.1.0 (#989)
renovate[bot] Jul 23, 2026
af752ec
Update dependency mocha to v11.8.0 (#1040)
renovate[bot] Aug 6, 2026
1c45566
Update dependency mocha to v12 (#1066)
renovate[bot] Sep 3, 2026
91d98b2
Add 'packages/limit-service/' from commit '1c455660017aa94f2943729934…
rob-ghost Sep 8, 2026
b204579
Wired the imported limit-service into the workspace
rob-ghost Sep 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,6 @@
],
},

// Bump @tryghost/limit-service on its own. Limit changes are feature-tied
// (each new flag is consumed by specific BREAD/limit-helper code) and we
// want the version bump landing as an isolated, reviewable PR rather than
// riding in with unrelated admin-support package updates.
{
groupName: '@tryghost/limit-service',
matchPackageNames: ['@tryghost/limit-service'],
},
{
groupName: 'TryGhost content and email packages',
matchPackageNames: [
Expand Down
4 changes: 4 additions & 0 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
// The imported limit-service documentation is kept exactly as it arrived from
// TryGhost/SDK so it can be diffed against the source. It is linted once it is
// rewritten alongside the package.
"ignores": ["packages/limit-service/**"],
"config": {
"default": false,
"MD011": true,
Expand Down
1 change: 1 addition & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"koenig/kg-simplemde/debug/**",
"koenig/koenig-lexical/**",
"packages/i18n/locales/**",
"packages/limit-service/**",
".changeset/ledger.yaml"
]
}
2 changes: 1 addition & 1 deletion apps/admin-x-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"dependencies": {
"@sentry/react": "catalog:",
"@tanstack/react-query": "catalog:",
"@tryghost/limit-service": "catalog:",
"@tryghost/limit-service": "workspace:*",
"@tryghost/metafield-types": "workspace:*",
"@tryghost/nql-string": "workspace:*",
"@tryghost/shade": "workspace:*",
Expand Down
6 changes: 5 additions & 1 deletion apps/admin/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export default defineConfig(({ command }) => ({
// forwardConsole: { logLevels: ['warn', 'error'] }
},
optimizeDeps: {
include: ['@tryghost/koenig-lexical'],
// limit-service is CommonJS, and Vite only converts CommonJS while pre-bundling. A
// workspace package is treated as source and served raw, where `module` does not exist,
// so the import fails and the limiter silently falls back to reporting every host limit
// as absent. Force it through the pre-bundler until the package itself is converted.
include: ['@tryghost/koenig-lexical', '@tryghost/limit-service'],
},
resolve: sharedResolve,
test: {
Expand Down
5 changes: 5 additions & 0 deletions apps/admin/vitest.acceptance.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default defineConfig({
// suite. Test files and screen helpers import test-lane modules the
// browser bundler can't process; vitest serves those itself.
entries: ['src/**/*.{ts,tsx}', '!src/**/*.test.*', '!src/**/*.screen.ts'],
// limit-service is CommonJS, and Vite only converts CommonJS while pre-bundling. A
// workspace package is treated as source and served raw, where `module` does not exist,
// so the import fails and the limiter silently falls back to reporting every host limit
// as absent. Force it through the pre-bundler until the package itself is converted.
include: ['@tryghost/limit-service'],
},
resolve: sharedResolve,
test: {
Expand Down
2 changes: 1 addition & 1 deletion apps/ember-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@tryghost/kg-clean-basic-html": "workspace:*",
"@tryghost/kg-converters": "workspace:*",
"@tryghost/koenig-lexical": "workspace:*",
"@tryghost/limit-service": "catalog:",
"@tryghost/limit-service": "workspace:*",
"@tryghost/nql": "catalog:",
"@tryghost/nql-string": "workspace:*",
"@tryghost/string": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"@tryghost/kg-html-to-lexical": "workspace:*",
"@tryghost/kg-lexical-html-renderer": "workspace:*",
"@tryghost/kg-markdown-html-renderer": "workspace:*",
"@tryghost/limit-service": "catalog:",
"@tryghost/limit-service": "workspace:*",
"@tryghost/logging": "catalog:",
"@tryghost/metafield-types": "workspace:*",
"@tryghost/metrics": "catalog:",
Expand Down
6 changes: 6 additions & 0 deletions packages/limit-service/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: ['ghost'],
extends: [
'plugin:ghost/node'
]
};
92 changes: 92 additions & 0 deletions packages/limit-service/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Common Development Commands

### Testing
- **Run all tests with coverage**: `npm test`
- **Run a specific test file**: `NODE_ENV=testing mocha './test/limit.test.js'`
- **Run tests matching a pattern**: `NODE_ENV=testing mocha './test/**/*.test.js' --grep "MaxLimit"`
- **Run tests with coverage report**: `NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'`

### Linting
- **Run ESLint**: `npm run lint`
- **Fix linting issues**: `npm run lint -- --fix`

### Development
- **Note**: There is no dev script currently implemented (placeholder exists)

## High-Level Architecture

The limit-service is a centralized limit enforcement system for Ghost that follows clean architecture principles:

### Core Components

1. **LimitService** (`lib/LimitService.js`): Main service class that acts as a facade for all limit operations. It creates and manages different limit types based on configuration.

2. **Limit Types** (`lib/limit.js`):
- **MaxLimit**: Enforces maximum counts (e.g., max 5 staff users)
- **MaxPeriodicLimit**: Enforces limits over time periods (e.g., max emails per month)
- **FlagLimit**: On/off feature toggles
- **AllowlistLimit**: Restricts values to an allowed list

3. **Configuration** (`lib/config.js`): Defines supported limits and their properties. Each limit can specify:
- `type`: The limit type to use
- `fallbackErrorMessage`: Default error message
- `currentCountQuery`: Database query function for count-based limits

### Key Architectural Patterns

- **Strategy Pattern**: Different limit types implement a common interface (`checkIsOverLimit`, `checkWouldGoOverLimit`)
- **Dependency Injection**: Database connection, errors handler, and configuration are injected at initialization
- **Transaction Support**: All database operations can be wrapped in transactions via `options.transacting`

### Adding New Limits

1. Add the limit configuration in `lib/config.js`:
```javascript
newFeature: {
type: 'max', // or 'flag', 'allowlist'
fallbackErrorMessage: 'Default error for {{name}} limit',
currentCountQuery: async (db, options) => {
// Return current count from database
}
}
```

2. Test the new limit following existing patterns in `test/`

### Testing Approach

- Uses Mocha with Should.js for assertions
- Sinon for mocking database queries and date/time
- Tests focus on behavior, not implementation
- Mock database responses to test limit logic in isolation

### Database Integration

- Expects a Knex instance for database queries
- All queries support transactions
- Count queries should return a number or be convertible to a number
- For periodic limits, queries receive `startDate` and `endDate` parameters

### Error Handling

- Uses `@tryghost/errors` for consistent error formatting
- Supports template variables in error messages: `{{max}}`, `{{count}}`, `{{name}}`
- All limits have fallback error messages
- Numbers in error messages are formatted with toLocaleString()

### Key Methods Flow

1. `loadLimits()`: Initializes the service with configuration
2. `isLimited()`: Checks if a limit is configured
3. `errorIfWouldGoOverLimit()`: Throws if action would exceed limit
4. `errorIfIsOverLimit()`: Throws if already over limit
5. `checkIsOverLimit()`: Returns boolean for limit status
6. `checkWouldGoOverLimit()`: Returns boolean for potential limit breach

### Environment Variable

- Set `NODE_ENV=testing` when running tests
21 changes: 21 additions & 0 deletions packages/limit-service/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013-2026 Ghost Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading