@tryghost/limit-service 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/lib/LimitService.js +21 -0
- package/lib/limit.js +8 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -68,8 +68,12 @@ const limits = {
|
|
|
68
68
|
error: 'Your plan supports uploads of max size up to {{max}}. Please upgrade to reenable uploading.'
|
|
69
69
|
},
|
|
70
70
|
limitStripeConnect: {},
|
|
71
|
-
limitAnalytics: {
|
|
72
|
-
|
|
71
|
+
limitAnalytics: {
|
|
72
|
+
disabled: false
|
|
73
|
+
},
|
|
74
|
+
limitSocialWeb: {
|
|
75
|
+
disabled: true
|
|
76
|
+
}
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
// This information is needed for the limit service to work with "max periodic" limits
|
|
@@ -134,6 +138,16 @@ if (limitService.isLimited('uploads')) {
|
|
|
134
138
|
await limitService.errorIfIsOverLimit('uploads', {currentCount: frame.file.size});
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
// Limits expose an async `checkWouldGoOverLimit` method, which can be used to check whether a limit has been reached, but not throw an error:
|
|
142
|
+
if (await limitService.checkWouldGoOverLimit('members')) {
|
|
143
|
+
console.log('Members limit has been reached!');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Flag limits additionally expose a `isDisabled` sync check, which can be used instead of the async `checkWouldGoOverLimit`:
|
|
147
|
+
if (limitService.isDisabled('limitSocialWeb')) {
|
|
148
|
+
console.log('Social web is disabled by config!'));
|
|
149
|
+
}
|
|
150
|
+
|
|
137
151
|
// check if any of the limits are acceding
|
|
138
152
|
if (limitService.checkIfAnyOverLimit()) {
|
|
139
153
|
console.log('One of the limits has acceded!');
|
package/lib/LimitService.js
CHANGED
|
@@ -69,6 +69,27 @@ class LimitService {
|
|
|
69
69
|
return !!this.limits[camelCase(limitName)];
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Check if a limit is disabled, applicable only to limits that support the disabled flag (e.g. FlagLimit)
|
|
74
|
+
* @returns {boolean|undefined} undefined if limit is not configured
|
|
75
|
+
* @throws {IncorrectUsageError} if limit does not support disabled flag
|
|
76
|
+
*/
|
|
77
|
+
isDisabled(limitName) {
|
|
78
|
+
if (!this.isLimited(limitName)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const limit = this.limits[camelCase(limitName)];
|
|
83
|
+
|
|
84
|
+
if (typeof limit.isDisabled !== 'function') {
|
|
85
|
+
throw new IncorrectUsageError({
|
|
86
|
+
message: `Limit ${limitName} does not support .isDisabled()`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return limit.isDisabled();
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
/**
|
|
73
94
|
*
|
|
74
95
|
* @param {String} limitName - name of the configured limit
|
package/lib/limit.js
CHANGED
|
@@ -303,6 +303,14 @@ class FlagLimit extends Limit {
|
|
|
303
303
|
async errorIfIsOverLimit() {
|
|
304
304
|
return;
|
|
305
305
|
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Checks whether the Flag limit is disabled or not
|
|
309
|
+
* @returns boolean
|
|
310
|
+
*/
|
|
311
|
+
isDisabled() {
|
|
312
|
+
return !!this.disabled;
|
|
313
|
+
}
|
|
306
314
|
}
|
|
307
315
|
|
|
308
316
|
class AllowlistLimit extends Limit {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/limit-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/SDK.git",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"luxon": "^1.26.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "8d4cf3dfddc7c9fd6c499e672be94e64123b23bd"
|
|
38
38
|
}
|