@budibase/backend-core 2.21.2 → 2.21.4
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/dist/index.js +68 -57
- package/dist/index.js.map +3 -3
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +6 -5
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/cache/base/index.d.ts +1 -1
- package/dist/src/cache/generic.d.ts +1 -1
- package/dist/src/cache/user.js.map +1 -1
- package/dist/src/db/Replication.d.ts +13 -25
- package/dist/src/db/Replication.js +18 -33
- package/dist/src/db/Replication.js.map +1 -1
- package/dist/src/redis/redis.d.ts +9 -5
- package/dist/src/redis/redis.js +46 -3
- package/dist/src/redis/redis.js.map +1 -1
- package/dist/src/redis/redlockImpl.js.map +1 -1
- package/dist/src/security/roles.d.ts +9 -10
- package/dist/src/security/roles.js +15 -18
- package/dist/src/security/roles.js.map +1 -1
- package/dist/tests/core/utilities/structures/accounts.js +1 -1
- package/dist/tests/core/utilities/structures/accounts.js.map +1 -1
- package/dist/tests/core/utilities/structures/scim.js +1 -1
- package/dist/tests/core/utilities/structures/scim.js.map +1 -1
- package/package.json +6 -5
- package/src/cache/user.ts +2 -2
- package/src/db/Replication.ts +27 -40
- package/src/redis/redis.ts +58 -9
- package/src/redis/redlockImpl.ts +1 -1
- package/src/redis/tests/redis.spec.ts +214 -0
- package/src/security/roles.ts +27 -35
- package/tests/core/utilities/structures/accounts.ts +1 -1
- package/tests/core/utilities/structures/scim.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -57055,21 +57055,16 @@ async function queryGlobalViewRaw(viewName, params2, opts) {
|
|
|
57055
57055
|
|
|
57056
57056
|
// src/db/Replication.ts
|
|
57057
57057
|
var Replication = class {
|
|
57058
|
-
/**
|
|
57059
|
-
*
|
|
57060
|
-
* @param source - the DB you want to replicate or rollback to
|
|
57061
|
-
* @param target - the DB you want to replicate to, or rollback from
|
|
57062
|
-
*/
|
|
57063
57058
|
constructor({ source, target }) {
|
|
57064
57059
|
this.source = getPouchDB(source);
|
|
57065
57060
|
this.target = getPouchDB(target);
|
|
57066
57061
|
}
|
|
57067
|
-
close() {
|
|
57068
|
-
|
|
57062
|
+
async close() {
|
|
57063
|
+
await Promise.all([closePouchDB(this.source), closePouchDB(this.target)]);
|
|
57069
57064
|
}
|
|
57070
|
-
|
|
57065
|
+
replicate(opts = {}) {
|
|
57071
57066
|
return new Promise((resolve) => {
|
|
57072
|
-
|
|
57067
|
+
this.source.replicate.to(this.target, opts).on("denied", function(err) {
|
|
57073
57068
|
throw new Error(`Denied: Document failed to replicate ${err}`);
|
|
57074
57069
|
}).on("complete", function(info) {
|
|
57075
57070
|
return resolve(info);
|
|
@@ -57078,29 +57073,22 @@ var Replication = class {
|
|
|
57078
57073
|
});
|
|
57079
57074
|
});
|
|
57080
57075
|
}
|
|
57081
|
-
|
|
57082
|
-
|
|
57083
|
-
|
|
57084
|
-
|
|
57085
|
-
|
|
57086
|
-
|
|
57087
|
-
return this.replication;
|
|
57088
|
-
}
|
|
57089
|
-
/**
|
|
57090
|
-
* One way replication operation, intended to be promise based.
|
|
57091
|
-
* @param opts - PouchDB replication options
|
|
57092
|
-
*/
|
|
57093
|
-
replicate(opts = {}) {
|
|
57094
|
-
this.replication = this.promisify(this.source.replicate.to, opts);
|
|
57095
|
-
return this.replication;
|
|
57096
|
-
}
|
|
57097
|
-
appReplicateOpts() {
|
|
57076
|
+
appReplicateOpts(opts = {}) {
|
|
57077
|
+
if (typeof opts.filter === "string") {
|
|
57078
|
+
return opts;
|
|
57079
|
+
}
|
|
57080
|
+
const filter = opts.filter;
|
|
57081
|
+
delete opts.filter;
|
|
57098
57082
|
return {
|
|
57099
|
-
|
|
57083
|
+
...opts,
|
|
57084
|
+
filter: (doc, params2) => {
|
|
57100
57085
|
if (doc._id && doc._id.startsWith("log_au" /* AUTOMATION_LOG */)) {
|
|
57101
57086
|
return false;
|
|
57102
57087
|
}
|
|
57103
|
-
|
|
57088
|
+
if (doc._id === "app_metadata" /* APP_METADATA */) {
|
|
57089
|
+
return false;
|
|
57090
|
+
}
|
|
57091
|
+
return filter ? filter(doc, params2) : true;
|
|
57104
57092
|
}
|
|
57105
57093
|
};
|
|
57106
57094
|
}
|
|
@@ -57112,9 +57100,6 @@ var Replication = class {
|
|
|
57112
57100
|
this.target = getPouchDB(this.target.name);
|
|
57113
57101
|
await this.replicate();
|
|
57114
57102
|
}
|
|
57115
|
-
cancel() {
|
|
57116
|
-
this.replication.cancel();
|
|
57117
|
-
}
|
|
57118
57103
|
};
|
|
57119
57104
|
var Replication_default = Replication;
|
|
57120
57105
|
|
|
@@ -58676,7 +58661,10 @@ var RedisWrapper = class {
|
|
|
58676
58661
|
let node = this.getClient().nodes("master");
|
|
58677
58662
|
stream2 = node[0].scanStream({ match: key + "*", count: 100 });
|
|
58678
58663
|
} else {
|
|
58679
|
-
stream2 = this.getClient().scanStream({
|
|
58664
|
+
stream2 = this.getClient().scanStream({
|
|
58665
|
+
match: key + "*",
|
|
58666
|
+
count: 100
|
|
58667
|
+
});
|
|
58680
58668
|
}
|
|
58681
58669
|
return promisifyStream(stream2, this.getClient());
|
|
58682
58670
|
}
|
|
@@ -58690,7 +58678,7 @@ var RedisWrapper = class {
|
|
|
58690
58678
|
}
|
|
58691
58679
|
async get(key) {
|
|
58692
58680
|
const db = this._db;
|
|
58693
|
-
|
|
58681
|
+
const response = await this.getClient().get(addDbPrefix(db, key));
|
|
58694
58682
|
if (response != null && response.key) {
|
|
58695
58683
|
response.key = key;
|
|
58696
58684
|
}
|
|
@@ -58738,6 +58726,21 @@ var RedisWrapper = class {
|
|
|
58738
58726
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
58739
58727
|
}
|
|
58740
58728
|
}
|
|
58729
|
+
async bulkStore(data, expirySeconds = null) {
|
|
58730
|
+
const client = this.getClient();
|
|
58731
|
+
const dataToStore = Object.entries(data).reduce((acc, [key, value]) => {
|
|
58732
|
+
acc[addDbPrefix(this._db, key)] = typeof value === "object" ? JSON.stringify(value) : value;
|
|
58733
|
+
return acc;
|
|
58734
|
+
}, {});
|
|
58735
|
+
const pipeline = client.pipeline();
|
|
58736
|
+
pipeline.mset(dataToStore);
|
|
58737
|
+
if (expirySeconds !== null) {
|
|
58738
|
+
for (const key of Object.keys(dataToStore)) {
|
|
58739
|
+
pipeline.expire(key, expirySeconds);
|
|
58740
|
+
}
|
|
58741
|
+
}
|
|
58742
|
+
await pipeline.exec();
|
|
58743
|
+
}
|
|
58741
58744
|
async getTTL(key) {
|
|
58742
58745
|
const db = this._db;
|
|
58743
58746
|
const prefixedKey = addDbPrefix(db, key);
|
|
@@ -58756,6 +58759,22 @@ var RedisWrapper = class {
|
|
|
58756
58759
|
let items = await this.scan();
|
|
58757
58760
|
await Promise.all(items.map((obj) => this.delete(obj.key)));
|
|
58758
58761
|
}
|
|
58762
|
+
async increment(key) {
|
|
58763
|
+
const result = await this.getClient().incr(addDbPrefix(this._db, key));
|
|
58764
|
+
if (isNaN(result)) {
|
|
58765
|
+
throw new Error(`Redis ${key} does not contain a number`);
|
|
58766
|
+
}
|
|
58767
|
+
return result;
|
|
58768
|
+
}
|
|
58769
|
+
async deleteIfValue(key, value) {
|
|
58770
|
+
const client = this.getClient();
|
|
58771
|
+
const luaScript = `
|
|
58772
|
+
if redis.call('GET', KEYS[1]) == ARGV[1] then
|
|
58773
|
+
redis.call('DEL', KEYS[1])
|
|
58774
|
+
end
|
|
58775
|
+
`;
|
|
58776
|
+
await client.eval(luaScript, 1, addDbPrefix(this._db, key), value);
|
|
58777
|
+
}
|
|
58759
58778
|
};
|
|
58760
58779
|
var redis_default = RedisWrapper;
|
|
58761
58780
|
|
|
@@ -60005,14 +60024,13 @@ var roles_exports = {};
|
|
|
60005
60024
|
__export(roles_exports, {
|
|
60006
60025
|
AccessController: () => AccessController,
|
|
60007
60026
|
BUILTIN_ROLE_IDS: () => BUILTIN_ROLE_IDS,
|
|
60008
|
-
BUILTIN_ROLE_ID_ARRAY: () => BUILTIN_ROLE_ID_ARRAY,
|
|
60009
|
-
BUILTIN_ROLE_NAME_ARRAY: () => BUILTIN_ROLE_NAME_ARRAY,
|
|
60010
60027
|
Role: () => Role,
|
|
60011
60028
|
RoleIDVersion: () => RoleIDVersion,
|
|
60012
60029
|
builtinRoleToNumber: () => builtinRoleToNumber,
|
|
60013
60030
|
checkForRoleResourceArray: () => checkForRoleResourceArray,
|
|
60014
60031
|
getAllRoleIds: () => getAllRoleIds,
|
|
60015
60032
|
getAllRoles: () => getAllRoles,
|
|
60033
|
+
getBuiltinRole: () => getBuiltinRole,
|
|
60016
60034
|
getBuiltinRoles: () => getBuiltinRoles,
|
|
60017
60035
|
getDBRoleID: () => getDBRoleID,
|
|
60018
60036
|
getExternalRoleID: () => getExternalRoleID,
|
|
@@ -60231,19 +60249,19 @@ var BUILTIN_ROLES = {
|
|
|
60231
60249
|
function getBuiltinRoles() {
|
|
60232
60250
|
return (0, import_cloneDeep2.default)(BUILTIN_ROLES);
|
|
60233
60251
|
}
|
|
60234
|
-
var BUILTIN_ROLE_ID_ARRAY = Object.values(BUILTIN_ROLES).map(
|
|
60235
|
-
(role) => role._id
|
|
60236
|
-
);
|
|
60237
|
-
var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
|
|
60238
|
-
(role) => role.name
|
|
60239
|
-
);
|
|
60240
60252
|
function isBuiltin(role) {
|
|
60241
|
-
return
|
|
60253
|
+
return getBuiltinRole(role) !== void 0;
|
|
60242
60254
|
}
|
|
60243
|
-
function
|
|
60244
|
-
|
|
60245
|
-
|
|
60255
|
+
function getBuiltinRole(roleId) {
|
|
60256
|
+
const role = Object.values(BUILTIN_ROLES).find(
|
|
60257
|
+
(role2) => roleId.includes(role2._id)
|
|
60258
|
+
);
|
|
60259
|
+
if (!role) {
|
|
60260
|
+
return void 0;
|
|
60246
60261
|
}
|
|
60262
|
+
return (0, import_cloneDeep2.default)(role);
|
|
60263
|
+
}
|
|
60264
|
+
function builtinRoleToNumber(id) {
|
|
60247
60265
|
const builtins = getBuiltinRoles();
|
|
60248
60266
|
const MAX = Object.values(builtins).length + 1;
|
|
60249
60267
|
if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) {
|
|
@@ -60267,7 +60285,7 @@ async function roleToNumber(id) {
|
|
|
60267
60285
|
defaultPublic: true
|
|
60268
60286
|
});
|
|
60269
60287
|
for (let role of hierarchy) {
|
|
60270
|
-
if (isBuiltin(role
|
|
60288
|
+
if (role?.inherits && isBuiltin(role.inherits)) {
|
|
60271
60289
|
return builtinRoleToNumber(role.inherits) + 1;
|
|
60272
60290
|
}
|
|
60273
60291
|
}
|
|
@@ -60283,27 +60301,20 @@ function lowerBuiltinRoleID(roleId1, roleId2) {
|
|
|
60283
60301
|
return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2) ? roleId2 : roleId1;
|
|
60284
60302
|
}
|
|
60285
60303
|
async function getRole(roleId, opts) {
|
|
60286
|
-
|
|
60287
|
-
|
|
60288
|
-
}
|
|
60289
|
-
let role = {};
|
|
60290
|
-
if (isBuiltin(roleId)) {
|
|
60291
|
-
role = (0, import_cloneDeep2.default)(
|
|
60292
|
-
Object.values(BUILTIN_ROLES).find((role2) => role2._id === roleId)
|
|
60293
|
-
);
|
|
60294
|
-
} else {
|
|
60304
|
+
let role = getBuiltinRole(roleId);
|
|
60305
|
+
if (!role) {
|
|
60295
60306
|
roleId = prefixRoleID(roleId);
|
|
60296
60307
|
}
|
|
60297
60308
|
try {
|
|
60298
60309
|
const db = getAppDB();
|
|
60299
60310
|
const dbRole = await db.get(getDBRoleID(roleId));
|
|
60300
|
-
role = Object.assign(role, dbRole);
|
|
60311
|
+
role = Object.assign(role || {}, dbRole);
|
|
60301
60312
|
role._id = getExternalRoleID(role._id, role.version);
|
|
60302
60313
|
} catch (err) {
|
|
60303
60314
|
if (!isBuiltin(roleId) && opts?.defaultPublic) {
|
|
60304
60315
|
return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
|
|
60305
60316
|
}
|
|
60306
|
-
if (Object.keys(role).length === 0) {
|
|
60317
|
+
if (!role || Object.keys(role).length === 0) {
|
|
60307
60318
|
throw err;
|
|
60308
60319
|
}
|
|
60309
60320
|
}
|