@base44-preview/sdk 0.8.28-pr.174.f540551 → 0.8.29-pr.176.65ba61b
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.
|
@@ -126,22 +126,25 @@ export interface AuthModule {
|
|
|
126
126
|
*/
|
|
127
127
|
me(): Promise<User>;
|
|
128
128
|
/**
|
|
129
|
-
* Updates the current authenticated user's
|
|
129
|
+
* Updates the current authenticated user's information.
|
|
130
130
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
131
|
+
* You can update `role` and any [custom fields](/developers/backend/resources/entities/user-schema#custom-fields) defined in your
|
|
132
|
+
* User entity schema.
|
|
133
|
+
* The `role` value must be either `'user'` or `'admin'`.
|
|
134
|
+
* <Note>
|
|
135
|
+
* The following fields are read-only and can't be changed with this method:
|
|
136
|
+
* `id`, `email`, `full_name`, `created_date`, `updated_date`, and `created_by`.
|
|
137
|
+
* </Note>
|
|
135
138
|
*
|
|
136
|
-
* @param data - Object containing the
|
|
139
|
+
* @param data - Object containing the fields to update.
|
|
137
140
|
* @returns Promise resolving to the updated user data.
|
|
138
141
|
*
|
|
139
142
|
* @example
|
|
140
143
|
* ```typescript
|
|
141
|
-
* // Update custom fields defined in your User entity
|
|
144
|
+
* // Update role and custom fields defined in your User entity
|
|
142
145
|
* await base44.auth.updateMe({
|
|
146
|
+
* role: 'admin',
|
|
143
147
|
* bio: 'Software developer',
|
|
144
|
-
* phone: '+1234567890',
|
|
145
148
|
* preferences: { theme: 'dark' }
|
|
146
149
|
* });
|
|
147
150
|
* ```
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { io } from "socket.io-client";
|
|
2
2
|
import { getAccessToken } from "./auth-utils.js";
|
|
3
|
+
const ROOM_LEAVE_GRACE_MS = 250;
|
|
3
4
|
function initializeSocket(config, handlers) {
|
|
4
5
|
var _a;
|
|
5
6
|
const socket = io(config.serverUrl, {
|
|
@@ -33,13 +34,17 @@ function initializeSocket(config, handlers) {
|
|
|
33
34
|
export function RoomsSocket({ config }) {
|
|
34
35
|
let currentConfig = { ...config };
|
|
35
36
|
const roomsToListeners = {};
|
|
37
|
+
const pendingRoomLeaves = {};
|
|
36
38
|
const handlers = {
|
|
37
39
|
connect: async () => {
|
|
38
40
|
const promises = [];
|
|
39
41
|
Object.keys(roomsToListeners).forEach((room) => {
|
|
40
|
-
joinRoom(room);
|
|
41
42
|
const listeners = getListeners(room);
|
|
42
|
-
|
|
43
|
+
if (listeners.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
joinRoom(room);
|
|
47
|
+
listeners.forEach(({ connect }) => {
|
|
43
48
|
const promise = async () => connect === null || connect === void 0 ? void 0 : connect();
|
|
44
49
|
promises.push(promise());
|
|
45
50
|
});
|
|
@@ -64,6 +69,7 @@ export function RoomsSocket({ config }) {
|
|
|
64
69
|
disconnect();
|
|
65
70
|
}
|
|
66
71
|
function disconnect() {
|
|
72
|
+
clearPendingRoomLeaves();
|
|
67
73
|
if (socket) {
|
|
68
74
|
socket.disconnect();
|
|
69
75
|
}
|
|
@@ -88,20 +94,59 @@ export function RoomsSocket({ config }) {
|
|
|
88
94
|
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
|
|
89
95
|
}
|
|
90
96
|
function getListeners(room) {
|
|
91
|
-
|
|
97
|
+
var _a;
|
|
98
|
+
return (_a = roomsToListeners[room]) !== null && _a !== void 0 ? _a : [];
|
|
99
|
+
}
|
|
100
|
+
function cancelPendingRoomLeave(room) {
|
|
101
|
+
const pendingLeave = pendingRoomLeaves[room];
|
|
102
|
+
if (!pendingLeave) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
clearTimeout(pendingLeave);
|
|
106
|
+
delete pendingRoomLeaves[room];
|
|
107
|
+
}
|
|
108
|
+
function clearPendingRoomLeaves() {
|
|
109
|
+
Object.keys(pendingRoomLeaves).forEach((room) => {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
clearTimeout(pendingRoomLeaves[room]);
|
|
112
|
+
delete pendingRoomLeaves[room];
|
|
113
|
+
if (((_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0) {
|
|
114
|
+
delete roomsToListeners[room];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function scheduleRoomLeave(room) {
|
|
119
|
+
cancelPendingRoomLeave(room);
|
|
120
|
+
pendingRoomLeaves[room] = setTimeout(() => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
delete pendingRoomLeaves[room];
|
|
123
|
+
if (((_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
leaveRoom(room);
|
|
127
|
+
delete roomsToListeners[room];
|
|
128
|
+
}, ROOM_LEAVE_GRACE_MS);
|
|
92
129
|
}
|
|
93
130
|
const subscribeToRoom = (room, handlers) => {
|
|
94
|
-
if (
|
|
131
|
+
if (roomsToListeners[room]) {
|
|
132
|
+
cancelPendingRoomLeave(room);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
95
135
|
joinRoom(room);
|
|
96
136
|
roomsToListeners[room] = [];
|
|
97
137
|
}
|
|
98
138
|
roomsToListeners[room].push(handlers);
|
|
139
|
+
let unsubscribed = false;
|
|
99
140
|
return () => {
|
|
100
141
|
var _a, _b;
|
|
142
|
+
if (unsubscribed) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
unsubscribed = true;
|
|
101
146
|
roomsToListeners[room] =
|
|
102
147
|
(_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
|
|
103
148
|
if (roomsToListeners[room].length === 0) {
|
|
104
|
-
|
|
149
|
+
scheduleRoomLeave(room);
|
|
105
150
|
}
|
|
106
151
|
};
|
|
107
152
|
};
|