@base44-preview/sdk 0.8.28-pr.174.f540551 → 0.8.29-pr.176.30c5ce1
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
|
});
|
|
@@ -88,20 +93,49 @@ export function RoomsSocket({ config }) {
|
|
|
88
93
|
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
|
|
89
94
|
}
|
|
90
95
|
function getListeners(room) {
|
|
91
|
-
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = roomsToListeners[room]) !== null && _a !== void 0 ? _a : [];
|
|
98
|
+
}
|
|
99
|
+
function cancelPendingRoomLeave(room) {
|
|
100
|
+
const pendingLeave = pendingRoomLeaves[room];
|
|
101
|
+
if (!pendingLeave) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
clearTimeout(pendingLeave);
|
|
105
|
+
delete pendingRoomLeaves[room];
|
|
106
|
+
}
|
|
107
|
+
function scheduleRoomLeave(room) {
|
|
108
|
+
cancelPendingRoomLeave(room);
|
|
109
|
+
pendingRoomLeaves[room] = setTimeout(() => {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
delete pendingRoomLeaves[room];
|
|
112
|
+
if (((_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
leaveRoom(room);
|
|
116
|
+
delete roomsToListeners[room];
|
|
117
|
+
}, ROOM_LEAVE_GRACE_MS);
|
|
92
118
|
}
|
|
93
119
|
const subscribeToRoom = (room, handlers) => {
|
|
94
|
-
if (
|
|
120
|
+
if (roomsToListeners[room]) {
|
|
121
|
+
cancelPendingRoomLeave(room);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
95
124
|
joinRoom(room);
|
|
96
125
|
roomsToListeners[room] = [];
|
|
97
126
|
}
|
|
98
127
|
roomsToListeners[room].push(handlers);
|
|
128
|
+
let unsubscribed = false;
|
|
99
129
|
return () => {
|
|
100
130
|
var _a, _b;
|
|
131
|
+
if (unsubscribed) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
unsubscribed = true;
|
|
101
135
|
roomsToListeners[room] =
|
|
102
136
|
(_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
|
|
103
137
|
if (roomsToListeners[room].length === 0) {
|
|
104
|
-
|
|
138
|
+
scheduleRoomLeave(room);
|
|
105
139
|
}
|
|
106
140
|
};
|
|
107
141
|
};
|