@budibase/backend-core 2.13.30 → 2.13.32

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
@@ -2533,6 +2533,7 @@ function updateContext(updates) {
2533
2533
  return context;
2534
2534
  }
2535
2535
  async function newContext(updates, task) {
2536
+ guardMigration();
2536
2537
  let context = updateContext(updates);
2537
2538
  return Context.run(context, task);
2538
2539
  }
@@ -2565,18 +2566,16 @@ async function doInTenant(tenantId, task) {
2565
2566
  return newContext(updates, task);
2566
2567
  }
2567
2568
  async function doInAppContext(appId, task) {
2568
- if (!appId && !environment_default.isTest()) {
2569
+ return _doInAppContext(appId, task);
2570
+ }
2571
+ async function _doInAppContext(appId, task, extraContextSettings) {
2572
+ if (!appId) {
2569
2573
  throw new Error("appId is required");
2570
2574
  }
2571
- let updates;
2572
- if (!appId) {
2573
- updates = { appId: "" };
2574
- } else {
2575
- const tenantId = getTenantIDFromAppID(appId);
2576
- updates = { appId };
2577
- if (tenantId) {
2578
- updates.tenantId = tenantId;
2579
- }
2575
+ const tenantId = getTenantIDFromAppID(appId);
2576
+ const updates = { appId, ...extraContextSettings };
2577
+ if (tenantId) {
2578
+ updates.tenantId = tenantId;
2580
2579
  }
2581
2580
  return newContext(updates, task);
2582
2581
  }
@@ -2592,6 +2591,19 @@ async function doInIdentityContext(identity, task) {
2592
2591
  }
2593
2592
  return newContext(context, task);
2594
2593
  }
2594
+ function guardMigration() {
2595
+ const context = Context.get();
2596
+ if (context?.isMigrating) {
2597
+ throw new Error(
2598
+ "The context cannot be changed, a migration is currently running"
2599
+ );
2600
+ }
2601
+ }
2602
+ async function doInAppMigrationContext(appId, task) {
2603
+ return _doInAppContext(appId, task, {
2604
+ isMigrating: true
2605
+ });
2606
+ }
2595
2607
  function getIdentity() {
2596
2608
  try {
2597
2609
  const context = Context.get();
@@ -2711,6 +2723,7 @@ __export(context_exports, {
2711
2723
  DEFAULT_TENANT_ID: () => DEFAULT_TENANT_ID,
2712
2724
  baseGlobalDBName: () => baseGlobalDBName,
2713
2725
  doInAppContext: () => doInAppContext,
2726
+ doInAppMigrationContext: () => doInAppMigrationContext,
2714
2727
  doInAutomationContext: () => doInAutomationContext,
2715
2728
  doInContext: () => doInContext,
2716
2729
  doInEnvironmentContext: () => doInEnvironmentContext,
@@ -6216,9 +6229,16 @@ var getTenantIDFromCtx = (ctx, opts) => {
6216
6229
  }
6217
6230
  }
6218
6231
  if (isAllowed("subdomain" /* SUBDOMAIN */)) {
6219
- const platformHost = new URL(getPlatformURL()).host.split(":")[0];
6232
+ let platformHost;
6233
+ try {
6234
+ platformHost = new URL(getPlatformURL()).host.split(":")[0];
6235
+ } catch (err) {
6236
+ if (err.code !== "ERR_INVALID_URL") {
6237
+ throw err;
6238
+ }
6239
+ }
6220
6240
  const requestHost = ctx.host;
6221
- if (requestHost.includes(platformHost)) {
6241
+ if (platformHost && requestHost.includes(platformHost)) {
6222
6242
  const tenantId = requestHost.substring(
6223
6243
  0,
6224
6244
  requestHost.indexOf(`.${platformHost}`)