@budibase/backend-core 2.30.2 → 2.30.3

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.
Files changed (57) hide show
  1. package/dist/index.js +267 -89
  2. package/dist/index.js.map +3 -3
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +5 -5
  5. package/dist/plugins.js.meta.json +1 -1
  6. package/dist/src/environment.d.ts +4 -0
  7. package/dist/src/environment.js +27 -1
  8. package/dist/src/environment.js.map +1 -1
  9. package/dist/src/events/processors/posthog/PosthogProcessor.d.ts +1 -1
  10. package/dist/src/events/processors/posthog/PosthogProcessor.js +2 -2
  11. package/dist/src/events/processors/posthog/PosthogProcessor.js.map +1 -1
  12. package/dist/src/features/index.d.ts +29 -26
  13. package/dist/src/features/index.js +195 -79
  14. package/dist/src/features/index.js.map +1 -1
  15. package/dist/src/index.d.ts +1 -1
  16. package/dist/src/index.js +3 -1
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/redis/redis.d.ts +1 -0
  19. package/dist/src/redis/redis.js +4 -0
  20. package/dist/src/redis/redis.js.map +1 -1
  21. package/dist/src/security/auth.js +1 -1
  22. package/dist/src/security/auth.js.map +1 -1
  23. package/dist/src/sql/sqlTable.js +23 -8
  24. package/dist/src/sql/sqlTable.js.map +1 -1
  25. package/dist/tests/core/utilities/mocks/index.d.ts +0 -2
  26. package/dist/tests/core/utilities/mocks/index.js +1 -7
  27. package/dist/tests/core/utilities/mocks/index.js.map +1 -1
  28. package/dist/tests/core/utilities/structures/users.js +1 -1
  29. package/dist/tests/core/utilities/structures/users.js.map +1 -1
  30. package/dist/tests/jestSetup.js +7 -2
  31. package/dist/tests/jestSetup.js.map +1 -1
  32. package/package.json +5 -5
  33. package/src/environment.ts +29 -0
  34. package/src/events/processors/posthog/PosthogProcessor.ts +1 -1
  35. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +16 -22
  36. package/src/features/index.ts +231 -81
  37. package/src/features/tests/features.spec.ts +204 -60
  38. package/src/index.ts +1 -1
  39. package/src/middleware/passport/sso/tests/oidc.spec.ts +4 -12
  40. package/src/middleware/passport/sso/tests/sso.spec.ts +10 -12
  41. package/src/plugin/tests/validation.spec.ts +168 -42
  42. package/src/redis/redis.ts +4 -0
  43. package/src/redis/tests/redis.spec.ts +5 -2
  44. package/src/security/auth.ts +1 -1
  45. package/src/security/tests/auth.spec.ts +2 -2
  46. package/src/sql/sqlTable.ts +21 -7
  47. package/tests/core/utilities/mocks/index.ts +0 -2
  48. package/tests/core/utilities/structures/users.ts +1 -1
  49. package/tests/jestSetup.ts +10 -3
  50. package/dist/tests/core/utilities/mocks/fetch.d.ts +0 -32
  51. package/dist/tests/core/utilities/mocks/fetch.js +0 -15
  52. package/dist/tests/core/utilities/mocks/fetch.js.map +0 -1
  53. package/dist/tests/core/utilities/mocks/posthog.d.ts +0 -0
  54. package/dist/tests/core/utilities/mocks/posthog.js +0 -9
  55. package/dist/tests/core/utilities/mocks/posthog.js.map +0 -1
  56. package/tests/core/utilities/mocks/fetch.ts +0 -17
  57. package/tests/core/utilities/mocks/posthog.ts +0 -7
