@base44-preview/sdk 0.8.35-pr.212.f5f8839 → 0.8.35-pr.213.b3debb7
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/client.js +1 -21
- package/dist/client.types.d.ts +0 -10
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/package.json +1 -2
- package/dist/modules/realtime.d.ts +0 -10
- package/dist/modules/realtime.js +0 -62
- package/dist/modules/realtime.types.d.ts +0 -61
- package/dist/modules/realtime.types.js +0 -1
- package/dist/realtime-handler.d.ts +0 -34
- package/dist/realtime-handler.js +0 -28
package/dist/client.js
CHANGED
|
@@ -11,7 +11,6 @@ import { createAppLogsModule } from "./modules/app-logs.js";
|
|
|
11
11
|
import { createUsersModule } from "./modules/users.js";
|
|
12
12
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
13
13
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
14
|
-
import { createRealtimeModule } from "./modules/realtime.js";
|
|
15
14
|
/**
|
|
16
15
|
* Creates a Base44 client.
|
|
17
16
|
*
|
|
@@ -51,19 +50,9 @@ import { createRealtimeModule } from "./modules/realtime.js";
|
|
|
51
50
|
*/
|
|
52
51
|
export function createClient(config) {
|
|
53
52
|
var _a, _b;
|
|
54
|
-
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders,
|
|
53
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
55
54
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
56
55
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
57
|
-
// Derive the dispatcher WebSocket URL from serverUrl if not explicitly provided.
|
|
58
|
-
// Convert https:// → wss:// (or http:// → ws://) and strip trailing slash.
|
|
59
|
-
const resolvedDispatcherWsUrl = (() => {
|
|
60
|
-
if (dispatcherWsUrl)
|
|
61
|
-
return dispatcherWsUrl.replace(/\/$/, "");
|
|
62
|
-
return serverUrl
|
|
63
|
-
.replace(/\/$/, "")
|
|
64
|
-
.replace(/^https:\/\//, "wss://")
|
|
65
|
-
.replace(/^http:\/\//, "ws://");
|
|
66
|
-
})();
|
|
67
56
|
const socketConfig = {
|
|
68
57
|
serverUrl,
|
|
69
58
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -169,15 +158,6 @@ export function createClient(config) {
|
|
|
169
158
|
appId,
|
|
170
159
|
userAuthModule,
|
|
171
160
|
}),
|
|
172
|
-
realtime: createRealtimeModule({
|
|
173
|
-
appId,
|
|
174
|
-
dispatcherWsUrl: resolvedDispatcherWsUrl,
|
|
175
|
-
getToken: async (handlerName, instanceId) => {
|
|
176
|
-
// axiosClient interceptors unwrap response.data, so the result is the body directly
|
|
177
|
-
const data = await axiosClient.post(`/apps/${appId}/realtime-token`, { handler_name: handlerName, instance_id: instanceId });
|
|
178
|
-
return data.token;
|
|
179
|
-
},
|
|
180
|
-
}),
|
|
181
161
|
cleanup: () => {
|
|
182
162
|
userModules.analytics.cleanup();
|
|
183
163
|
if (socket) {
|
package/dist/client.types.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type { FunctionsModule } from "./modules/functions.types.js";
|
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
8
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
9
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
10
|
-
import type { RealtimeModule } from "./modules/realtime.types.js";
|
|
11
10
|
/**
|
|
12
11
|
* Options for creating a Base44 client.
|
|
13
12
|
*/
|
|
@@ -73,13 +72,6 @@ export interface CreateClientConfig {
|
|
|
73
72
|
* Additional client options.
|
|
74
73
|
*/
|
|
75
74
|
options?: CreateClientOptions;
|
|
76
|
-
/**
|
|
77
|
-
* Base WebSocket URL for the Cloudflare Durable Object dispatcher.
|
|
78
|
-
*
|
|
79
|
-
* Defaults to the `serverUrl` with `https://` replaced by `wss://` (or `http://` by `ws://`).
|
|
80
|
-
* Override when the dispatcher lives at a different host than the API.
|
|
81
|
-
*/
|
|
82
|
-
dispatcherWsUrl?: string;
|
|
83
75
|
}
|
|
84
76
|
/**
|
|
85
77
|
* The Base44 client instance.
|
|
@@ -93,8 +85,6 @@ export interface Base44Client {
|
|
|
93
85
|
analytics: AnalyticsModule;
|
|
94
86
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
95
87
|
appLogs: AppLogsModule;
|
|
96
|
-
/** {@link RealtimeModule | Realtime module} for subscribing to and sending messages via Cloudflare Durable Object-backed RealtimeHandlers. */
|
|
97
|
-
realtime: RealtimeModule;
|
|
98
88
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
99
89
|
auth: AuthModule;
|
|
100
90
|
/** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
|
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,7 @@ export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations,
|
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
|
-
export type { RealtimeModule, RealtimeHandlerClient, RealtimeHandlerNameRegistry, RealtimeHandlerRegistry, } from "./modules/realtime.types.js";
|
|
14
13
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
15
|
-
export { RealtimeHandler, type Conn } from "./realtime-handler.js";
|
|
16
14
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
17
15
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
18
16
|
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,3 @@ import { Base44Error } from "./utils/axios-client.js";
|
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export * from "./types.js";
|
|
6
|
-
export { RealtimeHandler } from "./realtime-handler.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.35-pr.
|
|
3
|
+
"version": "0.8.35-pr.213.b3debb7",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"axios": "^1.17.0",
|
|
30
|
-
"partysocket": "^0.0.23",
|
|
31
30
|
"socket.io-client": "^4.8.3",
|
|
32
31
|
"uuid": "^13.0.2"
|
|
33
32
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function createRealtimeModule(config: {
|
|
2
|
-
appId: string;
|
|
3
|
-
getToken(handlerName: string, instanceId: string): Promise<string>;
|
|
4
|
-
dispatcherWsUrl: string;
|
|
5
|
-
}): Record<string, RealtimeHandler>;
|
|
6
|
-
interface RealtimeHandler {
|
|
7
|
-
subscribe(instanceId: string, callback: (data: unknown) => void): () => void;
|
|
8
|
-
send(instanceId: string, data: unknown): void;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
package/dist/modules/realtime.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import PartySocket from "partysocket";
|
|
2
|
-
// Module-level map: "HandlerName:instanceId" → active socket
|
|
3
|
-
const activeSockets = new Map();
|
|
4
|
-
function socketKey(handlerName, instanceId) {
|
|
5
|
-
return `${handlerName}:${instanceId}`;
|
|
6
|
-
}
|
|
7
|
-
export function createRealtimeModule(config) {
|
|
8
|
-
return new Proxy({}, {
|
|
9
|
-
get(_, handlerName) {
|
|
10
|
-
return {
|
|
11
|
-
subscribe(instanceId, callback) {
|
|
12
|
-
var _a;
|
|
13
|
-
const key = socketKey(handlerName, instanceId);
|
|
14
|
-
// close existing if any
|
|
15
|
-
(_a = activeSockets.get(key)) === null || _a === void 0 ? void 0 : _a.close();
|
|
16
|
-
// startClosed: don't connect until we have a token
|
|
17
|
-
const ws = new PartySocket({
|
|
18
|
-
host: config.dispatcherWsUrl,
|
|
19
|
-
party: handlerName,
|
|
20
|
-
room: instanceId,
|
|
21
|
-
startClosed: true,
|
|
22
|
-
});
|
|
23
|
-
activeSockets.set(key, ws);
|
|
24
|
-
ws.addEventListener("message", (ev) => {
|
|
25
|
-
try {
|
|
26
|
-
callback(JSON.parse(ev.data));
|
|
27
|
-
}
|
|
28
|
-
catch (_a) {
|
|
29
|
-
// ignore malformed
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
// Fetch token then open; re-fetch on every close (token expires in 30s)
|
|
33
|
-
const connect = async () => {
|
|
34
|
-
if (activeSockets.get(key) !== ws)
|
|
35
|
-
return;
|
|
36
|
-
try {
|
|
37
|
-
const token = await config.getToken(handlerName, instanceId);
|
|
38
|
-
ws.updateProperties({ party: handlerName, room: instanceId, query: { token } });
|
|
39
|
-
ws.reconnect();
|
|
40
|
-
}
|
|
41
|
-
catch (_a) {
|
|
42
|
-
// retry on next close
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
ws.addEventListener("close", () => connect());
|
|
46
|
-
connect();
|
|
47
|
-
return () => {
|
|
48
|
-
activeSockets.delete(key);
|
|
49
|
-
ws.close();
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
send(instanceId, data) {
|
|
53
|
-
const key = socketKey(handlerName, instanceId);
|
|
54
|
-
const ws = activeSockets.get(key);
|
|
55
|
-
if (!ws)
|
|
56
|
-
throw new Error(`No active subscription for ${handlerName}:${instanceId}`);
|
|
57
|
-
ws.send(JSON.stringify(data));
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extend this interface to add typed `subscribe` callbacks and `send` payloads
|
|
3
|
-
* for your deployed RealtimeHandlers.
|
|
4
|
-
*
|
|
5
|
-
* This is separate from {@link RealtimeHandlerNameRegistry} (which is auto-generated
|
|
6
|
-
* by `base44 types generate`), so there are no conflicts.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* declare module "@base44/sdk" {
|
|
11
|
-
* interface RealtimeHandlerRegistry {
|
|
12
|
-
* ChatRoom: {
|
|
13
|
-
* inbound: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
|
|
14
|
-
* outbound: { text: string };
|
|
15
|
-
* };
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export interface RealtimeHandlerRegistry {
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Auto-populated by `base44 types generate` with the names of your deployed handlers.
|
|
24
|
-
* Do not edit this interface manually — use {@link RealtimeHandlerRegistry} for message types.
|
|
25
|
-
*/
|
|
26
|
-
export interface RealtimeHandlerNameRegistry {
|
|
27
|
-
}
|
|
28
|
-
type AllHandlerNames = keyof RealtimeHandlerRegistry | keyof RealtimeHandlerNameRegistry;
|
|
29
|
-
type InboundFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
|
|
30
|
-
inbound: infer I;
|
|
31
|
-
} ? I : unknown : unknown;
|
|
32
|
-
type OutboundFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
|
|
33
|
-
outbound: infer O;
|
|
34
|
-
} ? O : unknown : unknown;
|
|
35
|
-
/**
|
|
36
|
-
* Client for a single named RealtimeHandler.
|
|
37
|
-
* Typed automatically when the handler is registered in {@link RealtimeHandlerRegistry}.
|
|
38
|
-
*/
|
|
39
|
-
export interface RealtimeHandlerClient<N extends string = string> {
|
|
40
|
-
/** Open a WebSocket subscription. Returns a synchronous unsubscribe function. */
|
|
41
|
-
subscribe(instanceId: string, callback: (data: InboundFor<N>) => void): () => void;
|
|
42
|
-
/** Send a message over the open socket. Throws if not subscribed. */
|
|
43
|
-
send(instanceId: string, data: OutboundFor<N>): void;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The realtime module provides access to Cloudflare Durable Object-backed
|
|
47
|
-
* RealtimeHandlers deployed by the Base44 platform.
|
|
48
|
-
*
|
|
49
|
-
* Handler names are accessed as dynamic properties on this module:
|
|
50
|
-
* ```typescript
|
|
51
|
-
* const sub = await base44.realtime.MyHandler.subscribe("room-1", (msg) => {
|
|
52
|
-
* console.log(msg); // typed if MyHandler is in RealtimeHandlerRegistry
|
|
53
|
-
* });
|
|
54
|
-
* sub.send({ text: "hello" });
|
|
55
|
-
* sub.close();
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export type RealtimeModule = {
|
|
59
|
-
[K in AllHandlerNames]: K extends keyof RealtimeHandlerRegistry ? RealtimeHandlerClient<string & K> : RealtimeHandlerClient;
|
|
60
|
-
} & Record<string, RealtimeHandlerClient>;
|
|
61
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-only base class for Realtime Handlers.
|
|
3
|
-
*
|
|
4
|
-
* Import and extend this in your handler files:
|
|
5
|
-
* import { RealtimeHandler } from "@base44/sdk";
|
|
6
|
-
* export class MyHandler extends RealtimeHandler { ... }
|
|
7
|
-
*
|
|
8
|
-
* At deploy time the bundler replaces this import with the compiled
|
|
9
|
-
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
|
-
*/
|
|
11
|
-
export interface Conn {
|
|
12
|
-
userId: string;
|
|
13
|
-
appId: string;
|
|
14
|
-
instanceId: string;
|
|
15
|
-
send(data: unknown): void;
|
|
16
|
-
reject(code: number, reason: string): void;
|
|
17
|
-
}
|
|
18
|
-
export interface Storage {
|
|
19
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
20
|
-
put(key: string, value: unknown): Promise<void>;
|
|
21
|
-
delete(key: string): Promise<boolean>;
|
|
22
|
-
}
|
|
23
|
-
export declare abstract class RealtimeHandler<_State = unknown, Message = unknown> {
|
|
24
|
-
abstract handleConnect(conn: Conn): void | Promise<void>;
|
|
25
|
-
abstract handleMessage(conn: Conn, msg: Message): void | Promise<void>;
|
|
26
|
-
abstract handleClose(conn: Conn): void | Promise<void>;
|
|
27
|
-
abstract handleTick(): void | Promise<void>;
|
|
28
|
-
onStart(): void | Promise<void>;
|
|
29
|
-
protected broadcast(_data: unknown): void;
|
|
30
|
-
protected getConnections(): Conn[];
|
|
31
|
-
protected startLoop(_ms: number): Promise<void>;
|
|
32
|
-
protected stopLoop(): Promise<void>;
|
|
33
|
-
protected get storage(): Storage;
|
|
34
|
-
}
|
package/dist/realtime-handler.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-only base class for Realtime Handlers.
|
|
3
|
-
*
|
|
4
|
-
* Import and extend this in your handler files:
|
|
5
|
-
* import { RealtimeHandler } from "@base44/sdk";
|
|
6
|
-
* export class MyHandler extends RealtimeHandler { ... }
|
|
7
|
-
*
|
|
8
|
-
* At deploy time the bundler replaces this import with the compiled
|
|
9
|
-
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
|
-
*/
|
|
11
|
-
export class RealtimeHandler {
|
|
12
|
-
onStart() { }
|
|
13
|
-
broadcast(_data) {
|
|
14
|
-
throw new Error("RealtimeHandler.broadcast() is only available inside a deployed handler");
|
|
15
|
-
}
|
|
16
|
-
getConnections() {
|
|
17
|
-
throw new Error("RealtimeHandler.getConnections() is only available inside a deployed handler");
|
|
18
|
-
}
|
|
19
|
-
startLoop(_ms) {
|
|
20
|
-
throw new Error("RealtimeHandler.startLoop() is only available inside a deployed handler");
|
|
21
|
-
}
|
|
22
|
-
stopLoop() {
|
|
23
|
-
throw new Error("RealtimeHandler.stopLoop() is only available inside a deployed handler");
|
|
24
|
-
}
|
|
25
|
-
get storage() {
|
|
26
|
-
throw new Error("RealtimeHandler.storage is only available inside a deployed handler");
|
|
27
|
-
}
|
|
28
|
-
}
|