@budibase/backend-core 2.32.13 → 2.32.15
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 +50 -35
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/context/mainContext.d.ts +2 -0
- package/dist/src/context/mainContext.js +9 -0
- package/dist/src/context/mainContext.js.map +1 -1
- package/dist/src/context/types.d.ts +1 -0
- package/dist/src/db/couch/DatabaseImpl.d.ts +1 -0
- package/dist/src/db/couch/DatabaseImpl.js +5 -3
- package/dist/src/db/couch/DatabaseImpl.js.map +1 -1
- package/dist/src/features/features.d.ts +3 -4
- package/dist/src/features/features.js +23 -32
- package/dist/src/features/features.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/middleware/index.d.ts +1 -0
- package/dist/src/middleware/index.js +3 -1
- package/dist/src/middleware/index.js.map +1 -1
- package/dist/src/middleware/ip.d.ts +3 -0
- package/dist/src/middleware/ip.js +23 -0
- package/dist/src/middleware/ip.js.map +1 -0
- package/package.json +4 -4
- package/src/context/mainContext.ts +9 -0
- package/src/context/types.ts +1 -0
- package/src/db/couch/DatabaseImpl.ts +8 -4
- package/src/features/features.ts +25 -47
- package/src/features/tests/features.spec.ts +59 -31
- package/src/middleware/index.ts +1 -0
- package/src/middleware/ip.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -63421,6 +63421,7 @@ __export(context_exports, {
|
|
|
63421
63421
|
doInAutomationContext: () => doInAutomationContext,
|
|
63422
63422
|
doInContext: () => doInContext,
|
|
63423
63423
|
doInEnvironmentContext: () => doInEnvironmentContext,
|
|
63424
|
+
doInIPContext: () => doInIPContext,
|
|
63424
63425
|
doInIdentityContext: () => doInIdentityContext,
|
|
63425
63426
|
doInScimContext: () => doInScimContext,
|
|
63426
63427
|
doInTenant: () => doInTenant,
|
|
@@ -63436,6 +63437,7 @@ __export(context_exports, {
|
|
|
63436
63437
|
getFeatureFlags: () => getFeatureFlags,
|
|
63437
63438
|
getGlobalDB: () => getGlobalDB,
|
|
63438
63439
|
getGlobalDBName: () => getGlobalDBName,
|
|
63440
|
+
getIP: () => getIP,
|
|
63439
63441
|
getIdentity: () => getIdentity,
|
|
63440
63442
|
getPlatformURL: () => getPlatformURL,
|
|
63441
63443
|
getProdAppDB: () => getProdAppDB,
|
|
@@ -67134,6 +67136,7 @@ __export(features_exports, {
|
|
|
67134
67136
|
});
|
|
67135
67137
|
|
|
67136
67138
|
// src/features/features.ts
|
|
67139
|
+
var crypto = __toESM(require("crypto"));
|
|
67137
67140
|
var import_posthog_node = require("posthog-node");
|
|
67138
67141
|
var import_dd_trace3 = __toESM(require("dd-trace"));
|
|
67139
67142
|
|
|
@@ -67609,15 +67612,15 @@ var FlagSet = class {
|
|
|
67609
67612
|
isFlagName(name) {
|
|
67610
67613
|
return this.flagSchema[name] !== void 0;
|
|
67611
67614
|
}
|
|
67612
|
-
async get(key
|
|
67613
|
-
const flags2 = await this.fetch(
|
|
67615
|
+
async get(key) {
|
|
67616
|
+
const flags2 = await this.fetch();
|
|
67614
67617
|
return flags2[key];
|
|
67615
67618
|
}
|
|
67616
|
-
async isEnabled(key
|
|
67617
|
-
const flags2 = await this.fetch(
|
|
67619
|
+
async isEnabled(key) {
|
|
67620
|
+
const flags2 = await this.fetch();
|
|
67618
67621
|
return flags2[key];
|
|
67619
67622
|
}
|
|
67620
|
-
async fetch(
|
|
67623
|
+
async fetch() {
|
|
67621
67624
|
return await import_dd_trace3.default.trace("features.fetch", async (span) => {
|
|
67622
67625
|
const cachedFlags = getFeatureFlags(this.setId);
|
|
67623
67626
|
if (cachedFlags) {
|
|
@@ -67628,10 +67631,10 @@ var FlagSet = class {
|
|
|
67628
67631
|
const flagValues = this.defaults();
|
|
67629
67632
|
const currentTenantId = getTenantId();
|
|
67630
67633
|
const specificallySetFalse = /* @__PURE__ */ new Set();
|
|
67631
|
-
for (const { tenantId, key, value } of parseEnvFlags(
|
|
67634
|
+
for (const { tenantId: tenantId2, key, value } of parseEnvFlags(
|
|
67632
67635
|
environment_default.TENANT_FEATURE_FLAGS || ""
|
|
67633
67636
|
)) {
|
|
67634
|
-
if (!
|
|
67637
|
+
if (!tenantId2 || tenantId2 !== "*" && tenantId2 !== currentTenantId) {
|
|
67635
67638
|
continue;
|
|
67636
67639
|
}
|
|
67637
67640
|
tags[`readFromEnvironmentVars`] = true;
|
|
@@ -67647,36 +67650,28 @@ var FlagSet = class {
|
|
|
67647
67650
|
flagValues[key] = value;
|
|
67648
67651
|
tags[`flags.${key}.source`] = "environment";
|
|
67649
67652
|
}
|
|
67650
|
-
const
|
|
67651
|
-
|
|
67652
|
-
|
|
67653
|
-
|
|
67654
|
-
|
|
67655
|
-
|
|
67656
|
-
}
|
|
67657
|
-
if (flagValues[feature] === true || specificallySetFalse.has(feature)) {
|
|
67658
|
-
continue;
|
|
67659
|
-
}
|
|
67660
|
-
flagValues[feature] = true;
|
|
67661
|
-
tags[`flags.${feature}.source`] = "license";
|
|
67653
|
+
const identity = getIdentity();
|
|
67654
|
+
let userId = identity?._id;
|
|
67655
|
+
if (!userId) {
|
|
67656
|
+
const ip = getIP();
|
|
67657
|
+
if (ip) {
|
|
67658
|
+
userId = crypto.createHash("sha512").update(ip).digest("hex");
|
|
67662
67659
|
}
|
|
67663
67660
|
}
|
|
67664
|
-
|
|
67661
|
+
let tenantId = identity?.tenantId;
|
|
67662
|
+
if (!tenantId) {
|
|
67663
|
+
tenantId = currentTenantId;
|
|
67664
|
+
}
|
|
67665
67665
|
tags[`identity.type`] = identity?.type;
|
|
67666
|
-
tags[`identity.tenantId`] = identity?.tenantId;
|
|
67667
67666
|
tags[`identity._id`] = identity?._id;
|
|
67668
|
-
|
|
67667
|
+
tags[`tenantId`] = tenantId;
|
|
67668
|
+
tags[`userId`] = userId;
|
|
67669
|
+
if (posthog && userId) {
|
|
67669
67670
|
tags[`readFromPostHog`] = true;
|
|
67670
|
-
const personProperties = {};
|
|
67671
|
-
|
|
67672
|
-
personProperties
|
|
67673
|
-
}
|
|
67674
|
-
const posthogFlags = await posthog.getAllFlagsAndPayloads(
|
|
67675
|
-
identity._id,
|
|
67676
|
-
{
|
|
67677
|
-
personProperties
|
|
67678
|
-
}
|
|
67679
|
-
);
|
|
67671
|
+
const personProperties = { tenantId };
|
|
67672
|
+
const posthogFlags = await posthog.getAllFlagsAndPayloads(userId, {
|
|
67673
|
+
personProperties
|
|
67674
|
+
});
|
|
67680
67675
|
for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
|
|
67681
67676
|
if (!this.isFlagName(name)) {
|
|
67682
67677
|
console.warn(`Unexpected posthog flag "${name}": ${value}`);
|
|
@@ -67896,12 +67891,13 @@ var DatabaseImpl = class _DatabaseImpl {
|
|
|
67896
67891
|
}
|
|
67897
67892
|
async getMultiple(ids, opts) {
|
|
67898
67893
|
ids = [...new Set(ids)];
|
|
67894
|
+
const includeDocs = !opts?.excludeDocs;
|
|
67899
67895
|
const response = await this.allDocs({
|
|
67900
67896
|
keys: ids,
|
|
67901
|
-
include_docs:
|
|
67897
|
+
include_docs: includeDocs
|
|
67902
67898
|
});
|
|
67903
67899
|
const rowUnavailable = (row) => {
|
|
67904
|
-
if (row.doc == null || "deleted" in row.value && row.value.deleted) {
|
|
67900
|
+
if (includeDocs && row.doc == null || row.value && "deleted" in row.value && row.value.deleted) {
|
|
67905
67901
|
return true;
|
|
67906
67902
|
}
|
|
67907
67903
|
return row.error === "not_found";
|
|
@@ -67913,7 +67909,7 @@ var DatabaseImpl = class _DatabaseImpl {
|
|
|
67913
67909
|
const missingIds = missing.map((row) => row.key).join(", ");
|
|
67914
67910
|
throw new Error(`Unable to get documents: ${missingIds}`);
|
|
67915
67911
|
}
|
|
67916
|
-
return rows.map((row) => row.doc);
|
|
67912
|
+
return rows.map((row) => includeDocs ? row.doc : row.value);
|
|
67917
67913
|
}
|
|
67918
67914
|
async remove(idOrDoc, rev) {
|
|
67919
67915
|
return this.performCall((db) => {
|
|
@@ -68333,6 +68329,10 @@ function getAppId() {
|
|
|
68333
68329
|
return foundId;
|
|
68334
68330
|
}
|
|
68335
68331
|
}
|
|
68332
|
+
function getIP() {
|
|
68333
|
+
const context = Context.get();
|
|
68334
|
+
return context?.ip;
|
|
68335
|
+
}
|
|
68336
68336
|
var getProdAppId = () => {
|
|
68337
68337
|
const appId = getAppId();
|
|
68338
68338
|
if (!appId) {
|
|
@@ -68355,6 +68355,9 @@ function doInScimContext(task) {
|
|
|
68355
68355
|
};
|
|
68356
68356
|
return newContext(updates, task);
|
|
68357
68357
|
}
|
|
68358
|
+
function doInIPContext(ip, task) {
|
|
68359
|
+
return newContext({ ip }, task);
|
|
68360
|
+
}
|
|
68358
68361
|
async function ensureSnippetContext(enabled2 = !environment_default.isTest()) {
|
|
68359
68362
|
const ctx = getCurrentContext();
|
|
68360
68363
|
if (!ctx || ctx.snippets) {
|
|
@@ -73827,6 +73830,7 @@ __export(middleware_exports, {
|
|
|
73827
73830
|
errorHandling: () => errorHandling_default,
|
|
73828
73831
|
google: () => google_exports,
|
|
73829
73832
|
internalApi: () => internalApi_default,
|
|
73833
|
+
ip: () => ip_default,
|
|
73830
73834
|
joiValidator: () => joi_validator_exports,
|
|
73831
73835
|
local: () => local_exports,
|
|
73832
73836
|
oidc: () => oidc_exports,
|
|
@@ -74817,6 +74821,17 @@ function params(schema, opts) {
|
|
|
74817
74821
|
return validate2(schema, "params", opts);
|
|
74818
74822
|
}
|
|
74819
74823
|
|
|
74824
|
+
// src/middleware/ip.ts
|
|
74825
|
+
var ip_default = async (ctx, next) => {
|
|
74826
|
+
if (ctx.ip) {
|
|
74827
|
+
return await doInIPContext(ctx.ip, () => {
|
|
74828
|
+
return next();
|
|
74829
|
+
});
|
|
74830
|
+
} else {
|
|
74831
|
+
return next();
|
|
74832
|
+
}
|
|
74833
|
+
};
|
|
74834
|
+
|
|
74820
74835
|
// src/middleware/index.ts
|
|
74821
74836
|
var datasource = {
|
|
74822
74837
|
google: google_exports2
|