@doany-ai/sdk 0.1.0
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 +22 -0
- package/README.md +60 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +395 -0
- package/dist/client.types.d.ts +149 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +5 -0
- package/dist/modules/agents.d.ts +2 -0
- package/dist/modules/agents.js +89 -0
- package/dist/modules/agents.types.d.ts +397 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/ai-gateway.d.ts +2 -0
- package/dist/modules/ai-gateway.js +13 -0
- package/dist/modules/ai-gateway.types.d.ts +88 -0
- package/dist/modules/ai-gateway.types.js +1 -0
- package/dist/modules/analytics.d.ts +20 -0
- package/dist/modules/analytics.js +284 -0
- package/dist/modules/analytics.types.d.ts +122 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +11 -0
- package/dist/modules/app-logs.js +27 -0
- package/dist/modules/app-logs.types.d.ts +46 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +142 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +13 -0
- package/dist/modules/auth.js +240 -0
- package/dist/modules/auth.types.d.ts +517 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +20 -0
- package/dist/modules/connectors.js +98 -0
- package/dist/modules/connectors.types.d.ts +376 -0
- package/dist/modules/connectors.types.js +1 -0
- package/dist/modules/custom-integrations.d.ts +11 -0
- package/dist/modules/custom-integrations.js +32 -0
- package/dist/modules/custom-integrations.types.d.ts +89 -0
- package/dist/modules/custom-integrations.types.js +1 -0
- package/dist/modules/entities.d.ts +20 -0
- package/dist/modules/entities.js +163 -0
- package/dist/modules/entities.types.d.ts +702 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +12 -0
- package/dist/modules/functions.js +79 -0
- package/dist/modules/functions.types.d.ts +150 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +11 -0
- package/dist/modules/integrations.js +77 -0
- package/dist/modules/integrations.types.d.ts +418 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +11 -0
- package/dist/modules/sso.js +22 -0
- package/dist/modules/sso.types.d.ts +68 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +5 -0
- package/dist/modules/types.js +5 -0
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +1 -0
- package/dist/utils/auth-utils.d.ts +117 -0
- package/dist/utils/auth-utils.js +189 -0
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +100 -0
- package/dist/utils/axios-client.js +202 -0
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +4 -0
- package/dist/utils/common.js +11 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +170 -0
- package/package.json +54 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the entities module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param config - Configuration object containing axios, appId, and getSocket
|
|
5
|
+
* @returns Entities module with dynamic entity access
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function createEntitiesModule(config) {
|
|
9
|
+
const { axios, appId, getSocket } = config;
|
|
10
|
+
// Using Proxy to dynamically handle entity names
|
|
11
|
+
return new Proxy({}, {
|
|
12
|
+
get(target, entityName) {
|
|
13
|
+
// Don't create handlers for internal properties
|
|
14
|
+
if (typeof entityName !== "string" ||
|
|
15
|
+
entityName === "then" ||
|
|
16
|
+
entityName.startsWith("_")) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
// Create entity handler
|
|
20
|
+
return createEntityHandler(axios, appId, entityName, getSocket);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses the realtime message data and extracts event information.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function parseRealtimeMessage(dataStr) {
|
|
29
|
+
var _a;
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(dataStr);
|
|
32
|
+
return {
|
|
33
|
+
type: parsed.type,
|
|
34
|
+
data: parsed.data,
|
|
35
|
+
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
36
|
+
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.warn("[Base44 SDK] Failed to parse realtime message:", error);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a handler for a specific entity.
|
|
46
|
+
*
|
|
47
|
+
* @param axios - Axios instance
|
|
48
|
+
* @param appId - Application ID
|
|
49
|
+
* @param entityName - Entity name
|
|
50
|
+
* @param getSocket - Function to get the socket instance
|
|
51
|
+
* @returns Entity handler with CRUD methods
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
55
|
+
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
56
|
+
return {
|
|
57
|
+
// List entities with optional pagination and sorting
|
|
58
|
+
async list(sort, limit, skip, fields) {
|
|
59
|
+
const params = {};
|
|
60
|
+
if (sort)
|
|
61
|
+
params.sort = sort;
|
|
62
|
+
if (limit)
|
|
63
|
+
params.limit = limit;
|
|
64
|
+
if (skip)
|
|
65
|
+
params.skip = skip;
|
|
66
|
+
if (fields)
|
|
67
|
+
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
68
|
+
return axios.get(baseURL, { params });
|
|
69
|
+
},
|
|
70
|
+
// Filter entities based on query
|
|
71
|
+
async filter(query, sort, limit, skip, fields) {
|
|
72
|
+
const params = {
|
|
73
|
+
q: JSON.stringify(query),
|
|
74
|
+
};
|
|
75
|
+
if (sort)
|
|
76
|
+
params.sort = sort;
|
|
77
|
+
if (limit)
|
|
78
|
+
params.limit = limit;
|
|
79
|
+
if (skip)
|
|
80
|
+
params.skip = skip;
|
|
81
|
+
if (fields)
|
|
82
|
+
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
83
|
+
return axios.get(baseURL, { params });
|
|
84
|
+
},
|
|
85
|
+
// Get entity by ID
|
|
86
|
+
async get(id) {
|
|
87
|
+
return axios.get(`${baseURL}/${id}`);
|
|
88
|
+
},
|
|
89
|
+
// Create new entity
|
|
90
|
+
async create(data) {
|
|
91
|
+
return axios.post(baseURL, data);
|
|
92
|
+
},
|
|
93
|
+
// Update entity by ID
|
|
94
|
+
async update(id, data) {
|
|
95
|
+
return axios.put(`${baseURL}/${id}`, data);
|
|
96
|
+
},
|
|
97
|
+
// Delete entity by ID
|
|
98
|
+
async delete(id) {
|
|
99
|
+
return axios.delete(`${baseURL}/${id}`);
|
|
100
|
+
},
|
|
101
|
+
// Delete multiple entities based on query
|
|
102
|
+
async deleteMany(query) {
|
|
103
|
+
return axios.delete(baseURL, { data: query });
|
|
104
|
+
},
|
|
105
|
+
// Create multiple entities in a single request
|
|
106
|
+
async bulkCreate(data) {
|
|
107
|
+
return axios.post(`${baseURL}/bulk`, data);
|
|
108
|
+
},
|
|
109
|
+
// Update multiple entities matching a query using a MongoDB update operator
|
|
110
|
+
async updateMany(query, data) {
|
|
111
|
+
return axios.patch(`${baseURL}/update-many`, { query, data });
|
|
112
|
+
},
|
|
113
|
+
// Update multiple entities by ID, each with its own update data
|
|
114
|
+
async bulkUpdate(data) {
|
|
115
|
+
return axios.put(`${baseURL}/bulk`, data);
|
|
116
|
+
},
|
|
117
|
+
// Import entities from a file
|
|
118
|
+
async importEntities(file) {
|
|
119
|
+
const formData = new FormData();
|
|
120
|
+
formData.append("file", file, file.name);
|
|
121
|
+
return axios.post(`${baseURL}/import`, formData, {
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "multipart/form-data",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
// Subscribe to realtime updates
|
|
128
|
+
subscribe(callback) {
|
|
129
|
+
const room = `entities:${appId}:${entityName}`;
|
|
130
|
+
// Get the socket and subscribe to the room
|
|
131
|
+
const socket = getSocket();
|
|
132
|
+
const unsubscribe = socket.subscribeToRoom(room, {
|
|
133
|
+
update_model: (msg) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const event = parseRealtimeMessage(msg.data);
|
|
136
|
+
if (!event) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Server signals oversize broadcasts with `_oversize: true` on
|
|
140
|
+
// `data`. The wire payload was slimmed to fit under the realtime
|
|
141
|
+
// transport cap, so big string fields arrive as empty strings (or
|
|
142
|
+
// the whole record collapses to a stub). Surface this to the
|
|
143
|
+
// developer console so they know to fetch the full record on
|
|
144
|
+
// demand (e.g. a follow-up entities.X.get(id) call) instead of
|
|
145
|
+
// rendering the slimmed payload directly. Skip on delete events
|
|
146
|
+
// — the record no longer exists.
|
|
147
|
+
if (event.type !== "delete" && ((_a = event.data) === null || _a === void 0 ? void 0 : _a._oversize)) {
|
|
148
|
+
console.error(`[Base44 SDK] Realtime broadcast for ${entityName}#${event.id} was oversize and got slimmed for transport. ` +
|
|
149
|
+
`Fields >10 KB are empty and the rest of the record may be a stub. ` +
|
|
150
|
+
`Call \`entities.${entityName}.get("${event.id}")\` to fetch the full record.`);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
callback(event);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error("[Base44 SDK] Subscription callback error:", error);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
return unsubscribe;
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|