@base44-preview/cli 0.0.32-pr.249.da1c23d → 0.0.32-pr.249.f0fa2ca
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/LICENSE +21 -0
- package/dist/cli/index.js +210 -211
- package/dist/cli/index.js.map +22 -22
- package/package.json +2 -2
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
|
}
|
|
@@ -186663,7 +186681,9 @@ var theme = {
|
|
|
186663
186681
|
styles: {
|
|
186664
186682
|
header: source_default.dim,
|
|
186665
186683
|
bold: source_default.bold,
|
|
186666
|
-
dim: source_default.dim
|
|
186684
|
+
dim: source_default.dim,
|
|
186685
|
+
error: source_default.red,
|
|
186686
|
+
warn: source_default.yellow
|
|
186667
186687
|
},
|
|
186668
186688
|
format: {
|
|
186669
186689
|
errorContext(ctx) {
|
|
@@ -186765,12 +186785,12 @@ var BANNER_LINES = [
|
|
|
186765
186785
|
"██████╔╝██║ ██║███████║███████╗ ██║ ██║",
|
|
186766
186786
|
"╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝"
|
|
186767
186787
|
];
|
|
186768
|
-
async function printBanner() {
|
|
186769
|
-
if (
|
|
186770
|
-
await printAnimatedLines(BANNER_LINES);
|
|
186771
|
-
} else {
|
|
186788
|
+
async function printBanner(isNonInteractive) {
|
|
186789
|
+
if (isNonInteractive) {
|
|
186772
186790
|
console.log(theme.colors.base44Orange(BANNER_LINES.join(`
|
|
186773
186791
|
`)));
|
|
186792
|
+
} else {
|
|
186793
|
+
await printAnimatedLines(BANNER_LINES);
|
|
186774
186794
|
}
|
|
186775
186795
|
}
|
|
186776
186796
|
// src/cli/errors.ts
|
|
@@ -193475,7 +193495,7 @@ var package_default = {
|
|
|
193475
193495
|
"command-line"
|
|
193476
193496
|
],
|
|
193477
193497
|
author: "",
|
|
193478
|
-
license: "
|
|
193498
|
+
license: "MIT",
|
|
193479
193499
|
repository: {
|
|
193480
193500
|
type: "git",
|
|
193481
193501
|
url: "https://github.com/base44/cli"
|
|
@@ -193575,7 +193595,7 @@ async function printUpgradeNotificationIfAvailable() {
|
|
|
193575
193595
|
async function runCommand(commandFn, options, context) {
|
|
193576
193596
|
console.log();
|
|
193577
193597
|
if (options?.fullBanner) {
|
|
193578
|
-
await printBanner();
|
|
193598
|
+
await printBanner(context.isNonInteractive);
|
|
193579
193599
|
Ie("");
|
|
193580
193600
|
} else {
|
|
193581
193601
|
Ie(theme.colors.base44OrangeBackground(" Base 44 "));
|
|
@@ -194505,7 +194525,7 @@ function printSummary(results, oauthOutcomes) {
|
|
|
194505
194525
|
M2.error(`Failed: ${r2.type}${r2.error ? ` - ${r2.error}` : ""}`);
|
|
194506
194526
|
}
|
|
194507
194527
|
}
|
|
194508
|
-
async function pushConnectorsAction() {
|
|
194528
|
+
async function pushConnectorsAction(isNonInteractive) {
|
|
194509
194529
|
const { connectors } = await readProjectConfig();
|
|
194510
194530
|
if (connectors.length === 0) {
|
|
194511
194531
|
M2.info("No local connectors found - checking for remote connectors to remove");
|
|
@@ -194519,18 +194539,18 @@ async function pushConnectorsAction() {
|
|
|
194519
194539
|
const needsOAuth = filterPendingOAuth(results);
|
|
194520
194540
|
let outroMessage = "Connectors pushed to Base44";
|
|
194521
194541
|
const oauthOutcomes = await promptOAuthFlows(needsOAuth, {
|
|
194522
|
-
skipPrompt:
|
|
194542
|
+
skipPrompt: isNonInteractive
|
|
194523
194543
|
});
|
|
194524
194544
|
const allAuthorized = oauthOutcomes.size > 0 && [...oauthOutcomes.values()].every((s) => s === "ACTIVE");
|
|
194525
194545
|
if (needsOAuth.length > 0 && !allAuthorized) {
|
|
194526
|
-
outroMessage =
|
|
194546
|
+
outroMessage = isNonInteractive ? "Skipped OAuth in non-interactive mode. Run 'base44 connectors push' locally or open the links above to authorize." : "Some connectors still require authorization. Run 'base44 connectors push' or open the links above to authorize.";
|
|
194527
194547
|
}
|
|
194528
194548
|
printSummary(results, oauthOutcomes);
|
|
194529
194549
|
return { outroMessage };
|
|
194530
194550
|
}
|
|
194531
194551
|
function getConnectorsPushCommand(context) {
|
|
194532
194552
|
return new Command("push").description("Push local connectors to Base44 (overwrites connectors on Base44)").action(async () => {
|
|
194533
|
-
await runCommand(pushConnectorsAction, { requireAuth: true }, context);
|
|
194553
|
+
await runCommand(() => pushConnectorsAction(context.isNonInteractive), { requireAuth: true }, context);
|
|
194534
194554
|
});
|
|
194535
194555
|
}
|
|
194536
194556
|
|
|
@@ -194540,16 +194560,16 @@ function getConnectorsCommand(context) {
|
|
|
194540
194560
|
}
|
|
194541
194561
|
|
|
194542
194562
|
// src/cli/commands/dashboard/open.ts
|
|
194543
|
-
async function openDashboard() {
|
|
194563
|
+
async function openDashboard(isNonInteractive) {
|
|
194544
194564
|
const dashboardUrl = getDashboardUrl();
|
|
194545
|
-
if (!
|
|
194565
|
+
if (!isNonInteractive) {
|
|
194546
194566
|
await open_default(dashboardUrl);
|
|
194547
194567
|
}
|
|
194548
194568
|
return { outroMessage: `Dashboard opened at ${dashboardUrl}` };
|
|
194549
194569
|
}
|
|
194550
194570
|
function getDashboardOpenCommand(context) {
|
|
194551
194571
|
return new Command("open").description("Open the app dashboard in your browser").action(async () => {
|
|
194552
|
-
await runCommand(openDashboard, { requireAuth: true }, context);
|
|
194572
|
+
await runCommand(() => openDashboard(context.isNonInteractive), { requireAuth: true }, context);
|
|
194553
194573
|
});
|
|
194554
194574
|
}
|
|
194555
194575
|
|
|
@@ -194855,7 +194875,7 @@ ${summaryLines.join(`
|
|
|
194855
194875
|
const needsOAuth = filterPendingOAuth(result.connectorResults ?? []);
|
|
194856
194876
|
if (needsOAuth.length > 0) {
|
|
194857
194877
|
const oauthOutcomes = await promptOAuthFlows(needsOAuth, {
|
|
194858
|
-
skipPrompt: options.yes ||
|
|
194878
|
+
skipPrompt: options.yes || options.isNonInteractive
|
|
194859
194879
|
});
|
|
194860
194880
|
const allAuthorized = oauthOutcomes.size > 0 && [...oauthOutcomes.values()].every((s) => s === "ACTIVE");
|
|
194861
194881
|
if (!allAuthorized) {
|
|
@@ -194870,7 +194890,10 @@ ${summaryLines.join(`
|
|
|
194870
194890
|
}
|
|
194871
194891
|
function getDeployCommand(context) {
|
|
194872
194892
|
return new Command("deploy").description("Deploy all project resources (entities, functions, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
|
|
194873
|
-
await runCommand(() => deployAction(
|
|
194893
|
+
await runCommand(() => deployAction({
|
|
194894
|
+
...options,
|
|
194895
|
+
isNonInteractive: context.isNonInteractive
|
|
194896
|
+
}), { requireAuth: true }, context);
|
|
194874
194897
|
});
|
|
194875
194898
|
}
|
|
194876
194899
|
|
|
@@ -195052,21 +195075,24 @@ async function deployAction2(options) {
|
|
|
195052
195075
|
}
|
|
195053
195076
|
function getSiteDeployCommand(context) {
|
|
195054
195077
|
return new Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
|
|
195055
|
-
await runCommand(() => deployAction2(
|
|
195078
|
+
await runCommand(() => deployAction2({
|
|
195079
|
+
...options,
|
|
195080
|
+
isNonInteractive: context.isNonInteractive
|
|
195081
|
+
}), { requireAuth: true }, context);
|
|
195056
195082
|
});
|
|
195057
195083
|
}
|
|
195058
195084
|
|
|
195059
195085
|
// src/cli/commands/site/open.ts
|
|
195060
|
-
async function openAction() {
|
|
195086
|
+
async function openAction(isNonInteractive) {
|
|
195061
195087
|
const siteUrl = await getSiteUrl();
|
|
195062
|
-
if (!
|
|
195088
|
+
if (!isNonInteractive) {
|
|
195063
195089
|
await open_default(siteUrl);
|
|
195064
195090
|
}
|
|
195065
195091
|
return { outroMessage: `Site opened at ${siteUrl}` };
|
|
195066
195092
|
}
|
|
195067
195093
|
function getSiteOpenCommand(context) {
|
|
195068
195094
|
return new Command("open").description("Open the published site in your browser").action(async () => {
|
|
195069
|
-
await runCommand(openAction, { requireAuth: true }, context);
|
|
195095
|
+
await runCommand(() => openAction(context.isNonInteractive), { requireAuth: true }, context);
|
|
195070
195096
|
});
|
|
195071
195097
|
}
|
|
195072
195098
|
|
|
@@ -195206,62 +195232,10 @@ function getTypesCommand(context) {
|
|
|
195206
195232
|
return new Command("types").description("Manage TypeScript type generation").addCommand(getTypesGenerateCommand(context));
|
|
195207
195233
|
}
|
|
195208
195234
|
|
|
195209
|
-
// src/cli/dev/createDevLogger.ts
|
|
195210
|
-
var dateTimeFormat = new Intl.DateTimeFormat([], {
|
|
195211
|
-
hour: "2-digit",
|
|
195212
|
-
minute: "2-digit",
|
|
195213
|
-
second: "2-digit",
|
|
195214
|
-
hour12: false
|
|
195215
|
-
});
|
|
195216
|
-
var colorByType = {
|
|
195217
|
-
error: source_default.red,
|
|
195218
|
-
warn: source_default.yellow,
|
|
195219
|
-
log: (text) => text
|
|
195220
|
-
};
|
|
195221
|
-
function createDevLogger(isPrefixed = true) {
|
|
195222
|
-
const print = (type, msg) => {
|
|
195223
|
-
const colorize = colorByType[type];
|
|
195224
|
-
switch (type) {
|
|
195225
|
-
case "error":
|
|
195226
|
-
console.error(colorize(msg));
|
|
195227
|
-
break;
|
|
195228
|
-
case "warn":
|
|
195229
|
-
console.warn(colorize(msg));
|
|
195230
|
-
break;
|
|
195231
|
-
default:
|
|
195232
|
-
console.log(msg);
|
|
195233
|
-
}
|
|
195234
|
-
};
|
|
195235
|
-
const prefixedLog = (type, msg) => {
|
|
195236
|
-
const timestamp = dateTimeFormat.format(new Date);
|
|
195237
|
-
const colorize = colorByType[type];
|
|
195238
|
-
console.log(`${source_default.gray(timestamp)} ${colorize(msg)}`);
|
|
195239
|
-
};
|
|
195240
|
-
return isPrefixed ? {
|
|
195241
|
-
log: (msg) => prefixedLog("log", msg),
|
|
195242
|
-
error: (msg, err) => {
|
|
195243
|
-
prefixedLog("error", msg);
|
|
195244
|
-
if (err) {
|
|
195245
|
-
prefixedLog("error", String(err));
|
|
195246
|
-
}
|
|
195247
|
-
},
|
|
195248
|
-
warn: (msg) => prefixedLog("warn", msg)
|
|
195249
|
-
} : {
|
|
195250
|
-
log: (msg) => print("log", msg),
|
|
195251
|
-
error: (msg, err) => {
|
|
195252
|
-
print("error", msg);
|
|
195253
|
-
if (err) {
|
|
195254
|
-
print("error", String(err));
|
|
195255
|
-
}
|
|
195256
|
-
},
|
|
195257
|
-
warn: (msg) => print("warn", msg)
|
|
195258
|
-
};
|
|
195259
|
-
}
|
|
195260
|
-
|
|
195261
195235
|
// src/cli/dev/dev-server/main.ts
|
|
195236
|
+
import { dirname as dirname12, join as join16 } from "node:path";
|
|
195262
195237
|
var import_cors = __toESM(require_lib4(), 1);
|
|
195263
195238
|
var import_express2 = __toESM(require_express(), 1);
|
|
195264
|
-
import { dirname as dirname12, join as join16 } from "node:path";
|
|
195265
195239
|
|
|
195266
195240
|
// node_modules/get-port/index.js
|
|
195267
195241
|
import net from "node:net";
|
|
@@ -195378,10 +195352,33 @@ async function getPorts(options8) {
|
|
|
195378
195352
|
}
|
|
195379
195353
|
|
|
195380
195354
|
// src/cli/dev/dev-server/main.ts
|
|
195381
|
-
var
|
|
195355
|
+
var import_http_proxy_middleware2 = __toESM(require_dist2(), 1);
|
|
195356
|
+
|
|
195357
|
+
// src/cli/dev/createDevLogger.ts
|
|
195358
|
+
var colorByType = {
|
|
195359
|
+
error: theme.styles.error,
|
|
195360
|
+
warn: theme.styles.warn,
|
|
195361
|
+
log: (text) => text
|
|
195362
|
+
};
|
|
195363
|
+
function createDevLogger() {
|
|
195364
|
+
const print = (type, msg) => {
|
|
195365
|
+
const colorize = colorByType[type];
|
|
195366
|
+
console[type](colorize(msg));
|
|
195367
|
+
};
|
|
195368
|
+
return {
|
|
195369
|
+
log: (msg) => print("log", msg),
|
|
195370
|
+
error: (msg, err) => {
|
|
195371
|
+
print("error", msg);
|
|
195372
|
+
if (err) {
|
|
195373
|
+
print("error", String(err));
|
|
195374
|
+
}
|
|
195375
|
+
},
|
|
195376
|
+
warn: (msg) => print("warn", msg)
|
|
195377
|
+
};
|
|
195378
|
+
}
|
|
195382
195379
|
|
|
195383
195380
|
// src/cli/dev/dev-server/function-manager.ts
|
|
195384
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
195381
|
+
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
195385
195382
|
import { dirname as dirname11, join as join15 } from "node:path";
|
|
195386
195383
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
195387
195384
|
var __dirname5 = dirname11(fileURLToPath7(import.meta.url));
|
|
@@ -195391,26 +195388,49 @@ var READY_TIMEOUT = 30000;
|
|
|
195391
195388
|
class FunctionManager {
|
|
195392
195389
|
functions;
|
|
195393
195390
|
running = new Map;
|
|
195391
|
+
starting = new Map;
|
|
195394
195392
|
logger;
|
|
195395
195393
|
constructor(functions, logger) {
|
|
195396
195394
|
this.functions = new Map(functions.map((f7) => [f7.name, f7]));
|
|
195397
195395
|
this.logger = logger;
|
|
195398
195396
|
}
|
|
195399
|
-
|
|
195400
|
-
return this.functions.
|
|
195397
|
+
getFunctionNames() {
|
|
195398
|
+
return Array.from(this.functions.keys());
|
|
195399
|
+
}
|
|
195400
|
+
verifyDenoIsInstalled() {
|
|
195401
|
+
if (this.functions.size > 0) {
|
|
195402
|
+
const result = spawnSync2("deno", ["--version"]);
|
|
195403
|
+
if (result.error) {
|
|
195404
|
+
throw new DependencyNotFoundError("Deno is required to run functions", {
|
|
195405
|
+
hints: [{ message: "Install Deno from https://deno.com/download" }]
|
|
195406
|
+
});
|
|
195407
|
+
}
|
|
195408
|
+
}
|
|
195401
195409
|
}
|
|
195402
195410
|
async ensureRunning(name2) {
|
|
195411
|
+
const backendFunction = this.functions.get(name2);
|
|
195412
|
+
if (!backendFunction) {
|
|
195413
|
+
throw new InvalidInputError(`Function "${name2}" not found`, {
|
|
195414
|
+
hints: [{ message: "Check available functions in your project" }]
|
|
195415
|
+
});
|
|
195416
|
+
}
|
|
195403
195417
|
const existing = this.running.get(name2);
|
|
195404
195418
|
if (existing?.ready) {
|
|
195405
195419
|
return existing.port;
|
|
195406
195420
|
}
|
|
195407
|
-
const
|
|
195408
|
-
if (
|
|
195409
|
-
|
|
195421
|
+
const pending = this.starting.get(name2);
|
|
195422
|
+
if (pending) {
|
|
195423
|
+
return pending;
|
|
195410
195424
|
}
|
|
195411
|
-
|
|
195412
|
-
|
|
195425
|
+
const promise2 = this.startFunction(name2, backendFunction);
|
|
195426
|
+
this.starting.set(name2, promise2);
|
|
195427
|
+
try {
|
|
195428
|
+
return await promise2;
|
|
195429
|
+
} finally {
|
|
195430
|
+
this.starting.delete(name2);
|
|
195413
195431
|
}
|
|
195432
|
+
}
|
|
195433
|
+
async startFunction(name2, backendFunction) {
|
|
195414
195434
|
const port = await this.allocatePort();
|
|
195415
195435
|
const process21 = this.spawnFunction(backendFunction, port);
|
|
195416
195436
|
const runningFunc = {
|
|
@@ -195422,16 +195442,13 @@ class FunctionManager {
|
|
|
195422
195442
|
this.setupProcessHandlers(name2, process21);
|
|
195423
195443
|
return this.waitForReady(name2, runningFunc);
|
|
195424
195444
|
}
|
|
195425
|
-
getPort(name2) {
|
|
195426
|
-
const running = this.running.get(name2);
|
|
195427
|
-
return running?.ready ? running.port : undefined;
|
|
195428
|
-
}
|
|
195429
195445
|
stopAll() {
|
|
195430
195446
|
for (const [name2, { process: process21 }] of this.running) {
|
|
195431
195447
|
this.logger.log(`[dev-server] Stopping function: ${name2}`);
|
|
195432
195448
|
process21.kill();
|
|
195433
195449
|
}
|
|
195434
195450
|
this.running.clear();
|
|
195451
|
+
this.starting.clear();
|
|
195435
195452
|
}
|
|
195436
195453
|
stop(name2) {
|
|
195437
195454
|
const running = this.running.get(name2);
|
|
@@ -195484,8 +195501,21 @@ class FunctionManager {
|
|
|
195484
195501
|
}
|
|
195485
195502
|
waitForReady(name2, runningFunc) {
|
|
195486
195503
|
return new Promise((resolve5, reject) => {
|
|
195504
|
+
runningFunc.process.on("exit", (code2) => {
|
|
195505
|
+
if (!runningFunc.ready) {
|
|
195506
|
+
clearTimeout(timeout3);
|
|
195507
|
+
reject(new InternalError(`Function "${name2}" exited with code ${code2}`, {
|
|
195508
|
+
hints: [{ message: "Check the function code for errors" }]
|
|
195509
|
+
}));
|
|
195510
|
+
}
|
|
195511
|
+
});
|
|
195487
195512
|
const timeout3 = setTimeout(() => {
|
|
195488
|
-
|
|
195513
|
+
runningFunc.process.kill();
|
|
195514
|
+
reject(new InternalError(`Function "${name2}" failed to start within ${READY_TIMEOUT / 1000}s timeout`, {
|
|
195515
|
+
hints: [
|
|
195516
|
+
{ message: "Check the function code for startup errors" }
|
|
195517
|
+
]
|
|
195518
|
+
}));
|
|
195489
195519
|
}, READY_TIMEOUT);
|
|
195490
195520
|
const onData = (data) => {
|
|
195491
195521
|
const output = data.toString();
|
|
@@ -195497,103 +195527,65 @@ class FunctionManager {
|
|
|
195497
195527
|
}
|
|
195498
195528
|
};
|
|
195499
195529
|
runningFunc.process.stdout?.on("data", onData);
|
|
195500
|
-
runningFunc.process.on("exit", (code2) => {
|
|
195501
|
-
if (!runningFunc.ready) {
|
|
195502
|
-
clearTimeout(timeout3);
|
|
195503
|
-
reject(new Error(`Function "${name2}" exited with code ${code2}`));
|
|
195504
|
-
}
|
|
195505
|
-
});
|
|
195506
195530
|
});
|
|
195507
195531
|
}
|
|
195508
195532
|
}
|
|
195509
195533
|
|
|
195510
195534
|
// src/cli/dev/dev-server/routes/functions.ts
|
|
195511
195535
|
var import_express = __toESM(require_express(), 1);
|
|
195512
|
-
|
|
195513
|
-
|
|
195536
|
+
var import_http_proxy_middleware = __toESM(require_dist2(), 1);
|
|
195537
|
+
import { ServerResponse } from "node:http";
|
|
195538
|
+
function createFunctionRouter(manager, logger) {
|
|
195514
195539
|
const router = import_express.Router({ mergeParams: true });
|
|
195515
|
-
|
|
195540
|
+
const portsByRequest = new WeakMap;
|
|
195541
|
+
const proxy = import_http_proxy_middleware.createProxyMiddleware({
|
|
195542
|
+
router: (req) => `http://localhost:${portsByRequest.get(req)}`,
|
|
195543
|
+
changeOrigin: true,
|
|
195544
|
+
on: {
|
|
195545
|
+
proxyReq: (proxyReq, req) => {
|
|
195546
|
+
const xAppId = req.headers["x-app-id"];
|
|
195547
|
+
if (xAppId) {
|
|
195548
|
+
proxyReq.setHeader("Base44-App-Id", xAppId);
|
|
195549
|
+
}
|
|
195550
|
+
proxyReq.setHeader("Base44-Api-Url", `${req.protocol}://${req.headers.host}`);
|
|
195551
|
+
},
|
|
195552
|
+
error: (err, _req, res) => {
|
|
195553
|
+
logger.error("Function proxy error:", err);
|
|
195554
|
+
if (res instanceof ServerResponse && !res.headersSent) {
|
|
195555
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
195556
|
+
res.end(JSON.stringify({
|
|
195557
|
+
error: "Failed to proxy request to function",
|
|
195558
|
+
details: err.message
|
|
195559
|
+
}));
|
|
195560
|
+
}
|
|
195561
|
+
}
|
|
195562
|
+
}
|
|
195563
|
+
});
|
|
195564
|
+
router.all("/:functionName", async (req, res, next) => {
|
|
195516
195565
|
const { functionName } = req.params;
|
|
195517
195566
|
try {
|
|
195518
|
-
const func = manager.getFunction(functionName);
|
|
195519
|
-
if (!func) {
|
|
195520
|
-
res.status(404).json({
|
|
195521
|
-
error: `Function "${functionName}" not found`
|
|
195522
|
-
});
|
|
195523
|
-
return;
|
|
195524
|
-
}
|
|
195525
195567
|
const port = await manager.ensureRunning(functionName);
|
|
195526
|
-
|
|
195568
|
+
portsByRequest.set(req, port);
|
|
195569
|
+
next();
|
|
195527
195570
|
} catch (error48) {
|
|
195528
|
-
logger.error(
|
|
195571
|
+
logger.error("Function error:", error48);
|
|
195529
195572
|
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
195530
195573
|
res.status(500).json({ error: message });
|
|
195531
195574
|
}
|
|
195532
|
-
});
|
|
195575
|
+
}, proxy);
|
|
195533
195576
|
return router;
|
|
195534
195577
|
}
|
|
195535
|
-
function proxyRequest(req, res, port, logger) {
|
|
195536
|
-
return new Promise((resolve5, reject) => {
|
|
195537
|
-
const headers = {
|
|
195538
|
-
...req.headers
|
|
195539
|
-
};
|
|
195540
|
-
delete headers.host;
|
|
195541
|
-
if (headers["x-app-id"]) {
|
|
195542
|
-
headers["Base44-App-Id"] = headers["x-app-id"];
|
|
195543
|
-
}
|
|
195544
|
-
headers["Base44-Api-Url"] = `${req.protocol}://${req.get("host")}`;
|
|
195545
|
-
const options8 = {
|
|
195546
|
-
hostname: "localhost",
|
|
195547
|
-
port,
|
|
195548
|
-
path: req.url,
|
|
195549
|
-
method: req.method,
|
|
195550
|
-
headers
|
|
195551
|
-
};
|
|
195552
|
-
const proxyReq = httpRequest(options8, (proxyRes) => {
|
|
195553
|
-
res.status(proxyRes.statusCode || 200);
|
|
195554
|
-
for (const [key2, value] of Object.entries(proxyRes.headers)) {
|
|
195555
|
-
if (value !== undefined) {
|
|
195556
|
-
res.setHeader(key2, value);
|
|
195557
|
-
}
|
|
195558
|
-
}
|
|
195559
|
-
proxyRes.pipe(res);
|
|
195560
|
-
proxyRes.on("end", () => {
|
|
195561
|
-
resolve5();
|
|
195562
|
-
});
|
|
195563
|
-
proxyRes.on("error", (error48) => {
|
|
195564
|
-
reject(error48);
|
|
195565
|
-
});
|
|
195566
|
-
});
|
|
195567
|
-
proxyReq.on("error", (error48) => {
|
|
195568
|
-
logger.error(`Function proxy error:`, error48);
|
|
195569
|
-
if (!res.headersSent) {
|
|
195570
|
-
res.status(502).json({
|
|
195571
|
-
error: "Failed to proxy request to function",
|
|
195572
|
-
details: error48.message
|
|
195573
|
-
});
|
|
195574
|
-
}
|
|
195575
|
-
resolve5();
|
|
195576
|
-
});
|
|
195577
|
-
if (req.body && Object.keys(req.body).length > 0) {
|
|
195578
|
-
const bodyString = JSON.stringify(req.body);
|
|
195579
|
-
proxyReq.setHeader("Content-Type", "application/json");
|
|
195580
|
-
proxyReq.setHeader("Content-Length", Buffer.byteLength(bodyString));
|
|
195581
|
-
proxyReq.write(bodyString);
|
|
195582
|
-
}
|
|
195583
|
-
proxyReq.end();
|
|
195584
|
-
});
|
|
195585
|
-
}
|
|
195586
195578
|
|
|
195587
195579
|
// src/cli/dev/dev-server/main.ts
|
|
195588
195580
|
var DEFAULT_PORT = 4400;
|
|
195589
195581
|
var BASE44_APP_URL = "https://base44.app";
|
|
195590
195582
|
async function createDevServer(options8) {
|
|
195591
|
-
const {
|
|
195583
|
+
const { port: userPort } = options8;
|
|
195592
195584
|
const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
|
|
195593
195585
|
const { project: project2 } = await readProjectConfig();
|
|
195594
195586
|
const configDir = dirname12(project2.configPath);
|
|
195595
195587
|
const app = import_express2.default();
|
|
195596
|
-
const remoteProxy =
|
|
195588
|
+
const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
195597
195589
|
target: BASE44_APP_URL,
|
|
195598
195590
|
changeOrigin: true
|
|
195599
195591
|
});
|
|
@@ -195609,17 +195601,18 @@ async function createDevServer(options8) {
|
|
|
195609
195601
|
}
|
|
195610
195602
|
next();
|
|
195611
195603
|
});
|
|
195612
|
-
const
|
|
195613
|
-
|
|
195614
|
-
|
|
195615
|
-
|
|
195616
|
-
|
|
195617
|
-
|
|
195604
|
+
const functions = await functionResource.readAll(join16(configDir, project2.functionsDir));
|
|
195605
|
+
const devLogger = createDevLogger();
|
|
195606
|
+
const functionManager = new FunctionManager(functions, devLogger);
|
|
195607
|
+
functionManager.verifyDenoIsInstalled();
|
|
195608
|
+
if (functionManager.getFunctionNames().length > 0) {
|
|
195609
|
+
M2.info(`Loaded functions: ${functionManager.getFunctionNames().join(", ")}`);
|
|
195610
|
+
}
|
|
195611
|
+
const functionRoutes = createFunctionRouter(functionManager, devLogger);
|
|
195618
195612
|
app.use("/api/apps/:appId/functions", functionRoutes);
|
|
195619
195613
|
app.use((req, res, next) => {
|
|
195620
195614
|
return remoteProxy(req, res, next);
|
|
195621
195615
|
});
|
|
195622
|
-
app.use(import_express2.default.json());
|
|
195623
195616
|
return new Promise((resolve5, reject) => {
|
|
195624
195617
|
const server = app.listen(port, "127.0.0.1", (err) => {
|
|
195625
195618
|
if (err) {
|
|
@@ -195629,6 +195622,12 @@ async function createDevServer(options8) {
|
|
|
195629
195622
|
reject(err);
|
|
195630
195623
|
}
|
|
195631
195624
|
} else {
|
|
195625
|
+
const shutdown = () => {
|
|
195626
|
+
functionManager.stopAll();
|
|
195627
|
+
server.close();
|
|
195628
|
+
};
|
|
195629
|
+
process.on("SIGINT", shutdown);
|
|
195630
|
+
process.on("SIGTERM", shutdown);
|
|
195632
195631
|
resolve5({
|
|
195633
195632
|
port,
|
|
195634
195633
|
server
|
|
@@ -195642,8 +195641,7 @@ async function createDevServer(options8) {
|
|
|
195642
195641
|
async function devAction(options8) {
|
|
195643
195642
|
const port = options8.port ? Number(options8.port) : undefined;
|
|
195644
195643
|
const { port: resolvedPort } = await createDevServer({
|
|
195645
|
-
port
|
|
195646
|
-
logger: createDevLogger()
|
|
195644
|
+
port
|
|
195647
195645
|
});
|
|
195648
195646
|
return {
|
|
195649
195647
|
outroMessage: `Dev server is available at ${theme.colors.links(`http://localhost:${resolvedPort}`)}`
|
|
@@ -195742,7 +195740,7 @@ async function eject(options8) {
|
|
|
195742
195740
|
}
|
|
195743
195741
|
function getEjectCommand(context) {
|
|
195744
195742
|
return new Command("eject").description("Download the code for an existing Base44 project").option("-p, --path <path>", "Path where to write the project").option("--project-id <id>", "Project ID to eject (skips interactive selection)").option("-y, --yes", "Skip confirmation prompts").action(async (options8) => {
|
|
195745
|
-
await runCommand(() => eject(options8), { requireAuth: true, requireAppConfig: false }, context);
|
|
195743
|
+
await runCommand(() => eject({ ...options8, isNonInteractive: context.isNonInteractive }), { requireAuth: true, requireAppConfig: false }, context);
|
|
195746
195744
|
});
|
|
195747
195745
|
}
|
|
195748
195746
|
|
|
@@ -200009,7 +200007,8 @@ function addCommandInfoToErrorReporter(program2, errorReporter) {
|
|
|
200009
200007
|
async function runCLI() {
|
|
200010
200008
|
const errorReporter = new ErrorReporter;
|
|
200011
200009
|
errorReporter.registerProcessErrorHandlers();
|
|
200012
|
-
const
|
|
200010
|
+
const isNonInteractive = !process.stdin.isTTY || !process.stdout.isTTY;
|
|
200011
|
+
const context = { errorReporter, isNonInteractive };
|
|
200013
200012
|
const program2 = createProgram(context);
|
|
200014
200013
|
try {
|
|
200015
200014
|
const userInfo = await readAuth();
|
|
@@ -200034,4 +200033,4 @@ export {
|
|
|
200034
200033
|
CLIExitError
|
|
200035
200034
|
};
|
|
200036
200035
|
|
|
200037
|
-
//# debugId=
|
|
200036
|
+
//# debugId=B4C79353BCDBC07064756E2164756E21
|