Skip to content

Commit 4473f74

Browse files
authored
Added new limits to Limit-Service config (#539)
closes BAE-331 We're introducing 3 new limits, which Ghost need to be aware of through the Limit-Service: - `limitStripeConnect` - `limitAnalytics` - `limitActivityPub` This adds those limits to the config, allowing them to be passed through to Ghost and being available for limit checks. All of the new limits are `Flag` type limits and don't require a `currentCountQuery`.
1 parent 310b061 commit 4473f74

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

packages/limit-service/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const LimitService = require('@tryghost/limit-service');
2525
const limitService = new LimitService();
2626

2727
// setup limit configuration
28-
// currently supported limit keys are: staff, members, customThemes, customIntegrations, uploads
28+
// currently supported limit keys are: staff, members, customThemes, customIntegrations, uploads,
29+
// limitStripeConnect, limitAnalytics, and limitActivityPub
2930
// all limit configs support custom "error" configuration that is a template string
3031
const limits = {
3132
// staff and member are "max" type of limits accepting "max" configuration
@@ -65,7 +66,10 @@ const limits = {
6566
max: 5000000,
6667
// formatting of the {{ max }} vairable is in MB, e.g: 5MB
6768
error: 'Your plan supports uploads of max size up to {{max}}. Please upgrade to reenable uploading.'
68-
}
69+
},
70+
limitStripeConnect: {},
71+
limitAnalytics: {},
72+
limitActivityPub: {}
6973
};
7074

7175
// This information is needed for the limit service to work with "max periodic" limits
@@ -160,9 +164,9 @@ At the moment there are four different types of limits that limit service allows
160164
4. `allowList` - checks if provided value is defined in configured "allowlist". Example usecase: "disable theme activation if it is not an official theme". To configure this limit define ` allowlist: ['VALUE_1', 'VALUE_2', 'VALUE_N']` property in the "limits" parameter.
161165

162166
### Supported limits
163-
There's a limited amount of limits that are supported by limit service. The are defined by "key" property name in the "config" module. List of currently supported limit names: `members`, `staff`, `customIntegrations`, `emails`, `customThemes`, `uploads`.
167+
There's a limited amount of limits that are supported by limit service. The are defined by "key" property name in the "config" module. List of currently supported limit names: `members`, `staff`, `customIntegrations`, `emails`, `customThemes`, `uploads`, `limitStripeConnect`, `limitAnalytics`, and `limitActivityPub`.
164168

165-
All limits can act as `flag` or `allowList` types. Only certain (`members`, `staff`, and`customIntegrations`) can have a `max` limit. Only `emails` currently supports the `maxPeriodic` type of limit.
169+
All limits can act as `flag` or `allowList` types. Only certain (`members`, `staff`) can have a `max` limit. Only `emails` currently supports the `maxPeriodic` type of limit.
166170

167171
### Frontend usage
168172
In case the limit check is run without direct access to the database you can override `currentCountQuery` functions for each "max" or "maxPeriodic" type of limit. An example usecase would be a frontend client running in a browser. A browser client can check the limit data through HTTP request and then provide that data to the limit service. Example code to do exactly that:

packages/limit-service/lib/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ module.exports = {
5555
// NOTE: the uploads limit is based on file sizes provided in Bytes
5656
// a custom formatter is here for more user-friendly formatting when forming an error
5757
formatter: count => `${count / 1000000}MB`
58-
}
58+
},
59+
limitStripeConnect: {},
60+
limitAnalytics: {},
61+
limitActivityPub: {}
5962
};

packages/limit-service/lib/limit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ class FlagLimit extends Limit {
269269
*/
270270
constructor({name, config, helpLink, db, errors}) {
271271
super({name, error: config.error || '', helpLink, db, errors});
272+
const userFacingLimitName = lowerCase(name.replace(/^limit/, ''));
272273

273274
this.disabled = config.disabled;
274-
this.fallbackMessage = `Your plan does not support ${lowerCase(this.name)}. Please upgrade to enable ${lowerCase(this.name)}.`;
275+
this.fallbackMessage = `Your plan does not support ${userFacingLimitName}. Please upgrade to enable ${userFacingLimitName}.`;
275276
}
276277

277278
generateError() {

packages/limit-service/test/limit.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Limit Service', function () {
2525
const config = {
2626
disabled: true
2727
};
28-
const limit = new FlagLimit({name: 'flaggy', config, errors});
28+
const limit = new FlagLimit({name: 'limitFlaggy', config, errors});
2929

3030
try {
3131
await limit.errorIfWouldGoOverLimit();
@@ -37,7 +37,7 @@ describe('Limit Service', function () {
3737
should.equal(err.errorType, 'HostLimitError');
3838

3939
should.exist(err.errorDetails);
40-
should.equal(err.errorDetails.name, 'flaggy');
40+
should.equal(err.errorDetails.name, 'limitFlaggy');
4141

4242
should.exist(err.message);
4343
should.equal(err.message, 'Your plan does not support flaggy. Please upgrade to enable flaggy.');

0 commit comments

Comments
 (0)