package/dist/index.js CHANGED
@@ -19623,11 +19623,11 @@ var require_nacl_fast = __commonJS({
19623
19623
  "use strict";
19624
19624
  (function(nacl) {
19625
19625
  "use strict";
19626
- var gf = function(init10) {
19626
+ var gf = function(init11) {
19627
19627
  var i, r = new Float64Array(16);
19628
- if (init10)
19629
- for (i = 0; i < init10.length; i++)
19630
- r[i] = init10[i];
19628
+ if (init11)
19629
+ for (i = 0; i < init11.length; i++)
19630
+ r[i] = init11[i];
19631
19631
  return r;
19632
19632
  };
19633
19633
  var randombytes = function() {
@@ -29351,7 +29351,7 @@ var require_extsprintf = __commonJS({
29351
29351
  ].join("");
29352
29352
  var re = new RegExp(regex);
29353
29353
  var args = Array.prototype.slice.call(arguments, 1);
29354
- var flags, width, precision, conversion2;
29354
+ var flags2, width, precision, conversion2;
29355
29355
  var left, pad, sign, arg, match;
29356
29356
  var ret = "";
29357
29357
  var argn = 1;
@@ -29359,7 +29359,7 @@ var require_extsprintf = __commonJS({
29359
29359
  while ((match = re.exec(fmt)) !== null) {
29360
29360
  ret += match[1];
29361
29361
  fmt = fmt.substring(match[0].length);
29362
- flags = match[2] || "";
29362
+ flags2 = match[2] || "";
29363
29363
  width = match[3] || 0;
29364
29364
  precision = match[4] || "";
29365
29365
  conversion2 = match[6];
@@ -29374,19 +29374,19 @@ var require_extsprintf = __commonJS({
29374
29374
  throw new Error("too few args to sprintf");
29375
29375
  arg = args.shift();
29376
29376
  argn++;
29377
- if (flags.match(/[\' #]/))
29377
+ if (flags2.match(/[\' #]/))
29378
29378
  throw new Error(
29379
- "unsupported flags: " + flags
29379
+ "unsupported flags: " + flags2
29380
29380
  );
29381
29381
  if (precision.length > 0)
29382
29382
  throw new Error(
29383
29383
  "non-zero precision not supported"
29384
29384
  );
29385
- if (flags.match(/-/))
29385
+ if (flags2.match(/-/))
29386
29386
  left = true;
29387
- if (flags.match(/0/))
29387
+ if (flags2.match(/0/))
29388
29388
  pad = "0";
29389
- if (flags.match(/\+/))
29389
+ if (flags2.match(/\+/))
29390
29390
  sign = true;
29391
29391
  switch (conversion2) {
29392
29392
  case "s":
@@ -29487,7 +29487,7 @@ var require_extsprintf2 = __commonJS({
29487
29487
  var re = new RegExp(regex);
29488
29488
  var args = Array.prototype.slice.call(arguments, 1);
29489
29489
  var fmt = ofmt;
29490
- var flags, width, precision, conversion2;
29490
+ var flags2, width, precision, conversion2;
29491
29491
  var left, pad, sign, arg, match;
29492
29492
  var ret = "";
29493
29493
  var argn = 1;
@@ -29505,7 +29505,7 @@ var require_extsprintf2 = __commonJS({
29505
29505
  curconv = match[0].substring(match[1].length);
29506
29506
  convposn = posn + match[1].length + 1;
29507
29507
  posn += match[0].length;
29508
- flags = match[2] || "";
29508
+ flags2 = match[2] || "";
29509
29509
  width = match[3] || 0;
29510
29510
  precision = match[4] || "";
29511
29511
  conversion2 = match[6];
@@ -29526,7 +29526,7 @@ var require_extsprintf2 = __commonJS({
29526
29526
  }
29527
29527
  arg = args.shift();
29528
29528
  argn++;
29529
- if (flags.match(/[\' #]/)) {
29529
+ if (flags2.match(/[\' #]/)) {
29530
29530
  throw jsError(
29531
29531
  ofmt,
29532
29532
  convposn,
@@ -29542,11 +29542,11 @@ var require_extsprintf2 = __commonJS({
29542
29542
  "uses non-zero precision (not supported)"
29543
29543
  );
29544
29544
  }
29545
- if (flags.match(/-/))
29545
+ if (flags2.match(/-/))
29546
29546
  left = true;
29547
- if (flags.match(/0/))
29547
+ if (flags2.match(/0/))
29548
29548
  pad = "0";
29549
- if (flags.match(/\+/))
29549
+ if (flags2.match(/\+/))
29550
29550
  sign = true;
29551
29551
  switch (conversion2) {
29552
29552
  case "s":
@@ -54197,7 +54197,7 @@ __export(src_exports, {
54197
54197
  events: () => events_exports,
54198
54198
  features: () => features_exports,
54199
54199
  getPublicError: () => getPublicError,
54200
- init: () => init9,
54200
+ init: () => init10,
54201
54201
  installation: () => installation_exports,
54202
54202
  locks: () => redlockImpl_exports,
54203
54203
  logging: () => logging_exports,
@@ -54212,12 +54212,14 @@ __export(src_exports, {
54212
54212
  roles: () => roles_exports,
54213
54213
  security: () => security_exports,
54214
54214
  sessions: () => sessions_exports,
54215
+ setEnv: () => setEnv,
54215
54216
  sql: () => sql_exports,
54216
54217
  tenancy: () => tenancy,
54217
54218
  timers: () => timers_exports,
54218
54219
  userUtils: () => utils_exports5,
54219
54220
  users: () => users_exports3,
54220
- utils: () => utils_exports4
54221
+ utils: () => utils_exports4,
54222
+ withEnv: () => withEnv
54221
54223
  });
54222
54224
  module.exports = __toCommonJS(src_exports);
54223
54225
 
@@ -55311,7 +55313,7 @@ var search = (docs, query) => {
55311
55313
  }
55312
55314
  return response;
55313
55315
  };
55314
- var runQuery = (docs, query) => {
55316
+ var runQuery = (docs, query, findInDoc = deepGet) => {
55315
55317
  if (!docs || !Array.isArray(docs)) {
55316
55318
  return [];
55317
55319
  }
@@ -55325,7 +55327,7 @@ var runQuery = (docs, query) => {
55325
55327
  }
55326
55328
  const match = (type, test) => (doc) => {
55327
55329
  for (const [key, testValue] of Object.entries(query[type] || {})) {
55328
- const valueToCheck = isLogicalSearchOperator(type) ? doc : deepGet(doc, removeKeyNumbering(key));
55330
+ const valueToCheck = isLogicalSearchOperator(type) ? doc : findInDoc(doc, removeKeyNumbering(key));
55329
55331
  const result = test(valueToCheck, testValue);
55330
55332
  if (query.allOr && result) {
55331
55333
  return true;
@@ -55864,6 +55866,27 @@ var allowSortColumnByType = {
55864
55866
  ["bb_reference" /* BB_REFERENCE */]: false,
55865
55867
  ["bb_reference_single" /* BB_REFERENCE_SINGLE */]: false
55866
55868
  };
55869
+ var allowDefaultColumnByType = {
55870
+ ["number" /* NUMBER */]: true,
55871
+ ["json" /* JSON */]: true,
55872
+ ["datetime" /* DATETIME */]: true,
55873
+ ["longform" /* LONGFORM */]: true,
55874
+ ["string" /* STRING */]: true,
55875
+ ["options" /* OPTIONS */]: false,
55876
+ ["auto" /* AUTO */]: false,
55877
+ ["internal" /* INTERNAL */]: false,
55878
+ ["barcodeqr" /* BARCODEQR */]: false,
55879
+ ["bigint" /* BIGINT */]: false,
55880
+ ["boolean" /* BOOLEAN */]: false,
55881
+ ["formula" /* FORMULA */]: false,
55882
+ ["attachment" /* ATTACHMENTS */]: false,
55883
+ ["attachment_single" /* ATTACHMENT_SINGLE */]: false,
55884
+ ["signature_single" /* SIGNATURE_SINGLE */]: false,
55885
+ ["array" /* ARRAY */]: false,
55886
+ ["link" /* LINK */]: false,
55887
+ ["bb_reference" /* BB_REFERENCE */]: false,
55888
+ ["bb_reference_single" /* BB_REFERENCE_SINGLE */]: false
55889
+ };
55867
55890
 
55868
55891
  // src/constants/db.ts
55869
55892
  var AutomationViewMode = /* @__PURE__ */ ((AutomationViewMode2) => {
@@ -56084,6 +56107,7 @@ function getAccountUserId(account) {
56084
56107
 
56085
56108
  // src/environment.ts
56086
56109
  var import_fs = require("fs");
56110
+ var import_lodash2 = require("lodash");
56087
56111
  function isTest() {
56088
56112
  return isJest();
56089
56113
  }
@@ -56194,6 +56218,8 @@ var environment = {
56194
56218
  COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
56195
56219
  PLATFORM_URL: process.env.PLATFORM_URL || "",
56196
56220
  POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
56221
+ POSTHOG_PERSONAL_TOKEN: process.env.POSTHOG_PERSONAL_TOKEN,
56222
+ POSTHOG_API_HOST: process.env.POSTHOG_API_HOST || "https://us.i.posthog.com",
56197
56223
  ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
56198
56224
  TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS,
56199
56225
  CLOUDFRONT_CDN: process.env.CLOUDFRONT_CDN,
@@ -56249,6 +56275,28 @@ var environment = {
56249
56275
  BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD,
56250
56276
  OPENAI_API_KEY: process.env.OPENAI_API_KEY
56251
56277
  };
56278
+ function setEnv(newEnvVars) {
56279
+ const oldEnv = (0, import_lodash2.cloneDeep)(environment);
56280
+ let key;
56281
+ for (key in newEnvVars) {
56282
+ environment._set(key, newEnvVars[key]);
56283
+ }
56284
+ return () => {
56285
+ for (const [key2, value] of Object.entries(oldEnv)) {
56286
+ environment._set(key2, value);
56287
+ }
56288
+ };
56289
+ }
56290
+ function withEnv(envVars, f) {
56291
+ const cleanup3 = setEnv(envVars);
56292
+ const result = f();
56293
+ if (result instanceof Promise) {
56294
+ return result.finally(cleanup3);
56295
+ } else {
56296
+ cleanup3();
56297
+ return result;
56298
+ }
56299
+ }
56252
56300
  var SECRETS = [
56253
56301
  "API_ENCRYPTION_KEY",
56254
56302
  "BB_ADMIN_USER_PASSWORD",
@@ -62058,7 +62106,7 @@ var enabled = async () => {
62058
62106
  };
62059
62107
 
62060
62108
  // src/events/processors/posthog/PosthogProcessor.ts
62061
- var import_posthog_node = __toESM(require("posthog-node"));
62109
+ var import_posthog_node = require("posthog-node");
62062
62110
 
62063
62111
  // src/events/processors/posthog/rateLimiting.ts
62064
62112
  var isRateLimited = (event) => {
@@ -62142,7 +62190,7 @@ var PosthogProcessor = class {
62142
62190
  if (!token) {
62143
62191
  throw new Error("Posthog token is not defined");
62144
62192
  }
62145
- this.posthog = new import_posthog_node.default(token);
62193
+ this.posthog = new import_posthog_node.PostHog(token);
62146
62194
  }
62147
62195
  async processEvent(event, identity, properties, timestamp) {
62148
62196
  if (EXCLUDED_EVENTS.includes(event)) {
@@ -64667,7 +64715,7 @@ __export(security_exports, {
64667
64715
  });
64668
64716
 
64669
64717
  // src/security/auth.ts
64670
- var PASSWORD_MIN_LENGTH = +(environment_default.PASSWORD_MIN_LENGTH || 8);
64718
+ var PASSWORD_MIN_LENGTH = +(environment_default.PASSWORD_MIN_LENGTH || 12);
64671
64719
  var PASSWORD_MAX_LENGTH = +(environment_default.PASSWORD_MAX_LENGTH || 512);
64672
64720
  function validatePassword(password) {
64673
64721
  if (!password || password.length < PASSWORD_MIN_LENGTH) {
@@ -65977,70 +66025,188 @@ var DEFINITIONS = [
65977
66025
  // src/features/index.ts
65978
66026
  var features_exports = {};
65979
66027
  __export(features_exports, {
65980
- defaultFlags: () => defaultFlags,
65981
- fetch: () => fetch6,
65982
- get: () => get4,
65983
- isEnabled: () => isEnabled
66028
+ Flag: () => Flag,
66029
+ FlagSet: () => FlagSet,
66030
+ flags: () => flags,
66031
+ init: () => init8
65984
66032
  });
65985
- var import_lodash2 = require("lodash");
65986
- var Flag = class _Flag {
66033
+ var import_posthog_node2 = require("posthog-node");
66034
+ var import_dd_trace3 = __toESM(require("dd-trace"));
66035
+ var posthog;
66036
+ function init8(opts) {
66037
+ if (environment_default.POSTHOG_TOKEN && environment_default.POSTHOG_API_HOST) {
66038
+ console.log("initializing posthog client...");
66039
+ posthog = new import_posthog_node2.PostHog(environment_default.POSTHOG_TOKEN, {
66040
+ host: environment_default.POSTHOG_API_HOST,
66041
+ personalApiKey: environment_default.POSTHOG_PERSONAL_TOKEN,
66042
+ ...opts
66043
+ });
66044
+ } else {
66045
+ console.log("posthog disabled");
66046
+ }
66047
+ }
66048
+ var Flag = class {
65987
66049
  constructor(defaultValue) {
65988
66050
  this.defaultValue = defaultValue;
65989
66051
  }
65990
- static withDefault(value) {
65991
- return new _Flag(value);
66052
+ static boolean(defaultValue) {
66053
+ return new BooleanFlag(defaultValue);
66054
+ }
66055
+ static string(defaultValue) {
66056
+ return new StringFlag(defaultValue);
66057
+ }
66058
+ static number(defaultValue) {
66059
+ return new NumberFlag(defaultValue);
66060
+ }
66061
+ };
66062
+ var BooleanFlag = class extends Flag {
66063
+ parse(value) {
66064
+ if (typeof value === "string") {
66065
+ return ["true", "t", "1"].includes(value.toLowerCase());
66066
+ }
66067
+ if (typeof value === "boolean") {
66068
+ return value;
66069
+ }
66070
+ throw new Error(`could not parse value "${value}" as boolean`);
65992
66071
  }
65993
66072
  };
65994
- var FLAGS = {
65995
- LICENSING: Flag.withDefault(false),
65996
- GOOGLE_SHEETS: Flag.withDefault(false),
65997
- USER_GROUPS: Flag.withDefault(false),
65998
- ONBOARDING_TOUR: Flag.withDefault(false)
66073
+ var StringFlag = class extends Flag {
66074
+ parse(value) {
66075
+ if (typeof value === "string") {
66076
+ return value;
66077
+ }
66078
+ throw new Error(`could not parse value "${value}" as string`);
66079
+ }
65999
66080
  };
66000
- var DEFAULTS = Object.keys(FLAGS).reduce((acc, key) => {
66001
- const typedKey = key;
66002
- acc[typedKey] = FLAGS[typedKey].defaultValue;
66003
- return acc;
66004
- }, {});
66005
- function defaultFlags() {
66006
- return (0, import_lodash2.cloneDeep)(DEFAULTS);
66007
- }
66008
- function isFlagName(name) {
66009
- return FLAGS[name] !== void 0;
66010
- }
66011
- async function fetch6() {
66012
- const currentTenantId = getTenantId();
66013
- const flags = defaultFlags();
66014
- const split = (environment_default.TENANT_FEATURE_FLAGS || "").split(",").map((x) => x.split(":"));
66015
- for (const [tenantId, ...features] of split) {
66016
- if (!tenantId || tenantId !== "*" && tenantId !== currentTenantId) {
66017
- continue;
66081
+ var NumberFlag = class extends Flag {
66082
+ parse(value) {
66083
+ if (typeof value === "number") {
66084
+ return value;
66018
66085
  }
66019
- for (let feature of features) {
66020
- let value = true;
66021
- if (feature.startsWith("!")) {
66022
- feature = feature.slice(1);
66023
- value = false;
66086
+ if (typeof value === "string") {
66087
+ const parsed = parseFloat(value);
66088
+ if (!isNaN(parsed)) {
66089
+ return parsed;
66024
66090
  }
66025
- if (!isFlagName(feature)) {
66026
- throw new Error(`Feature: ${feature} is not an allowed option`);
66091
+ }
66092
+ throw new Error(`could not parse value "${value}" as number`);
66093
+ }
66094
+ };
66095
+ var FlagSet = class {
66096
+ constructor(flagSchema) {
66097
+ this.flagSchema = flagSchema;
66098
+ }
66099
+ defaults() {
66100
+ return Object.keys(this.flagSchema).reduce((acc, key) => {
66101
+ const typedKey = key;
66102
+ acc[typedKey] = this.flagSchema[key].defaultValue;
66103
+ return acc;
66104
+ }, {});
66105
+ }
66106
+ isFlagName(name) {
66107
+ return this.flagSchema[name] !== void 0;
66108
+ }
66109
+ async get(key, ctx) {
66110
+ const flags2 = await this.fetch(ctx);
66111
+ return flags2[key];
66112
+ }
66113
+ async isEnabled(key, ctx) {
66114
+ const flags2 = await this.fetch(ctx);
66115
+ return flags2[key];
66116
+ }
66117
+ async fetch(ctx) {
66118
+ return await import_dd_trace3.default.trace("features.fetch", async (span) => {
66119
+ const tags = {};
66120
+ const flagValues = this.defaults();
66121
+ const currentTenantId = getTenantId();
66122
+ const specificallySetFalse = /* @__PURE__ */ new Set();
66123
+ const split = (environment_default.TENANT_FEATURE_FLAGS || "").split(",").map((x) => x.split(":"));
66124
+ for (const [tenantId, ...features] of split) {
66125
+ if (!tenantId || tenantId !== "*" && tenantId !== currentTenantId) {
66126
+ continue;
66127
+ }
66128
+ tags[`readFromEnvironmentVars`] = true;
66129
+ for (let feature of features) {
66130
+ let value = true;
66131
+ if (feature.startsWith("!")) {
66132
+ feature = feature.slice(1);
66133
+ value = false;
66134
+ specificallySetFalse.add(feature);
66135
+ }
66136
+ if (!this.isFlagName(feature)) {
66137
+ throw new Error(`Feature: ${feature} is not an allowed option`);
66138
+ }
66139
+ if (typeof flagValues[feature] !== "boolean") {
66140
+ throw new Error(`Feature: ${feature} is not a boolean`);
66141
+ }
66142
+ flagValues[feature] = value;
66143
+ tags[`flags.${feature}.source`] = "environment";
66144
+ }
66027
66145
  }
66028
- if (typeof flags[feature] !== "boolean") {
66029
- throw new Error(`Feature: ${feature} is not a boolean`);
66146
+ const license = ctx?.user?.license;
66147
+ if (license) {
66148
+ tags[`readFromLicense`] = true;
66149
+ for (const feature of license.features) {
66150
+ if (!this.isFlagName(feature)) {
66151
+ continue;
66152
+ }
66153
+ if (flagValues[feature] === true || specificallySetFalse.has(feature)) {
66154
+ continue;
66155
+ }
66156
+ flagValues[feature] = true;
66157
+ tags[`flags.${feature}.source`] = "license";
66158
+ }
66030
66159
  }
66031
- flags[feature] = value;
66032
- }
66160
+ const identity = getIdentity();
66161
+ tags[`identity.type`] = identity?.type;
66162
+ tags[`identity.tenantId`] = identity?.tenantId;
66163
+ tags[`identity._id`] = identity?._id;
66164
+ const usePosthog = environment_default.isTest() || environment_default.isQA();
66165
+ if (usePosthog && posthog && identity?.type === "user" /* USER */) {
66166
+ tags[`readFromPostHog`] = true;
66167
+ const personProperties = {};
66168
+ if (identity.tenantId) {
66169
+ personProperties.tenantId = identity.tenantId;
66170
+ }
66171
+ const posthogFlags = await posthog.getAllFlagsAndPayloads(
66172
+ identity._id,
66173
+ {
66174
+ personProperties
66175
+ }
66176
+ );
66177
+ console.log("posthog flags", JSON.stringify(posthogFlags));
66178
+ for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
66179
+ if (!this.isFlagName(name)) {
66180
+ console.warn(`Unexpected posthog flag "${name}": ${value}`);
66181
+ continue;
66182
+ }
66183
+ if (flagValues[name] === true || specificallySetFalse.has(name)) {
66184
+ continue;
66185
+ }
66186
+ const payload = posthogFlags.featureFlagPayloads?.[name];
66187
+ const flag = this.flagSchema[name];
66188
+ try {
66189
+ flagValues[name] = flag.parse(payload || value);
66190
+ tags[`flags.${name}.source`] = "posthog";
66191
+ } catch (err) {
66192
+ console.warn(`Error parsing posthog flag "${name}": ${value}`, err);
66193
+ }
66194
+ }
66195
+ }
66196
+ for (const [key, value] of Object.entries(flagValues)) {
66197
+ tags[`flags.${key}.value`] = value;
66198
+ }
66199
+ span?.addTags(tags);
66200
+ return flagValues;
66201
+ });
66033
66202
  }
66034
- return flags;
66035
- }
66036
- async function get4(name) {
66037
- const flags = await fetch6();
66038
- return flags[name];
66039
- }
66040
- async function isEnabled(name) {
66041
- const flags = await fetch6();
66042
- return flags[name];
66043
- }
66203
+ };
66204
+ var flags = new FlagSet({
66205
+ LICENSING: Flag.boolean(false),
66206
+ GOOGLE_SHEETS: Flag.boolean(false),
66207
+ USER_GROUPS: Flag.boolean(false),
66208
+ ONBOARDING_TOUR: Flag.boolean(false)
66209
+ });
66044
66210
 
66045
66211
  // src/auth/index.ts
66046
66212
  var auth_exports = {};
@@ -66657,7 +66823,7 @@ function readBytes(stream3, length) {
66657
66823
  }
66658
66824
 
66659
66825
  // src/middleware/authenticated.ts
66660
- var import_dd_trace3 = __toESM(require("dd-trace"));
66826
+ var import_dd_trace4 = __toESM(require("dd-trace"));
66661
66827
  var ONE_MINUTE = environment_default.SESSION_UPDATE_PERIOD ? parseInt(environment_default.SESSION_UPDATE_PERIOD) : 60 * 1e3;
66662
66828
  function timeMinusOneMinute() {
66663
66829
  return new Date(Date.now() - ONE_MINUTE).toISOString();
@@ -66771,7 +66937,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
66771
66937
  return user2 && user2.email;
66772
66938
  };
66773
66939
  if (isUser(user)) {
66774
- import_dd_trace3.default.setUser({
66940
+ import_dd_trace4.default.setUser({
66775
66941
  id: user._id,
66776
66942
  tenantId: user.tenantId,
66777
66943
  budibaseAccess: user.budibaseAccess,
@@ -67415,7 +67581,7 @@ async function isBlacklisted(address) {
67415
67581
  // src/docUpdates/index.ts
67416
67582
  var docUpdates_exports = {};
67417
67583
  __export(docUpdates_exports, {
67418
- init: () => init8
67584
+ init: () => init9
67419
67585
  });
67420
67586
 
67421
67587
  // src/events/documentId.ts
@@ -67473,7 +67639,7 @@ var DocumentUpdateProcessor = class {
67473
67639
  // src/docUpdates/index.ts
67474
67640
  var processingPromise;
67475
67641
  var documentProcessor;
67476
- function init8(processors2) {
67642
+ function init9(processors2) {
67477
67643
  if (!asyncEventQueue) {
67478
67644
  init5();
67479
67645
  }
@@ -67507,21 +67673,27 @@ function isIgnoredType(type) {
67507
67673
  return ignored.indexOf(type) !== -1;
67508
67674
  }
67509
67675
  function generateSchema(schema, table, tables, oldTable = null, renamed) {
67510
- let primaryKey = table && table.primary ? table.primary[0] : null;
67676
+ let primaryKeys = table && table.primary ? table.primary : [];
67511
67677
  const columns = Object.values(table.schema);
67512
67678
  let metaCols = columns.filter((col) => col.meta);
67513
67679
  let isJunction = metaCols.length === columns.length;
67514
- if (primaryKey && !oldTable && !isJunction) {
67515
- schema.increments(primaryKey).primary();
67516
- } else if (!oldTable && isJunction) {
67517
- schema.primary(metaCols.map((col) => col.name));
67680
+ let columnTypeSet = [];
67681
+ if (!oldTable) {
67682
+ if (isJunction) {
67683
+ schema.primary(metaCols.map((col) => col.name));
67684
+ } else if (primaryKeys.length === 1) {
67685
+ schema.increments(primaryKeys[0]).primary();
67686
+ columnTypeSet.push(primaryKeys[0]);
67687
+ } else {
67688
+ schema.primary(primaryKeys);
67689
+ }
67518
67690
  }
67519
67691
  const foreignKeys = Object.values(table.schema).map(
67520
67692
  (col) => col.foreignKey
67521
67693
  );
67522
67694
  for (let [key, column] of Object.entries(table.schema)) {
67523
67695
  const oldColumn = oldTable ? oldTable.schema[key] : null;
67524
- if (oldColumn && oldColumn.type || primaryKey === key && !isJunction || renamed?.updated === key) {
67696
+ if (oldColumn && oldColumn.type || columnTypeSet.includes(key) || renamed?.updated === key) {
67525
67697
  continue;
67526
67698
  }
67527
67699
  const columnType = column.type;
@@ -67531,7 +67703,11 @@ function generateSchema(schema, table, tables, oldTable = null, renamed) {
67531
67703
  case "longform" /* LONGFORM */:
67532
67704
  case "barcodeqr" /* BARCODEQR */:
67533
67705
  case "bb_reference_single" /* BB_REFERENCE_SINGLE */:
67534
- schema.text(key);
67706
+ if (primaryKeys.includes(key)) {
67707
+ schema.string(key, 255);
67708
+ } else {
67709
+ schema.text(key);
67710
+ }
67535
67711
  break;
67536
67712
  case "number" /* NUMBER */:
67537
67713
  if (column.meta && column.meta.toKey && column.meta.toTable) {
@@ -68663,7 +68839,7 @@ var tenancy = {
68663
68839
  ...tenancy_exports,
68664
68840
  ...context_exports
68665
68841
  };
68666
- var init9 = (opts = {}) => {
68842
+ var init10 = (opts = {}) => {
68667
68843
  init(opts.db);
68668
68844
  };
68669
68845
  // Annotate the CommonJS export names for ESM import in node:
@@ -68738,12 +68914,14 @@ var init9 = (opts = {}) => {
68738
68914
  roles,
68739
68915
  security,
68740
68916
  sessions,
68917
+ setEnv,
68741
68918
  sql,
68742
68919
  tenancy,
68743
68920
  timers,
68744
68921
  userUtils,
68745
68922
  users,
68746
- utils
68923
+ utils,
68924
+ withEnv
68747
68925
  });
68748
68926
  /*! Bundled license information:
68749
68927