base44 0.0.45 → 0.0.47
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.
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno Exec Wrapper
|
|
3
|
+
*
|
|
4
|
+
* This script is executed by Deno to run user scripts with the Base44 SDK
|
|
5
|
+
* pre-authenticated and available as a global `base44` variable.
|
|
6
|
+
*
|
|
7
|
+
* Environment variables:
|
|
8
|
+
* - SCRIPT_PATH: Absolute path (or file:// URL) to the user's script
|
|
9
|
+
* - BASE44_APP_ID: App identifier from .app.jsonc
|
|
10
|
+
* - BASE44_ACCESS_TOKEN: User's access token
|
|
11
|
+
* - BASE44_APP_BASE_URL: App's published URL / subdomain (used for function calls)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export {};
|
|
15
|
+
|
|
16
|
+
const scriptPath = Deno.env.get("SCRIPT_PATH");
|
|
17
|
+
const appId = Deno.env.get("BASE44_APP_ID");
|
|
18
|
+
const accessToken = Deno.env.get("BASE44_ACCESS_TOKEN");
|
|
19
|
+
const appBaseUrl = Deno.env.get("BASE44_APP_BASE_URL");
|
|
20
|
+
|
|
21
|
+
if (!scriptPath) {
|
|
22
|
+
console.error("SCRIPT_PATH environment variable is required");
|
|
23
|
+
Deno.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!appId || !accessToken) {
|
|
27
|
+
console.error("BASE44_APP_ID and BASE44_ACCESS_TOKEN are required");
|
|
28
|
+
Deno.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!appBaseUrl) {
|
|
32
|
+
console.error("BASE44_APP_BASE_URL environment variable is required");
|
|
33
|
+
Deno.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
import { createClient } from "npm:@base44/sdk";
|
|
37
|
+
|
|
38
|
+
const base44 = createClient({
|
|
39
|
+
appId,
|
|
40
|
+
token: accessToken,
|
|
41
|
+
serverUrl: appBaseUrl,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
(globalThis as any).base44 = base44;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
await import(scriptPath);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("Failed to execute script:", error);
|
|
50
|
+
Deno.exit(1);
|
|
51
|
+
} finally {
|
|
52
|
+
// Clean up the SDK client (clears analytics heartbeat interval,
|
|
53
|
+
// disconnects socket) so the process can exit naturally.
|
|
54
|
+
base44.cleanup();
|
|
55
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno Function Wrapper
|
|
3
|
+
*
|
|
4
|
+
* This script is executed by Deno to run user functions.
|
|
5
|
+
* It patches Deno.serve to inject a dynamic port before importing the user's function.
|
|
6
|
+
*
|
|
7
|
+
* Environment variables:
|
|
8
|
+
* - FUNCTION_PATH: Absolute path to the user's function entry file
|
|
9
|
+
* - FUNCTION_PORT: Port number for the function to listen on
|
|
10
|
+
* - FUNCTION_NAME: Name of the function (for logging)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Make this file a module for top-level await support
|
|
14
|
+
export {};
|
|
15
|
+
|
|
16
|
+
const functionPath = Deno.env.get("FUNCTION_PATH");
|
|
17
|
+
const port = parseInt(Deno.env.get("FUNCTION_PORT") || "8000", 10);
|
|
18
|
+
const functionName = Deno.env.get("FUNCTION_NAME") || "unknown";
|
|
19
|
+
|
|
20
|
+
if (!functionPath) {
|
|
21
|
+
console.error("[wrapper] FUNCTION_PATH environment variable is required");
|
|
22
|
+
Deno.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Store the original Deno.serve
|
|
26
|
+
const originalServe = Deno.serve.bind(Deno);
|
|
27
|
+
|
|
28
|
+
// Patch Deno.serve to inject our port and add onListen callback
|
|
29
|
+
// @ts-expect-error - We're intentionally overriding Deno.serve
|
|
30
|
+
Deno.serve = (
|
|
31
|
+
optionsOrHandler:
|
|
32
|
+
| Deno.ServeOptions
|
|
33
|
+
| Deno.ServeHandler
|
|
34
|
+
| (Deno.ServeOptions & { handler: Deno.ServeHandler }),
|
|
35
|
+
maybeHandler?: Deno.ServeHandler,
|
|
36
|
+
): Deno.HttpServer<Deno.NetAddr> => {
|
|
37
|
+
const onListen = () => {
|
|
38
|
+
// This message is used by FunctionManager to detect when the function is ready
|
|
39
|
+
console.log(`[${functionName}] Listening on http://localhost:${port}`);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Handle the different Deno.serve signatures:
|
|
43
|
+
// 1. Deno.serve(handler)
|
|
44
|
+
// 2. Deno.serve(options, handler)
|
|
45
|
+
// 3. Deno.serve({ ...options, handler })
|
|
46
|
+
if (typeof optionsOrHandler === "function") {
|
|
47
|
+
// Signature: Deno.serve(handler)
|
|
48
|
+
return originalServe({ port, onListen }, optionsOrHandler);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (maybeHandler) {
|
|
52
|
+
// Signature: Deno.serve(options, handler)
|
|
53
|
+
return originalServe({ ...optionsOrHandler, port, onListen }, maybeHandler);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Signature: Deno.serve({ ...options, handler })
|
|
57
|
+
const options = optionsOrHandler as Deno.ServeOptions & {
|
|
58
|
+
handler: Deno.ServeHandler;
|
|
59
|
+
};
|
|
60
|
+
return originalServe({ ...options, port, onListen });
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
console.log(`[${functionName}] Starting function from ${functionPath}`);
|
|
64
|
+
|
|
65
|
+
// Dynamically import the user's function
|
|
66
|
+
// The function will call Deno.serve which is now patched to use our port
|
|
67
|
+
try {
|
|
68
|
+
await import(functionPath);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(`[${functionName}] Failed to load function:`, error);
|
|
71
|
+
Deno.exit(1);
|
|
72
|
+
}
|