@budibase/backend-core 2.32.14 → 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 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, ctx) {
67613
- const flags2 = await this.fetch(ctx);
67615
+ async get(key) {
67616
+ const flags2 = await this.fetch();
67614
67617
  return flags2[key];
67615
67618
  }
67616
- async isEnabled(key, ctx) {
67617
- const flags2 = await this.fetch(ctx);
67619
+ async isEnabled(key) {
67620
+ const flags2 = await this.fetch();
67618
67621
  return flags2[key];
67619
67622
  }
67620
- async fetch(ctx) {
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 (!tenantId || tenantId !== "*" && tenantId !== currentTenantId) {
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 license = ctx?.user?.license;
67651
- if (license) {
67652
- tags[`readFromLicense`] = true;
67653
- for (const feature of license.features) {
67654
- if (!this.isFlagName(feature)) {
67655
- continue;
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
- const identity = getIdentity();
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
- if (posthog && identity?.type === "user" /* USER */) {
67667
+ tags[`tenantId`] = tenantId;
67668
+ tags[`userId`] = userId;
67669
+ if (posthog && userId) {
67669
67670
  tags[`readFromPostHog`] = true;
67670
- const personProperties = {};
67671
- if (identity.tenantId) {
67672
- personProperties.tenantId = identity.tenantId;
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}`);
@@ -68334,6 +68329,10 @@ function getAppId() {
68334
68329
  return foundId;
68335
68330
  }
68336
68331
  }
68332
+ function getIP() {
68333
+ const context = Context.get();
68334
+ return context?.ip;
68335
+ }
68337
68336
  var getProdAppId = () => {
68338
68337
  const appId = getAppId();
68339
68338
  if (!appId) {
@@ -68356,6 +68355,9 @@ function doInScimContext(task) {
68356
68355
  };
68357
68356
  return newContext(updates, task);
68358
68357
  }
68358
+ function doInIPContext(ip, task) {
68359
+ return newContext({ ip }, task);
68360
+ }
68359
68361
  async function ensureSnippetContext(enabled2 = !environment_default.isTest()) {
68360
68362
  const ctx = getCurrentContext();
68361
68363
  if (!ctx || ctx.snippets) {
@@ -73828,6 +73830,7 @@ __export(middleware_exports, {
73828
73830
  errorHandling: () => errorHandling_default,
73829
73831
  google: () => google_exports,
73830
73832
  internalApi: () => internalApi_default,
73833
+ ip: () => ip_default,
73831
73834
  joiValidator: () => joi_validator_exports,
73832
73835
  local: () => local_exports,
73833
73836
  oidc: () => oidc_exports,
@@ -74818,6 +74821,17 @@ function params(schema, opts) {
74818
74821
  return validate2(schema, "params", opts);
74819
74822
  }
74820
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
+
74821
74835
  // src/middleware/index.ts
74822
74836
  var datasource = {
74823
74837
  google: google_exports2