@base44-preview/cli 0.0.32-pr.248.70443e1 → 0.0.32-pr.249.15900d9
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/cli/index.js +363 -48
- package/dist/cli/index.js.map +12 -9
- package/dist/deno-runtime/main.js +31 -0
- package/dist/deno-runtime/main.js.map +10 -0
- package/package.json +2 -1
package/dist/cli/index.js
CHANGED
|
@@ -178102,6 +178102,18 @@ class InvalidInputError extends UserError {
|
|
|
178102
178102
|
code = "INVALID_INPUT";
|
|
178103
178103
|
}
|
|
178104
178104
|
|
|
178105
|
+
class DependencyNotFoundError extends UserError {
|
|
178106
|
+
code = "DEPENDENCY_NOT_FOUND";
|
|
178107
|
+
constructor(message, options) {
|
|
178108
|
+
super(message, {
|
|
178109
|
+
hints: options?.hints ?? [
|
|
178110
|
+
{ message: "Install the required dependency and try again" }
|
|
178111
|
+
],
|
|
178112
|
+
cause: options?.cause
|
|
178113
|
+
});
|
|
178114
|
+
}
|
|
178115
|
+
}
|
|
178116
|
+
|
|
178105
178117
|
class ApiError extends SystemError {
|
|
178106
178118
|
code = "API_ERROR";
|
|
178107
178119
|
statusCode;
|
|
@@ -178217,6 +178229,21 @@ class FileReadError extends SystemError {
|
|
|
178217
178229
|
});
|
|
178218
178230
|
}
|
|
178219
178231
|
}
|
|
178232
|
+
|
|
178233
|
+
class InternalError extends SystemError {
|
|
178234
|
+
code = "INTERNAL_ERROR";
|
|
178235
|
+
constructor(message, options) {
|
|
178236
|
+
super(message, {
|
|
178237
|
+
hints: options?.hints ?? [
|
|
178238
|
+
{
|
|
178239
|
+
message: "This is an unexpected error. Please report it if it persists."
|
|
178240
|
+
}
|
|
178241
|
+
],
|
|
178242
|
+
cause: options?.cause
|
|
178243
|
+
});
|
|
178244
|
+
}
|
|
178245
|
+
}
|
|
178246
|
+
|
|
178220
178247
|
class TypeGenerationError extends SystemError {
|
|
178221
178248
|
code = "TYPE_GENERATION_ERROR";
|
|
178222
178249
|
entityName;
|
|
@@ -185051,6 +185078,10 @@ var TikTokConnectorSchema = exports_external.object({
|
|
|
185051
185078
|
type: exports_external.literal("tiktok"),
|
|
185052
185079
|
scopes: exports_external.array(exports_external.string()).default([])
|
|
185053
185080
|
});
|
|
185081
|
+
var GoogleBigQueryConnectorSchema = exports_external.object({
|
|
185082
|
+
type: exports_external.literal("googlebigquery"),
|
|
185083
|
+
scopes: exports_external.array(exports_external.string()).default([])
|
|
185084
|
+
});
|
|
185054
185085
|
var CustomTypeSchema = exports_external.string().min(1).regex(/^[a-z0-9_-]+$/i);
|
|
185055
185086
|
var GenericConnectorSchema = exports_external.object({
|
|
185056
185087
|
type: CustomTypeSchema,
|
|
@@ -185063,6 +185094,7 @@ var ConnectorResourceSchema = exports_external.union([
|
|
|
185063
185094
|
GoogleSheetsConnectorSchema,
|
|
185064
185095
|
GoogleDocsConnectorSchema,
|
|
185065
185096
|
GoogleSlidesConnectorSchema,
|
|
185097
|
+
GoogleBigQueryConnectorSchema,
|
|
185066
185098
|
SlackConnectorSchema,
|
|
185067
185099
|
NotionConnectorSchema,
|
|
185068
185100
|
SalesforceConnectorSchema,
|
|
@@ -185078,6 +185110,7 @@ var KnownIntegrationTypes = [
|
|
|
185078
185110
|
"googlesheets",
|
|
185079
185111
|
"googledocs",
|
|
185080
185112
|
"googleslides",
|
|
185113
|
+
"googlebigquery",
|
|
185081
185114
|
"slack",
|
|
185082
185115
|
"notion",
|
|
185083
185116
|
"salesforce",
|
|
@@ -185340,7 +185373,10 @@ var connectorResource = {
|
|
|
185340
185373
|
// src/core/resources/entity/schema.ts
|
|
185341
185374
|
var FieldConditionSchema = exports_external.union([
|
|
185342
185375
|
exports_external.string(),
|
|
185343
|
-
exports_external.
|
|
185376
|
+
exports_external.number(),
|
|
185377
|
+
exports_external.boolean(),
|
|
185378
|
+
exports_external.null(),
|
|
185379
|
+
exports_external.looseObject({
|
|
185344
185380
|
$in: exports_external.unknown().optional(),
|
|
185345
185381
|
$nin: exports_external.unknown().optional(),
|
|
185346
185382
|
$ne: exports_external.unknown().optional(),
|
|
@@ -185357,6 +185393,15 @@ var rlsConditionAllowedKeys = new Set([
|
|
|
185357
185393
|
"user_condition",
|
|
185358
185394
|
"created_by",
|
|
185359
185395
|
"created_by_id",
|
|
185396
|
+
"id",
|
|
185397
|
+
"_id",
|
|
185398
|
+
"created_date",
|
|
185399
|
+
"updated_date",
|
|
185400
|
+
"app_id",
|
|
185401
|
+
"entity_name",
|
|
185402
|
+
"is_deleted",
|
|
185403
|
+
"deleted_date",
|
|
185404
|
+
"environment",
|
|
185360
185405
|
"$or",
|
|
185361
185406
|
"$and",
|
|
185362
185407
|
"$nor"
|
|
@@ -185385,60 +185430,33 @@ var isValidFieldCondition = (value) => {
|
|
|
185385
185430
|
}
|
|
185386
185431
|
return false;
|
|
185387
185432
|
};
|
|
185388
|
-
var RefineRLSConditionSchema = RLSConditionSchema.refine((val) => Object.entries(val).every(([key, value]) =>
|
|
185389
|
-
if (rlsConditionAllowedKeys.has(key)) {
|
|
185390
|
-
return true;
|
|
185391
|
-
}
|
|
185392
|
-
if (!key.startsWith("data.")) {
|
|
185393
|
-
return false;
|
|
185394
|
-
}
|
|
185395
|
-
return isValidFieldCondition(value);
|
|
185396
|
-
}), "Keys must be known RLS keys or match data.* pattern with valid value");
|
|
185433
|
+
var RefineRLSConditionSchema = RLSConditionSchema.refine((val) => Object.entries(val).every(([key, value]) => rlsConditionAllowedKeys.has(key) || isValidFieldCondition(value)), "Field condition values must be a primitive or an operator object ($in, $nin, $ne, $all)");
|
|
185397
185434
|
var RLSRuleSchema = exports_external.union([exports_external.boolean(), RefineRLSConditionSchema]);
|
|
185398
|
-
var EntityRLSSchema = exports_external.
|
|
185435
|
+
var EntityRLSSchema = exports_external.looseObject({
|
|
185399
185436
|
create: RLSRuleSchema.optional(),
|
|
185400
185437
|
read: RLSRuleSchema.optional(),
|
|
185401
185438
|
update: RLSRuleSchema.optional(),
|
|
185402
185439
|
delete: RLSRuleSchema.optional(),
|
|
185403
185440
|
write: RLSRuleSchema.optional()
|
|
185404
185441
|
});
|
|
185405
|
-
var FieldRLSSchema = exports_external.
|
|
185442
|
+
var FieldRLSSchema = exports_external.looseObject({
|
|
185406
185443
|
read: RLSRuleSchema.optional(),
|
|
185407
185444
|
write: RLSRuleSchema.optional(),
|
|
185408
185445
|
create: RLSRuleSchema.optional(),
|
|
185409
185446
|
update: RLSRuleSchema.optional(),
|
|
185410
185447
|
delete: RLSRuleSchema.optional()
|
|
185411
185448
|
});
|
|
185412
|
-
var
|
|
185413
|
-
|
|
185414
|
-
"number",
|
|
185415
|
-
"integer",
|
|
185416
|
-
"boolean",
|
|
185417
|
-
"array",
|
|
185418
|
-
"object"
|
|
185419
|
-
]);
|
|
185420
|
-
var StringFormatSchema = exports_external.enum([
|
|
185421
|
-
"date",
|
|
185422
|
-
"date-time",
|
|
185423
|
-
"time",
|
|
185424
|
-
"email",
|
|
185425
|
-
"uri",
|
|
185426
|
-
"hostname",
|
|
185427
|
-
"ipv4",
|
|
185428
|
-
"ipv6",
|
|
185429
|
-
"uuid"
|
|
185430
|
-
]);
|
|
185431
|
-
var PropertyDefinitionSchema = exports_external.object({
|
|
185432
|
-
type: PropertyTypeSchema,
|
|
185449
|
+
var PropertyDefinitionSchema = exports_external.looseObject({
|
|
185450
|
+
type: exports_external.string().optional(),
|
|
185433
185451
|
title: exports_external.string().optional(),
|
|
185434
185452
|
description: exports_external.string().optional(),
|
|
185435
185453
|
minLength: exports_external.number().int().min(0).optional(),
|
|
185436
185454
|
maxLength: exports_external.number().int().min(0).optional(),
|
|
185437
185455
|
pattern: exports_external.string().optional(),
|
|
185438
|
-
format:
|
|
185456
|
+
format: exports_external.string().optional(),
|
|
185439
185457
|
minimum: exports_external.number().optional(),
|
|
185440
185458
|
maximum: exports_external.number().optional(),
|
|
185441
|
-
enum: exports_external.array(exports_external.
|
|
185459
|
+
enum: exports_external.array(exports_external.unknown()).optional(),
|
|
185442
185460
|
enumNames: exports_external.array(exports_external.string()).optional(),
|
|
185443
185461
|
default: exports_external.unknown().optional(),
|
|
185444
185462
|
$ref: exports_external.string().optional(),
|
|
@@ -185451,12 +185469,12 @@ var PropertyDefinitionSchema = exports_external.object({
|
|
|
185451
185469
|
return exports_external.record(exports_external.string(), PropertyDefinitionSchema).optional();
|
|
185452
185470
|
}
|
|
185453
185471
|
});
|
|
185454
|
-
var EntitySchema = exports_external.
|
|
185455
|
-
type: exports_external.literal("object"),
|
|
185456
|
-
name: exports_external.string().regex(/^[a-zA-Z0-9]+$/, "Entity name must be alphanumeric only"),
|
|
185472
|
+
var EntitySchema = exports_external.looseObject({
|
|
185473
|
+
type: exports_external.literal("object").default("object"),
|
|
185474
|
+
name: exports_external.string().min(1).regex(/^[a-zA-Z0-9]+$/, "Entity name must be alphanumeric only"),
|
|
185457
185475
|
title: exports_external.string().optional(),
|
|
185458
185476
|
description: exports_external.string().optional(),
|
|
185459
|
-
properties: exports_external.record(exports_external.string(), PropertyDefinitionSchema),
|
|
185477
|
+
properties: exports_external.record(exports_external.string(), PropertyDefinitionSchema).default({}),
|
|
185460
185478
|
required: exports_external.array(exports_external.string()).optional(),
|
|
185461
185479
|
rls: EntityRLSSchema.optional()
|
|
185462
185480
|
});
|
|
@@ -186024,7 +186042,7 @@ async function handleUnauthorized(request, _options, response) {
|
|
|
186024
186042
|
return;
|
|
186025
186043
|
}
|
|
186026
186044
|
retriedRequests.add(request);
|
|
186027
|
-
return distribution_default(request, {
|
|
186045
|
+
return distribution_default(request.clone(), {
|
|
186028
186046
|
headers: { Authorization: `Bearer ${newAccessToken}` }
|
|
186029
186047
|
});
|
|
186030
186048
|
}
|
|
@@ -193486,6 +193504,7 @@ var package_default = {
|
|
|
193486
193504
|
"@types/bun": "^1.2.15",
|
|
193487
193505
|
"@types/common-tags": "^1.8.4",
|
|
193488
193506
|
"@types/cors": "^2.8.19",
|
|
193507
|
+
"@types/deno": "^2.5.0",
|
|
193489
193508
|
"@types/ejs": "^3.1.5",
|
|
193490
193509
|
"@types/express": "^5.0.6",
|
|
193491
193510
|
"@types/json-schema": "^7.0.15",
|
|
@@ -195206,8 +195225,9 @@ function getTypesCommand(context) {
|
|
|
195206
195225
|
}
|
|
195207
195226
|
|
|
195208
195227
|
// src/cli/dev/dev-server/main.ts
|
|
195228
|
+
import { dirname as dirname12, join as join16 } from "node:path";
|
|
195209
195229
|
var import_cors = __toESM(require_lib4(), 1);
|
|
195210
|
-
var
|
|
195230
|
+
var import_express2 = __toESM(require_express(), 1);
|
|
195211
195231
|
|
|
195212
195232
|
// node_modules/get-port/index.js
|
|
195213
195233
|
import net from "node:net";
|
|
@@ -195325,11 +195345,288 @@ async function getPorts(options8) {
|
|
|
195325
195345
|
|
|
195326
195346
|
// src/cli/dev/dev-server/main.ts
|
|
195327
195347
|
var import_http_proxy_middleware = __toESM(require_dist2(), 1);
|
|
195348
|
+
|
|
195349
|
+
// src/cli/dev/createDevLogger.ts
|
|
195350
|
+
var dateTimeFormat = new Intl.DateTimeFormat([], {
|
|
195351
|
+
hour: "2-digit",
|
|
195352
|
+
minute: "2-digit",
|
|
195353
|
+
second: "2-digit",
|
|
195354
|
+
hour12: false
|
|
195355
|
+
});
|
|
195356
|
+
var colorByType = {
|
|
195357
|
+
error: source_default.red,
|
|
195358
|
+
warn: source_default.yellow,
|
|
195359
|
+
log: (text) => text
|
|
195360
|
+
};
|
|
195361
|
+
function createDevLogger(isPrefixed = true) {
|
|
195362
|
+
const print = (type, msg) => {
|
|
195363
|
+
const colorize = colorByType[type];
|
|
195364
|
+
switch (type) {
|
|
195365
|
+
case "error":
|
|
195366
|
+
console.error(colorize(msg));
|
|
195367
|
+
break;
|
|
195368
|
+
case "warn":
|
|
195369
|
+
console.warn(colorize(msg));
|
|
195370
|
+
break;
|
|
195371
|
+
default:
|
|
195372
|
+
console.log(msg);
|
|
195373
|
+
}
|
|
195374
|
+
};
|
|
195375
|
+
const prefixedLog = (type, msg) => {
|
|
195376
|
+
const timestamp = dateTimeFormat.format(new Date);
|
|
195377
|
+
const colorize = colorByType[type];
|
|
195378
|
+
console.log(`${source_default.gray(timestamp)} ${colorize(msg)}`);
|
|
195379
|
+
};
|
|
195380
|
+
return isPrefixed ? {
|
|
195381
|
+
log: (msg) => prefixedLog("log", msg),
|
|
195382
|
+
error: (msg, err) => {
|
|
195383
|
+
prefixedLog("error", msg);
|
|
195384
|
+
if (err) {
|
|
195385
|
+
prefixedLog("error", String(err));
|
|
195386
|
+
}
|
|
195387
|
+
},
|
|
195388
|
+
warn: (msg) => prefixedLog("warn", msg)
|
|
195389
|
+
} : {
|
|
195390
|
+
log: (msg) => print("log", msg),
|
|
195391
|
+
error: (msg, err) => {
|
|
195392
|
+
print("error", msg);
|
|
195393
|
+
if (err) {
|
|
195394
|
+
print("error", String(err));
|
|
195395
|
+
}
|
|
195396
|
+
},
|
|
195397
|
+
warn: (msg) => print("warn", msg)
|
|
195398
|
+
};
|
|
195399
|
+
}
|
|
195400
|
+
|
|
195401
|
+
// src/cli/dev/dev-server/function-manager.ts
|
|
195402
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
195403
|
+
import { dirname as dirname11, join as join15 } from "node:path";
|
|
195404
|
+
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
195405
|
+
var __dirname5 = dirname11(fileURLToPath7(import.meta.url));
|
|
195406
|
+
var WRAPPER_PATH = join15(__dirname5, "../deno-runtime/main.js");
|
|
195407
|
+
var READY_TIMEOUT = 30000;
|
|
195408
|
+
|
|
195409
|
+
class FunctionManager {
|
|
195410
|
+
functions;
|
|
195411
|
+
running = new Map;
|
|
195412
|
+
logger;
|
|
195413
|
+
constructor(functions, logger) {
|
|
195414
|
+
this.functions = new Map(functions.map((f7) => [f7.name, f7]));
|
|
195415
|
+
this.logger = logger;
|
|
195416
|
+
}
|
|
195417
|
+
functionNames() {
|
|
195418
|
+
return Array.from(this.functions.keys());
|
|
195419
|
+
}
|
|
195420
|
+
getFunction(name2) {
|
|
195421
|
+
return this.functions.get(name2);
|
|
195422
|
+
}
|
|
195423
|
+
verifyDenoIsInstalled() {
|
|
195424
|
+
if (this.functions.size > 0) {
|
|
195425
|
+
try {
|
|
195426
|
+
spawn2("deno", ["--version"]);
|
|
195427
|
+
} catch {
|
|
195428
|
+
throw new DependencyNotFoundError("Deno is required to run functions", {
|
|
195429
|
+
hints: [{ message: "Install Deno from https://deno.com/download" }]
|
|
195430
|
+
});
|
|
195431
|
+
}
|
|
195432
|
+
}
|
|
195433
|
+
}
|
|
195434
|
+
async ensureRunning(name2) {
|
|
195435
|
+
const existing = this.running.get(name2);
|
|
195436
|
+
if (existing?.ready) {
|
|
195437
|
+
return existing.port;
|
|
195438
|
+
}
|
|
195439
|
+
const backendFunction = this.functions.get(name2);
|
|
195440
|
+
if (!backendFunction) {
|
|
195441
|
+
throw new InvalidInputError(`Function "${name2}" not found`, {
|
|
195442
|
+
hints: [{ message: "Check available functions in your project" }]
|
|
195443
|
+
});
|
|
195444
|
+
}
|
|
195445
|
+
if (existing && !existing.ready) {
|
|
195446
|
+
return this.waitForReady(name2, existing);
|
|
195447
|
+
}
|
|
195448
|
+
const port = await this.allocatePort();
|
|
195449
|
+
const process21 = this.spawnFunction(backendFunction, port);
|
|
195450
|
+
const runningFunc = {
|
|
195451
|
+
process: process21,
|
|
195452
|
+
port,
|
|
195453
|
+
ready: false
|
|
195454
|
+
};
|
|
195455
|
+
this.running.set(name2, runningFunc);
|
|
195456
|
+
this.setupProcessHandlers(name2, process21);
|
|
195457
|
+
return this.waitForReady(name2, runningFunc);
|
|
195458
|
+
}
|
|
195459
|
+
getPort(name2) {
|
|
195460
|
+
const running = this.running.get(name2);
|
|
195461
|
+
return running?.ready ? running.port : undefined;
|
|
195462
|
+
}
|
|
195463
|
+
stopAll() {
|
|
195464
|
+
for (const [name2, { process: process21 }] of this.running) {
|
|
195465
|
+
this.logger.log(`[dev-server] Stopping function: ${name2}`);
|
|
195466
|
+
process21.kill();
|
|
195467
|
+
}
|
|
195468
|
+
this.running.clear();
|
|
195469
|
+
}
|
|
195470
|
+
stop(name2) {
|
|
195471
|
+
const running = this.running.get(name2);
|
|
195472
|
+
if (running) {
|
|
195473
|
+
this.logger.log(`Stopping function: ${name2}`);
|
|
195474
|
+
running.process.kill();
|
|
195475
|
+
this.running.delete(name2);
|
|
195476
|
+
}
|
|
195477
|
+
}
|
|
195478
|
+
async allocatePort() {
|
|
195479
|
+
const usedPorts = Array.from(this.running.values()).map((r5) => r5.port);
|
|
195480
|
+
return getPorts({ exclude: usedPorts });
|
|
195481
|
+
}
|
|
195482
|
+
spawnFunction(func, port) {
|
|
195483
|
+
this.logger.log(`[dev-server] Spawning function "${func.name}" on port ${port}`);
|
|
195484
|
+
const process21 = spawn2("deno", ["run", "--allow-all", WRAPPER_PATH], {
|
|
195485
|
+
env: {
|
|
195486
|
+
...globalThis.process.env,
|
|
195487
|
+
FUNCTION_PATH: func.entryPath,
|
|
195488
|
+
FUNCTION_PORT: String(port),
|
|
195489
|
+
FUNCTION_NAME: func.name
|
|
195490
|
+
},
|
|
195491
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
195492
|
+
});
|
|
195493
|
+
return process21;
|
|
195494
|
+
}
|
|
195495
|
+
setupProcessHandlers(name2, process21) {
|
|
195496
|
+
process21.stdout?.on("data", (data) => {
|
|
195497
|
+
const lines = data.toString().trim().split(`
|
|
195498
|
+
`);
|
|
195499
|
+
for (const line3 of lines) {
|
|
195500
|
+
this.logger.log(line3);
|
|
195501
|
+
}
|
|
195502
|
+
});
|
|
195503
|
+
process21.stderr?.on("data", (data) => {
|
|
195504
|
+
const lines = data.toString().trim().split(`
|
|
195505
|
+
`);
|
|
195506
|
+
for (const line3 of lines) {
|
|
195507
|
+
this.logger.error(line3);
|
|
195508
|
+
}
|
|
195509
|
+
});
|
|
195510
|
+
process21.on("exit", (code2) => {
|
|
195511
|
+
this.logger.log(`[dev-server] Function "${name2}" exited with code ${code2}`);
|
|
195512
|
+
this.running.delete(name2);
|
|
195513
|
+
});
|
|
195514
|
+
process21.on("error", (error48) => {
|
|
195515
|
+
this.logger.error(`[dev-server] Function "${name2}" error:`, error48);
|
|
195516
|
+
this.running.delete(name2);
|
|
195517
|
+
});
|
|
195518
|
+
}
|
|
195519
|
+
waitForReady(name2, runningFunc) {
|
|
195520
|
+
return new Promise((resolve5, reject) => {
|
|
195521
|
+
const timeout3 = setTimeout(() => {
|
|
195522
|
+
reject(new InternalError(`Function "${name2}" failed to start within ${READY_TIMEOUT / 1000}s timeout`, {
|
|
195523
|
+
hints: [
|
|
195524
|
+
{ message: "Check the function code for startup errors" }
|
|
195525
|
+
]
|
|
195526
|
+
}));
|
|
195527
|
+
}, READY_TIMEOUT);
|
|
195528
|
+
const onData = (data) => {
|
|
195529
|
+
const output = data.toString();
|
|
195530
|
+
if (output.includes("Listening on")) {
|
|
195531
|
+
runningFunc.ready = true;
|
|
195532
|
+
clearTimeout(timeout3);
|
|
195533
|
+
runningFunc.process.stdout?.off("data", onData);
|
|
195534
|
+
resolve5(runningFunc.port);
|
|
195535
|
+
}
|
|
195536
|
+
};
|
|
195537
|
+
runningFunc.process.stdout?.on("data", onData);
|
|
195538
|
+
runningFunc.process.on("exit", (code2) => {
|
|
195539
|
+
if (!runningFunc.ready) {
|
|
195540
|
+
clearTimeout(timeout3);
|
|
195541
|
+
reject(new InternalError(`Function "${name2}" exited with code ${code2}`, {
|
|
195542
|
+
hints: [{ message: "Check the function code for errors" }]
|
|
195543
|
+
}));
|
|
195544
|
+
}
|
|
195545
|
+
});
|
|
195546
|
+
});
|
|
195547
|
+
}
|
|
195548
|
+
}
|
|
195549
|
+
|
|
195550
|
+
// src/cli/dev/dev-server/routes/functions.ts
|
|
195551
|
+
var import_express = __toESM(require_express(), 1);
|
|
195552
|
+
import { request as httpRequest } from "node:http";
|
|
195553
|
+
function createFunctionRoutes(manager, logger) {
|
|
195554
|
+
const router = import_express.Router({ mergeParams: true });
|
|
195555
|
+
router.all("/:functionName", async (req, res) => {
|
|
195556
|
+
const { functionName } = req.params;
|
|
195557
|
+
try {
|
|
195558
|
+
const func = manager.getFunction(functionName);
|
|
195559
|
+
if (!func) {
|
|
195560
|
+
res.status(404).json({
|
|
195561
|
+
error: `Function "${functionName}" not found`
|
|
195562
|
+
});
|
|
195563
|
+
return;
|
|
195564
|
+
}
|
|
195565
|
+
const port = await manager.ensureRunning(functionName);
|
|
195566
|
+
await proxyRequest(req, res, port, logger);
|
|
195567
|
+
} catch (error48) {
|
|
195568
|
+
logger.error(`Function error:`, error48);
|
|
195569
|
+
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
195570
|
+
res.status(500).json({ error: message });
|
|
195571
|
+
}
|
|
195572
|
+
});
|
|
195573
|
+
return router;
|
|
195574
|
+
}
|
|
195575
|
+
function proxyRequest(req, res, port, logger) {
|
|
195576
|
+
return new Promise((resolve5, reject) => {
|
|
195577
|
+
const headers = {
|
|
195578
|
+
...req.headers
|
|
195579
|
+
};
|
|
195580
|
+
delete headers.host;
|
|
195581
|
+
if (headers["x-app-id"]) {
|
|
195582
|
+
headers["Base44-App-Id"] = headers["x-app-id"];
|
|
195583
|
+
}
|
|
195584
|
+
headers["Base44-Api-Url"] = `${req.protocol}://${req.get("host")}`;
|
|
195585
|
+
const options8 = {
|
|
195586
|
+
hostname: "localhost",
|
|
195587
|
+
port,
|
|
195588
|
+
path: req.url,
|
|
195589
|
+
method: req.method,
|
|
195590
|
+
headers
|
|
195591
|
+
};
|
|
195592
|
+
const proxyReq = httpRequest(options8, (proxyRes) => {
|
|
195593
|
+
res.status(proxyRes.statusCode || 200);
|
|
195594
|
+
for (const [key2, value] of Object.entries(proxyRes.headers)) {
|
|
195595
|
+
if (value !== undefined) {
|
|
195596
|
+
res.setHeader(key2, value);
|
|
195597
|
+
}
|
|
195598
|
+
}
|
|
195599
|
+
proxyRes.pipe(res);
|
|
195600
|
+
proxyRes.on("end", () => {
|
|
195601
|
+
resolve5();
|
|
195602
|
+
});
|
|
195603
|
+
proxyRes.on("error", (error48) => {
|
|
195604
|
+
reject(error48);
|
|
195605
|
+
});
|
|
195606
|
+
});
|
|
195607
|
+
proxyReq.on("error", (error48) => {
|
|
195608
|
+
logger.error(`Function proxy error:`, error48);
|
|
195609
|
+
if (!res.headersSent) {
|
|
195610
|
+
res.status(502).json({
|
|
195611
|
+
error: "Failed to proxy request to function",
|
|
195612
|
+
details: error48.message
|
|
195613
|
+
});
|
|
195614
|
+
}
|
|
195615
|
+
resolve5();
|
|
195616
|
+
});
|
|
195617
|
+
req.pipe(proxyReq);
|
|
195618
|
+
});
|
|
195619
|
+
}
|
|
195620
|
+
|
|
195621
|
+
// src/cli/dev/dev-server/main.ts
|
|
195328
195622
|
var DEFAULT_PORT = 4400;
|
|
195329
195623
|
var BASE44_APP_URL = "https://base44.app";
|
|
195330
|
-
async function createDevServer(options8
|
|
195331
|
-
const
|
|
195332
|
-
const
|
|
195624
|
+
async function createDevServer(options8) {
|
|
195625
|
+
const { port: userPort } = options8;
|
|
195626
|
+
const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
|
|
195627
|
+
const { project: project2 } = await readProjectConfig();
|
|
195628
|
+
const configDir = dirname12(project2.configPath);
|
|
195629
|
+
const app = import_express2.default();
|
|
195333
195630
|
const remoteProxy = import_http_proxy_middleware.createProxyMiddleware({
|
|
195334
195631
|
target: BASE44_APP_URL,
|
|
195335
195632
|
changeOrigin: true
|
|
@@ -195346,6 +195643,17 @@ async function createDevServer(options8 = {}) {
|
|
|
195346
195643
|
}
|
|
195347
195644
|
next();
|
|
195348
195645
|
});
|
|
195646
|
+
const [functions] = await Promise.all([
|
|
195647
|
+
functionResource.readAll(join16(configDir, project2.functionsDir))
|
|
195648
|
+
]);
|
|
195649
|
+
const devLogger = createDevLogger(false);
|
|
195650
|
+
const functionManager = new FunctionManager(functions, devLogger);
|
|
195651
|
+
functionManager.verifyDenoIsInstalled();
|
|
195652
|
+
if (functionManager.functionNames().length > 0) {
|
|
195653
|
+
M2.info(`Loaded functions: ${functionManager.functionNames().join(", ")}`);
|
|
195654
|
+
}
|
|
195655
|
+
const functionRoutes = createFunctionRoutes(functionManager, devLogger);
|
|
195656
|
+
app.use("/api/apps/:appId/functions", functionRoutes);
|
|
195349
195657
|
app.use((req, res, next) => {
|
|
195350
195658
|
return remoteProxy(req, res, next);
|
|
195351
195659
|
});
|
|
@@ -195357,6 +195665,11 @@ async function createDevServer(options8 = {}) {
|
|
|
195357
195665
|
} else {
|
|
195358
195666
|
reject(err);
|
|
195359
195667
|
}
|
|
195668
|
+
const shutdown = () => {
|
|
195669
|
+
functionManager.stopAll();
|
|
195670
|
+
};
|
|
195671
|
+
process.on("SIGINT", shutdown);
|
|
195672
|
+
process.on("SIGTERM", shutdown);
|
|
195360
195673
|
} else {
|
|
195361
195674
|
resolve5({
|
|
195362
195675
|
port,
|
|
@@ -195370,7 +195683,9 @@ async function createDevServer(options8 = {}) {
|
|
|
195370
195683
|
// src/cli/commands/dev.ts
|
|
195371
195684
|
async function devAction(options8) {
|
|
195372
195685
|
const port = options8.port ? Number(options8.port) : undefined;
|
|
195373
|
-
const { port: resolvedPort } = await createDevServer({
|
|
195686
|
+
const { port: resolvedPort } = await createDevServer({
|
|
195687
|
+
port
|
|
195688
|
+
});
|
|
195374
195689
|
return {
|
|
195375
195690
|
outroMessage: `Dev server is available at ${theme.colors.links(`http://localhost:${resolvedPort}`)}`
|
|
195376
195691
|
};
|
|
@@ -195532,7 +195847,7 @@ function nanoid3(size = 21) {
|
|
|
195532
195847
|
}
|
|
195533
195848
|
|
|
195534
195849
|
// node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs
|
|
195535
|
-
import { dirname as
|
|
195850
|
+
import { dirname as dirname13, posix, sep } from "path";
|
|
195536
195851
|
function createModulerModifier() {
|
|
195537
195852
|
const getModuleFromFileName = createGetModuleFromFilename();
|
|
195538
195853
|
return async (frames) => {
|
|
@@ -195541,7 +195856,7 @@ function createModulerModifier() {
|
|
|
195541
195856
|
return frames;
|
|
195542
195857
|
};
|
|
195543
195858
|
}
|
|
195544
|
-
function createGetModuleFromFilename(basePath = process.argv[1] ?
|
|
195859
|
+
function createGetModuleFromFilename(basePath = process.argv[1] ? dirname13(process.argv[1]) : process.cwd(), isWindows4 = sep === "\\") {
|
|
195545
195860
|
const normalizedBase = isWindows4 ? normalizeWindowsPath2(basePath) : basePath;
|
|
195546
195861
|
return (filename) => {
|
|
195547
195862
|
if (!filename)
|
|
@@ -199760,4 +200075,4 @@ export {
|
|
|
199760
200075
|
CLIExitError
|
|
199761
200076
|
};
|
|
199762
200077
|
|
|
199763
|
-
//# debugId=
|
|
200078
|
+
//# debugId=235A3A90E106536A64756E2164756E21
|