@budibase/backend-core 3.2.31 → 3.2.33

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
@@ -8,9 +8,9 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __commonJS = (cb, mod) => function __require() {
9
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
10
  };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
11
+ var __export = (target, all2) => {
12
+ for (var name in all2)
13
+ __defProp(target, name, { get: all2[name], enumerable: true });
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
16
16
  if (from && typeof from === "object" || typeof from === "function") {
@@ -7985,18 +7985,18 @@ var require_luxon = __commonJS({
7985
7985
  function match(input, regex, handlers) {
7986
7986
  const matches2 = input.match(regex);
7987
7987
  if (matches2) {
7988
- const all = {};
7988
+ const all2 = {};
7989
7989
  let matchIndex = 1;
7990
7990
  for (const i in handlers) {
7991
7991
  if (hasOwnProperty(handlers, i)) {
7992
7992
  const h = handlers[i], groups = h.groups ? h.groups + 1 : 1;
7993
7993
  if (!h.literal && h.token) {
7994
- all[h.token.val[0]] = h.deser(matches2.slice(matchIndex, matchIndex + groups));
7994
+ all2[h.token.val[0]] = h.deser(matches2.slice(matchIndex, matchIndex + groups));
7995
7995
  }
7996
7996
  matchIndex += groups;
7997
7997
  }
7998
7998
  }
7999
- return [matches2, all];
7999
+ return [matches2, all2];
8000
8000
  } else {
8001
8001
  return [matches2, {}];
8002
8002
  }
@@ -11596,6 +11596,15 @@ var TenantResolutionStrategy = /* @__PURE__ */ ((TenantResolutionStrategy2) => {
11596
11596
  return TenantResolutionStrategy2;
11597
11597
  })(TenantResolutionStrategy || {});
11598
11598
 
11599
+ // ../types/src/sdk/featureFlag.ts
11600
+ var FeatureFlagDefaults = {
11601
+ ["DEFAULT_VALUES" /* DEFAULT_VALUES */]: true,
11602
+ ["AUTOMATION_BRANCHING" /* AUTOMATION_BRANCHING */]: true,
11603
+ ["AI_CUSTOM_CONFIGS" /* AI_CUSTOM_CONFIGS */]: true,
11604
+ ["BUDIBASE_AI" /* BUDIBASE_AI */]: true,
11605
+ ["USE_ZOD_VALIDATOR" /* USE_ZOD_VALIDATOR */]: false
11606
+ };
11607
+
11599
11608
  // ../types/src/sdk/cli/constants.ts
11600
11609
  var AnalyticsEvent = {
11601
11610
  OptOut: "analytics:opt:out",
@@ -20158,7 +20167,7 @@ async function getAllDbs(opts = { efficient: false }) {
20158
20167
  }
20159
20168
  async function getAllApps({
20160
20169
  dev,
20161
- all,
20170
+ all: all2,
20162
20171
  idsOnly,
20163
20172
  efficient
20164
20173
  } = {}) {
@@ -20204,7 +20213,7 @@ async function getAllApps({
20204
20213
  const apps = response.filter(
20205
20214
  (result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
20206
20215
  ).map(({ value }) => value);
20207
- if (!all) {
20216
+ if (!all2) {
20208
20217
  return apps.filter((app) => {
20209
20218
  if (dev) {
20210
20219
  return isDevApp(app);
@@ -27864,10 +27873,11 @@ var GLOBAL_BUILDER = "globalBuilder" /* GLOBAL_BUILDER */;
27864
27873
  // src/features/index.ts
27865
27874
  var features_exports = {};
27866
27875
  __export(features_exports, {
27867
- Flag: () => Flag,
27868
27876
  FlagSet: () => FlagSet,
27877
+ all: () => all,
27869
27878
  flags: () => flags,
27870
27879
  init: () => init8,
27880
+ isEnabled: () => isEnabled,
27871
27881
  parseEnvFlags: () => parseEnvFlags,
27872
27882
  shutdown: () => shutdown5,
27873
27883
  testutils: () => utils_exports6
@@ -27877,6 +27887,7 @@ __export(features_exports, {
27877
27887
  var crypto = __toESM(require("crypto"));
27878
27888
  var import_posthog_node2 = require("posthog-node");
27879
27889
  var import_dd_trace3 = __toESM(require("dd-trace"));
27890
+ var import_lodash6 = require("lodash");
27880
27891
  var posthog;
27881
27892
  function init8(opts) {
27882
27893
  if (environment_default.POSTHOG_TOKEN && environment_default.POSTHOG_API_HOST && !environment_default.SELF_HOSTED && environment_default.POSTHOG_FEATURE_FLAGS_ENABLED) {
@@ -27894,53 +27905,6 @@ function init8(opts) {
27894
27905
  function shutdown5() {
27895
27906
  posthog?.shutdown();
27896
27907
  }
27897
- var Flag = class {
27898
- constructor(defaultValue) {
27899
- this.defaultValue = defaultValue;
27900
- }
27901
- static boolean(defaultValue) {
27902
- return new BooleanFlag(defaultValue);
27903
- }
27904
- static string(defaultValue) {
27905
- return new StringFlag(defaultValue);
27906
- }
27907
- static number(defaultValue) {
27908
- return new NumberFlag(defaultValue);
27909
- }
27910
- };
27911
- var BooleanFlag = class extends Flag {
27912
- parse(value) {
27913
- if (typeof value === "string") {
27914
- return ["true", "t", "1"].includes(value.toLowerCase());
27915
- }
27916
- if (typeof value === "boolean") {
27917
- return value;
27918
- }
27919
- throw new Error(`could not parse value "${value}" as boolean`);
27920
- }
27921
- };
27922
- var StringFlag = class extends Flag {
27923
- parse(value) {
27924
- if (typeof value === "string") {
27925
- return value;
27926
- }
27927
- throw new Error(`could not parse value "${value}" as string`);
27928
- }
27929
- };
27930
- var NumberFlag = class extends Flag {
27931
- parse(value) {
27932
- if (typeof value === "number") {
27933
- return value;
27934
- }
27935
- if (typeof value === "string") {
27936
- const parsed = parseFloat(value);
27937
- if (!isNaN(parsed)) {
27938
- return parsed;
27939
- }
27940
- }
27941
- throw new Error(`could not parse value "${value}" as number`);
27942
- }
27943
- };
27944
27908
  function parseEnvFlags(flags2) {
27945
27909
  const split = flags2.split(",").map((x) => x.split(":"));
27946
27910
  const result = [];
@@ -27962,19 +27926,11 @@ var FlagSet = class {
27962
27926
  this.setId = crypto.randomUUID();
27963
27927
  }
27964
27928
  defaults() {
27965
- return Object.keys(this.flagSchema).reduce((acc, key) => {
27966
- const typedKey = key;
27967
- acc[typedKey] = this.flagSchema[key].defaultValue;
27968
- return acc;
27969
- }, {});
27929
+ return (0, import_lodash6.cloneDeep)(this.flagSchema);
27970
27930
  }
27971
27931
  isFlagName(name) {
27972
27932
  return this.flagSchema[name] !== void 0;
27973
27933
  }
27974
- async get(key) {
27975
- const flags2 = await this.fetch();
27976
- return flags2[key];
27977
- }
27978
27934
  async isEnabled(key) {
27979
27935
  const flags2 = await this.fetch();
27980
27936
  return flags2[key];
@@ -28028,21 +27984,23 @@ var FlagSet = class {
28028
27984
  if (posthog && userId) {
28029
27985
  tags[`readFromPostHog`] = true;
28030
27986
  const personProperties = { tenantId };
28031
- const posthogFlags = await posthog.getAllFlagsAndPayloads(userId, {
27987
+ const posthogFlags = await posthog.getAllFlags(userId, {
28032
27988
  personProperties
28033
27989
  });
28034
- for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
27990
+ for (const [name, value] of Object.entries(posthogFlags)) {
28035
27991
  if (!this.isFlagName(name)) {
28036
27992
  console.warn(`Unexpected posthog flag "${name}": ${value}`);
28037
27993
  continue;
28038
27994
  }
27995
+ if (typeof value !== "boolean") {
27996
+ console.warn(`Invalid value for posthog flag "${name}": ${value}`);
27997
+ continue;
27998
+ }
28039
27999
  if (flagValues[name] === true || specificallySetFalse.has(name)) {
28040
28000
  continue;
28041
28001
  }
28042
- const payload = posthogFlags.featureFlagPayloads?.[name];
28043
- const flag = this.flagSchema[name];
28044
28002
  try {
28045
- flagValues[name] = flag.parse(payload || value);
28003
+ flagValues[name] = value;
28046
28004
  tags[`flags.${name}.source`] = "posthog";
28047
28005
  } catch (err) {
28048
28006
  console.warn(`Error parsing posthog flag "${name}": ${value}`, err);
@@ -28058,14 +28016,13 @@ var FlagSet = class {
28058
28016
  });
28059
28017
  }
28060
28018
  };
28061
- var flagsConfig = {
28062
- ["DEFAULT_VALUES" /* DEFAULT_VALUES */]: Flag.boolean(true),
28063
- ["AUTOMATION_BRANCHING" /* AUTOMATION_BRANCHING */]: Flag.boolean(true),
28064
- ["AI_CUSTOM_CONFIGS" /* AI_CUSTOM_CONFIGS */]: Flag.boolean(true),
28065
- ["BUDIBASE_AI" /* BUDIBASE_AI */]: Flag.boolean(true),
28066
- ["USE_ZOD_VALIDATOR" /* USE_ZOD_VALIDATOR */]: Flag.boolean(environment_default.isDev())
28067
- };
28068
- var flags = new FlagSet(flagsConfig);
28019
+ var flags = new FlagSet(FeatureFlagDefaults);
28020
+ async function isEnabled(flag) {
28021
+ return await flags.isEnabled(flag);
28022
+ }
28023
+ async function all() {
28024
+ return await flags.fetch();
28025
+ }
28069
28026
 
28070
28027
  // src/features/tests/utils.ts
28071
28028
  var utils_exports6 = {};
@@ -29935,7 +29892,7 @@ var SqlTableQueryBuilder = class {
29935
29892
  var sqlTable_default = SqlTableQueryBuilder;
29936
29893
 
29937
29894
  // src/sql/sql.ts
29938
- var import_lodash6 = require("lodash");
29895
+ var import_lodash7 = require("lodash");
29939
29896
  var COUNT_FIELD_NAME = "__bb_total";
29940
29897
  function getBaseLimit() {
29941
29898
  const envLimit = environment_default.SQL_MAX_ROWS ? parseInt(environment_default.SQL_MAX_ROWS) : null;
@@ -30228,7 +30185,7 @@ var InternalBuilder = class {
30228
30185
  return body2;
30229
30186
  }
30230
30187
  parseFilters(filters) {
30231
- filters = (0, import_lodash6.cloneDeep)(filters);
30188
+ filters = (0, import_lodash7.cloneDeep)(filters);
30232
30189
  for (const op of Object.values(BasicOperator)) {
30233
30190
  const filter = filters[op];
30234
30191
  if (!filter) {