@gravity-rail/sdk 4.0.0 → 6.0.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/README.md +4 -2
- package/dist/account-CSJJbLIj.d.cts +459 -0
- package/dist/account-CSJJbLIj.d.ts +459 -0
- package/dist/{path-CUY-Iw70.d.ts → agent_standing_job-CqKpMoHO.d.cts} +1068 -140
- package/dist/{path-B3b3_El9.d.cts → agent_standing_job-yehTe972.d.ts} +1068 -140
- package/dist/{chat-interaction-DXgKjFqZ.d.cts → chat-interaction-BtUtVszg.d.ts} +13512 -9340
- package/dist/{chat-interaction-a7U-tHfQ.d.ts → chat-interaction-CAfwlYvv.d.cts} +13512 -9340
- package/dist/{chunk-WHRIIBJ4.js → chunk-L4XC6KDG.js} +1773 -475
- package/dist/chunk-L4XC6KDG.js.map +1 -0
- package/dist/{chunk-D5VNVTUQ.js → chunk-P2MSMMMJ.js} +120 -2
- package/dist/chunk-P2MSMMMJ.js.map +1 -0
- package/dist/{chunk-ZLF3N3ZD.js → chunk-P2X5TOYY.js} +31 -5
- package/dist/chunk-P2X5TOYY.js.map +1 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +3 -2
- package/dist/helpers.d.ts +3 -2
- package/dist/helpers.js +1 -1
- package/dist/index.cjs +1961 -917
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -249
- package/dist/index.d.ts +87 -249
- package/dist/index.js +171 -458
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +1928 -448
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +2428 -263
- package/dist/internal.d.ts +2428 -263
- package/dist/internal.js +146 -27
- package/dist/internal.js.map +1 -1
- package/dist/{member-import-VOLKR5dY.d.ts → member-import-C5nnoGvW.d.ts} +1 -1
- package/dist/{member-import-BHtOru8g.d.cts → member-import-DhaNVT7s.d.cts} +1 -1
- package/dist/realtime.cjs +250 -3
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +87 -4
- package/dist/realtime.d.ts +87 -4
- package/dist/realtime.js +245 -3
- package/dist/realtime.js.map +1 -1
- package/dist/schemas.cjs +154 -19
- package/dist/schemas.cjs.map +1 -1
- package/dist/schemas.d.cts +624 -72
- package/dist/schemas.d.ts +624 -72
- package/dist/schemas.js +72 -21
- package/dist/schemas.js.map +1 -1
- package/dist/{tasks-CgptqCsN.d.cts → tasks-A12E_RLa.d.cts} +2243 -1979
- package/dist/{tasks-CgptqCsN.d.ts → tasks-DrmyOlRh.d.ts} +2243 -1979
- package/dist/{types-BXaWYGHj.d.cts → types-Bv6GtLZ2.d.cts} +25 -2
- package/dist/{types-BXaWYGHj.d.ts → types-Bv6GtLZ2.d.ts} +25 -2
- package/package.json +4 -4
- package/dist/chunk-D5VNVTUQ.js.map +0 -1
- package/dist/chunk-WHRIIBJ4.js.map +0 -1
- package/dist/chunk-ZLF3N3ZD.js.map +0 -1
package/dist/realtime.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { R as RealtimeSessionBase, a as ChannelListener, U as Unsubscribe, b as RealtimeAuthSession, A as AccountRealtimeSession,
|
|
2
|
-
export {
|
|
1
|
+
import { R as RealtimeSessionBase, a as ChannelListener, U as Unsubscribe, O as OrgAuthRequirement, b as OrgSessionsUpdate, c as RealtimeAuthSession, A as AccountRealtimeSession, C as ChannelEvent, d as OperatorSessionState, e as OperatorCallPhase } from './types-Bv6GtLZ2.js';
|
|
2
|
+
export { f as ACCOUNT_ACTIVITY_CHANNEL, g as ACCOUNT_PRESENCE_CHANNEL, h as ACTIVITY_CHANNEL, i as ACTIVITY_MEMBER_CHANNEL, j as ActivityChannelName, k as ActivityInvalidationEvent, P as PRESENCE_CHANNEL, l as RealtimeLoginTokenProvider, m as isActiveCallPhase, n as isActivityInvalidation, p as parseOrgAuthRequirement, o as parseOrgAuthRequirements } from './types-Bv6GtLZ2.js';
|
|
3
|
+
import { AccountResponseAvatarIcon, AccountResponseAvatarColor } from './internal.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The realtime socket state machine, shared by both mounts.
|
|
@@ -32,6 +33,9 @@ declare abstract class RealtimeSocketClient<TSession extends RealtimeSessionBase
|
|
|
32
33
|
private readonly getSessionFn;
|
|
33
34
|
private readonly state;
|
|
34
35
|
private readonly connectionListeners;
|
|
36
|
+
private readonly orgAuthListeners;
|
|
37
|
+
private readonly orgSessionsListeners;
|
|
38
|
+
private readonly credentialRevokedListeners;
|
|
35
39
|
constructor(config?: TSession | (() => TSession | null));
|
|
36
40
|
/** The WebSocket URL this mount connects to. */
|
|
37
41
|
protected abstract buildUrl(session: TSession): string;
|
|
@@ -59,6 +63,34 @@ declare abstract class RealtimeSocketClient<TSession extends RealtimeSessionBase
|
|
|
59
63
|
private scheduleSubscriptionRetry;
|
|
60
64
|
setSession(session: TSession): void;
|
|
61
65
|
subscribe(channel: string, listener: ChannelListener): Unsubscribe;
|
|
66
|
+
/**
|
|
67
|
+
* Hear every workspace the server refused for want of an org session: a
|
|
68
|
+
* `subscribe_error` entry, an `error` frame with that code, a lapse notice,
|
|
69
|
+
* or the list in an `org_sessions_updated` reply.
|
|
70
|
+
*/
|
|
71
|
+
onOrgAuthRequired(listener: (items: OrgAuthRequirement[]) => void): () => void;
|
|
72
|
+
/** Hear the server's reply to an `org_sessions` frame. */
|
|
73
|
+
onOrgSessionsUpdated(listener: (update: OrgSessionsUpdate) => void): () => void;
|
|
74
|
+
/**
|
|
75
|
+
* Hear that the server ended this socket's login credential. The client
|
|
76
|
+
* does not reconnect afterwards; the consumer decides what the person sees
|
|
77
|
+
* (in the web app, the account check that leads to the login page).
|
|
78
|
+
*/
|
|
79
|
+
onCredentialRevoked(listener: () => void): () => void;
|
|
80
|
+
/** Whether the server ended this socket's login credential. */
|
|
81
|
+
isCredentialRevoked(): boolean;
|
|
82
|
+
private markCredentialRevoked;
|
|
83
|
+
private emitOrgAuthRequired;
|
|
84
|
+
/** Send a control frame (one that is not a channel message) on the open socket. */
|
|
85
|
+
sendFrame(frame: {
|
|
86
|
+
type: string;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Try again after the person completed org sign-in: reconnect a socket the
|
|
91
|
+
* server closed for it, or ask again for every channel it refused.
|
|
92
|
+
*/
|
|
93
|
+
retryAfterOrgAuth(): void;
|
|
62
94
|
send(channel: string, data: unknown): void;
|
|
63
95
|
onConnection(listener: (connected: boolean) => void): () => void;
|
|
64
96
|
isConnected(): boolean;
|
|
@@ -204,6 +236,55 @@ declare function subscribeAccountChannel(channel: string, listener: ChannelListe
|
|
|
204
236
|
declare function onAccountSocketConnection(listener: (connected: boolean) => void): () => void;
|
|
205
237
|
declare function isAccountSocketConnected(): boolean;
|
|
206
238
|
|
|
239
|
+
type EditorCollaborationResource = 'workflow' | 'journey';
|
|
240
|
+
/**
|
|
241
|
+
* Stable server identities, not the transient React Flow node keys that a clean
|
|
242
|
+
* editor replacement can regenerate. Workflow Tasks and notes use numeric ids;
|
|
243
|
+
* Journey steps/routes/endings use their durable UUIDs.
|
|
244
|
+
*/
|
|
245
|
+
type EditorCollaborationItemKind = 'workflow' | 'task' | 'note' | 'journey' | 'step' | 'route' | 'ending' | 'enrollment' | 'goal' | 'connection' | 'wait' | 'action';
|
|
246
|
+
/**
|
|
247
|
+
* Journey item ids: `step`, `route`, `ending`, `enrollment` and `goal` use the
|
|
248
|
+
* object's own UUID. A `wait` is the wait before a step, so its id is that
|
|
249
|
+
* step's UUID. An `action` is one EventRule on a step or Ending, so its id is
|
|
250
|
+
* that EventRule's UUID.
|
|
251
|
+
*/
|
|
252
|
+
interface EditorCollaborationItem {
|
|
253
|
+
kind: EditorCollaborationItemKind;
|
|
254
|
+
id: number | string;
|
|
255
|
+
}
|
|
256
|
+
/** A person with the editor open, or the workspace Manager acting for one. */
|
|
257
|
+
type EditorCollaboratorKind = 'member' | 'manager';
|
|
258
|
+
interface EditorCollaborator {
|
|
259
|
+
/** `manager` draws the Manager mark; its `memberId` is the person it acts for. */
|
|
260
|
+
kind: EditorCollaboratorKind;
|
|
261
|
+
memberId: number;
|
|
262
|
+
name: string | null;
|
|
263
|
+
/** The image to draw, if any; null means draw the icon or the initials. */
|
|
264
|
+
avatarUrl: string | null;
|
|
265
|
+
/** Null draws the Member's initials. */
|
|
266
|
+
avatarIcon: AccountResponseAvatarIcon;
|
|
267
|
+
/** Null on a server that predates the field; the client derives one. */
|
|
268
|
+
avatarColor: AccountResponseAvatarColor | null;
|
|
269
|
+
}
|
|
270
|
+
interface CollaboratorsChangedEvent {
|
|
271
|
+
type: 'collaborators.changed';
|
|
272
|
+
collaborators: EditorCollaborator[];
|
|
273
|
+
}
|
|
274
|
+
interface EditorUpdatedEvent {
|
|
275
|
+
type: 'editor.updated';
|
|
276
|
+
editor: EditorCollaborator;
|
|
277
|
+
items: EditorCollaborationItem[];
|
|
278
|
+
/** One mounted browser editor, distinct from the Member using other tabs. */
|
|
279
|
+
originId: string;
|
|
280
|
+
updatedAt: string;
|
|
281
|
+
}
|
|
282
|
+
type EditorCollaborationEvent = CollaboratorsChangedEvent | EditorUpdatedEvent;
|
|
283
|
+
declare function editorCollaborationChannel(resource: EditorCollaborationResource, resourceId: number): string;
|
|
284
|
+
declare function editorCollaborationItemKey(item: EditorCollaborationItem): string;
|
|
285
|
+
/** Narrow the untyped shared-socket envelope before it changes editor state. */
|
|
286
|
+
declare function parseEditorCollaborationEvent(event: ChannelEvent): EditorCollaborationEvent | null;
|
|
287
|
+
|
|
207
288
|
/**
|
|
208
289
|
* How long one connect attempt waits for its login token. A provider that
|
|
209
290
|
* never settles (a hung mint request) must not hold the attempt open forever:
|
|
@@ -223,6 +304,8 @@ interface OperatorSessionHandlers {
|
|
|
223
304
|
onCallPhaseChange?: (phase: OperatorCallPhase) => void;
|
|
224
305
|
onAguiEvent?: (event: ChannelEvent) => void;
|
|
225
306
|
onError?: (message: string) => void;
|
|
307
|
+
/** The session was refused for want of an org session; the step-up path takes it from here. */
|
|
308
|
+
onOrgAuthRequired?: (requirement: OrgAuthRequirement) => void;
|
|
226
309
|
/** Fired when the server closes the session (e.g. callee hung up). */
|
|
227
310
|
onSessionClosed?: (reason?: string) => void;
|
|
228
311
|
}
|
|
@@ -311,5 +394,5 @@ declare class OperatorSessionClient {
|
|
|
311
394
|
disconnect(): Promise<void>;
|
|
312
395
|
}
|
|
313
396
|
|
|
314
|
-
export { AccountRealtimeClient, AccountRealtimeSession, ChannelEvent, ChannelListener, LOGIN_TOKEN_TIMEOUT_MS, OperatorCallPhase, OperatorSessionClient, OperatorSessionState, RealtimeAuthSession, RealtimeSessionBase, RealtimeSocketClient, Unsubscribe, WorkspaceRealtimeClient, buildAccountWsUrl, buildWorkspaceWsUrl, initAccountSocket, initWorkspaceSocket, isAccountSocketConnected, isWorkspaceSocketConnected, onAccountSocketConnection, onWorkspaceSocketConnection, subscribeAccountChannel, subscribeWorkspaceChannel, workspaceChannel };
|
|
315
|
-
export type { OperatorSessionHandlers, ProtocolInitMessage };
|
|
397
|
+
export { AccountRealtimeClient, AccountRealtimeSession, ChannelEvent, ChannelListener, LOGIN_TOKEN_TIMEOUT_MS, OperatorCallPhase, OperatorSessionClient, OperatorSessionState, OrgAuthRequirement, OrgSessionsUpdate, RealtimeAuthSession, RealtimeSessionBase, RealtimeSocketClient, Unsubscribe, WorkspaceRealtimeClient, buildAccountWsUrl, buildWorkspaceWsUrl, editorCollaborationChannel, editorCollaborationItemKey, initAccountSocket, initWorkspaceSocket, isAccountSocketConnected, isWorkspaceSocketConnected, onAccountSocketConnection, onWorkspaceSocketConnection, parseEditorCollaborationEvent, subscribeAccountChannel, subscribeWorkspaceChannel, workspaceChannel };
|
|
398
|
+
export type { CollaboratorsChangedEvent, EditorCollaborationEvent, EditorCollaborationItem, EditorCollaborationItemKind, EditorCollaborationResource, EditorCollaborator, EditorCollaboratorKind, EditorUpdatedEvent, OperatorSessionHandlers, ProtocolInitMessage };
|
package/dist/realtime.js
CHANGED
|
@@ -6,6 +6,32 @@ import {
|
|
|
6
6
|
} from "./chunk-BSOOMHW6.js";
|
|
7
7
|
|
|
8
8
|
// src/realtime/types.ts
|
|
9
|
+
function parseOrgAuthRequirement(value) {
|
|
10
|
+
if (typeof value !== "object" || value === null) return null;
|
|
11
|
+
const item = value;
|
|
12
|
+
const {
|
|
13
|
+
workspace_uuid: workspaceUuid,
|
|
14
|
+
org_uuid: orgUuid,
|
|
15
|
+
auth_url: authUrl,
|
|
16
|
+
requirement
|
|
17
|
+
} = item;
|
|
18
|
+
if (typeof workspaceUuid !== "string" || typeof orgUuid !== "string" || typeof authUrl !== "string" || !workspaceUuid || !orgUuid) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
workspaceUuid,
|
|
23
|
+
orgUuid,
|
|
24
|
+
authUrl,
|
|
25
|
+
requirement: requirement === "mfa" ? "mfa" : "sso"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function parseOrgAuthRequirements(value) {
|
|
29
|
+
if (!Array.isArray(value)) return [];
|
|
30
|
+
return value.flatMap((item) => {
|
|
31
|
+
const parsed = parseOrgAuthRequirement(item);
|
|
32
|
+
return parsed ? [parsed] : [];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
9
35
|
function isActiveCallPhase(phase) {
|
|
10
36
|
return phase === "dialing" || phase === "live" || phase === "onHold";
|
|
11
37
|
}
|
|
@@ -47,6 +73,9 @@ var RECONNECT_DELAY_MS = 3e3;
|
|
|
47
73
|
var MAX_RECONNECT_ATTEMPTS = 5;
|
|
48
74
|
var CLOSE_DELAY_MS = 1e3;
|
|
49
75
|
var MAX_SUBSCRIBE_RETRY_DELAY_MS = 3e4;
|
|
76
|
+
var CREDENTIAL_REVOKED_CLOSE_CODE = 4001;
|
|
77
|
+
var CREDENTIAL_REVOKED_CODE = "credential_revoked";
|
|
78
|
+
var CREDENTIAL_REVOKED_REASON = "Credential revoked";
|
|
50
79
|
function createSocketState() {
|
|
51
80
|
return {
|
|
52
81
|
ws: null,
|
|
@@ -64,6 +93,8 @@ function createSocketState() {
|
|
|
64
93
|
heartbeatTimer: null,
|
|
65
94
|
closeTimer: null,
|
|
66
95
|
intentionalClose: false,
|
|
96
|
+
orgAuthHalted: false,
|
|
97
|
+
credentialRevoked: false,
|
|
67
98
|
connectGeneration: 0
|
|
68
99
|
};
|
|
69
100
|
}
|
|
@@ -72,6 +103,9 @@ var RealtimeSocketClient = class {
|
|
|
72
103
|
getSessionFn;
|
|
73
104
|
state = createSocketState();
|
|
74
105
|
connectionListeners = /* @__PURE__ */ new Set();
|
|
106
|
+
orgAuthListeners = /* @__PURE__ */ new Set();
|
|
107
|
+
orgSessionsListeners = /* @__PURE__ */ new Set();
|
|
108
|
+
credentialRevokedListeners = /* @__PURE__ */ new Set();
|
|
75
109
|
constructor(config) {
|
|
76
110
|
if (typeof config === "function") {
|
|
77
111
|
this.getSessionFn = config;
|
|
@@ -158,6 +192,7 @@ var RealtimeSocketClient = class {
|
|
|
158
192
|
if (changed && (this.state.ws || this.state.connecting)) {
|
|
159
193
|
this.closeConnection();
|
|
160
194
|
}
|
|
195
|
+
if (changed) this.state.credentialRevoked = false;
|
|
161
196
|
if (this.state.listeners.size > 0) {
|
|
162
197
|
this.ensureConnection();
|
|
163
198
|
}
|
|
@@ -194,6 +229,79 @@ var RealtimeSocketClient = class {
|
|
|
194
229
|
}
|
|
195
230
|
};
|
|
196
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Hear every workspace the server refused for want of an org session: a
|
|
234
|
+
* `subscribe_error` entry, an `error` frame with that code, a lapse notice,
|
|
235
|
+
* or the list in an `org_sessions_updated` reply.
|
|
236
|
+
*/
|
|
237
|
+
onOrgAuthRequired(listener) {
|
|
238
|
+
this.orgAuthListeners.add(listener);
|
|
239
|
+
return () => {
|
|
240
|
+
this.orgAuthListeners.delete(listener);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** Hear the server's reply to an `org_sessions` frame. */
|
|
244
|
+
onOrgSessionsUpdated(listener) {
|
|
245
|
+
this.orgSessionsListeners.add(listener);
|
|
246
|
+
return () => {
|
|
247
|
+
this.orgSessionsListeners.delete(listener);
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Hear that the server ended this socket's login credential. The client
|
|
252
|
+
* does not reconnect afterwards; the consumer decides what the person sees
|
|
253
|
+
* (in the web app, the account check that leads to the login page).
|
|
254
|
+
*/
|
|
255
|
+
onCredentialRevoked(listener) {
|
|
256
|
+
this.credentialRevokedListeners.add(listener);
|
|
257
|
+
return () => {
|
|
258
|
+
this.credentialRevokedListeners.delete(listener);
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** Whether the server ended this socket's login credential. */
|
|
262
|
+
isCredentialRevoked() {
|
|
263
|
+
return this.state.credentialRevoked;
|
|
264
|
+
}
|
|
265
|
+
markCredentialRevoked(message) {
|
|
266
|
+
if (this.state.credentialRevoked) return;
|
|
267
|
+
this.state.credentialRevoked = true;
|
|
268
|
+
this.state.lastError = message;
|
|
269
|
+
if (this.state.reconnectTimer) {
|
|
270
|
+
clearTimeout(this.state.reconnectTimer);
|
|
271
|
+
this.state.reconnectTimer = null;
|
|
272
|
+
}
|
|
273
|
+
this.notifyConnectionListeners();
|
|
274
|
+
for (const listener of this.credentialRevokedListeners) listener();
|
|
275
|
+
}
|
|
276
|
+
emitOrgAuthRequired(items) {
|
|
277
|
+
if (items.length === 0) return;
|
|
278
|
+
for (const listener of this.orgAuthListeners) listener(items);
|
|
279
|
+
}
|
|
280
|
+
/** Send a control frame (one that is not a channel message) on the open socket. */
|
|
281
|
+
sendFrame(frame) {
|
|
282
|
+
if (!this.state.connected || this.state.ws?.readyState !== WebSocket.OPEN) return false;
|
|
283
|
+
this.state.ws.send(JSON.stringify(frame));
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Try again after the person completed org sign-in: reconnect a socket the
|
|
288
|
+
* server closed for it, or ask again for every channel it refused.
|
|
289
|
+
*/
|
|
290
|
+
retryAfterOrgAuth() {
|
|
291
|
+
this.state.orgAuthHalted = false;
|
|
292
|
+
if (this.state.connected && this.state.ws?.readyState === WebSocket.OPEN) {
|
|
293
|
+
const pending = Array.from(this.state.listeners.keys()).filter(
|
|
294
|
+
(channel) => !this.state.subscribedChannels.has(channel)
|
|
295
|
+
);
|
|
296
|
+
if (pending.length > 0) {
|
|
297
|
+
this.state.ws.send(JSON.stringify({ type: "subscribe", channels: pending }));
|
|
298
|
+
}
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (this.state.ws || this.state.connecting) return;
|
|
302
|
+
this.state.reconnectAttempts = 0;
|
|
303
|
+
this.ensureConnection();
|
|
304
|
+
}
|
|
197
305
|
send(channel, data) {
|
|
198
306
|
if (!this.state.connected || !this.state.ws) return;
|
|
199
307
|
this.state.ws.send(JSON.stringify({ type: "message", channel, data }));
|
|
@@ -251,6 +359,7 @@ var RealtimeSocketClient = class {
|
|
|
251
359
|
if (!session) return;
|
|
252
360
|
if (typeof window === "undefined" || typeof WebSocket === "undefined") return;
|
|
253
361
|
if (this.state.ws || this.state.connecting) return;
|
|
362
|
+
if (this.state.credentialRevoked) return;
|
|
254
363
|
this.clearCloseTimer();
|
|
255
364
|
this.state.connecting = true;
|
|
256
365
|
this.state.intentionalClose = false;
|
|
@@ -320,10 +429,17 @@ var RealtimeSocketClient = class {
|
|
|
320
429
|
}
|
|
321
430
|
if (msg.type === "subscribe_error" && Array.isArray(msg.errors)) {
|
|
322
431
|
const retryableChannels = [];
|
|
432
|
+
const orgRequired = [];
|
|
323
433
|
for (const rawError of msg.errors) {
|
|
324
434
|
if (!rawError || typeof rawError !== "object") continue;
|
|
325
435
|
const error = rawError;
|
|
326
436
|
if (typeof error.channel !== "string") continue;
|
|
437
|
+
if (error.code === "org_auth_required") {
|
|
438
|
+
this.clearSubscriptionRetry(error.channel);
|
|
439
|
+
const requirement = parseOrgAuthRequirement(rawError);
|
|
440
|
+
if (requirement) orgRequired.push(requirement);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
327
443
|
if (error.retryable === true) {
|
|
328
444
|
retryableChannels.push(error.channel);
|
|
329
445
|
} else {
|
|
@@ -331,6 +447,20 @@ var RealtimeSocketClient = class {
|
|
|
331
447
|
}
|
|
332
448
|
}
|
|
333
449
|
this.scheduleSubscriptionRetry(retryableChannels);
|
|
450
|
+
this.emitOrgAuthRequired(orgRequired);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (msg.type === "org_auth_required") {
|
|
454
|
+
this.emitOrgAuthRequired(parseOrgAuthRequirements(msg.org_auth_required));
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (msg.type === "org_sessions_updated") {
|
|
458
|
+
const orgAuthRequired = parseOrgAuthRequirements(msg.org_auth_required);
|
|
459
|
+
const orgUuids = Array.isArray(msg.org_uuids) ? msg.org_uuids.filter((value) => typeof value === "string") : [];
|
|
460
|
+
for (const listener of this.orgSessionsListeners) {
|
|
461
|
+
listener({ orgUuids, orgAuthRequired });
|
|
462
|
+
}
|
|
463
|
+
this.emitOrgAuthRequired(orgAuthRequired);
|
|
334
464
|
return;
|
|
335
465
|
}
|
|
336
466
|
if (msg.type === "unsubscribed" && Array.isArray(msg.channels)) {
|
|
@@ -342,6 +472,19 @@ var RealtimeSocketClient = class {
|
|
|
342
472
|
this.scheduleSubscriptionRetry(msg.channels);
|
|
343
473
|
return;
|
|
344
474
|
}
|
|
475
|
+
if (msg.type === "error" && msg.code === "org_auth_required") {
|
|
476
|
+
this.state.orgAuthHalted = true;
|
|
477
|
+
const requirement = parseOrgAuthRequirement(msg);
|
|
478
|
+
if (requirement) this.emitOrgAuthRequired([requirement]);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (msg.type === "error" && msg.code === CREDENTIAL_REVOKED_CODE) {
|
|
482
|
+
const message = msg.message;
|
|
483
|
+
this.markCredentialRevoked(
|
|
484
|
+
typeof message === "string" && message ? message : CREDENTIAL_REVOKED_REASON
|
|
485
|
+
);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
345
488
|
if (msg.type === "error") {
|
|
346
489
|
const message = msg.message;
|
|
347
490
|
this.state.lastError = typeof message === "string" && message ? message : "Realtime error";
|
|
@@ -363,8 +506,11 @@ var RealtimeSocketClient = class {
|
|
|
363
506
|
} catch {
|
|
364
507
|
}
|
|
365
508
|
};
|
|
366
|
-
ws.onclose = () => {
|
|
509
|
+
ws.onclose = (event) => {
|
|
367
510
|
if (this.state.ws !== null && this.state.ws !== ws) return;
|
|
511
|
+
if (event?.code === CREDENTIAL_REVOKED_CLOSE_CODE && event.reason === CREDENTIAL_REVOKED_REASON) {
|
|
512
|
+
this.markCredentialRevoked(CREDENTIAL_REVOKED_REASON);
|
|
513
|
+
}
|
|
368
514
|
this.state.connected = false;
|
|
369
515
|
this.state.connecting = false;
|
|
370
516
|
this.state.ws = null;
|
|
@@ -390,8 +536,8 @@ var RealtimeSocketClient = class {
|
|
|
390
536
|
}
|
|
391
537
|
/** Decide whether a connection that just ended (or never opened) retries. */
|
|
392
538
|
afterConnectionEnded() {
|
|
393
|
-
const willRetry = !this.state.intentionalClose && this.state.listeners.size > 0 && this.state.reconnectAttempts < MAX_RECONNECT_ATTEMPTS;
|
|
394
|
-
if (!willRetry && !this.state.intentionalClose && this.state.listeners.size > 0) {
|
|
539
|
+
const willRetry = !this.state.intentionalClose && !this.state.orgAuthHalted && !this.state.credentialRevoked && this.state.listeners.size > 0 && this.state.reconnectAttempts < MAX_RECONNECT_ATTEMPTS;
|
|
540
|
+
if (!willRetry && !this.state.intentionalClose && !this.state.credentialRevoked && this.state.listeners.size > 0) {
|
|
395
541
|
this.state.lastError = "Realtime connection lost";
|
|
396
542
|
}
|
|
397
543
|
this.notifyConnectionListeners();
|
|
@@ -404,6 +550,8 @@ var RealtimeSocketClient = class {
|
|
|
404
550
|
}
|
|
405
551
|
closeConnection() {
|
|
406
552
|
this.state.intentionalClose = true;
|
|
553
|
+
this.state.orgAuthHalted = false;
|
|
554
|
+
this.state.credentialRevoked = false;
|
|
407
555
|
this.state.connectGeneration += 1;
|
|
408
556
|
this.clearCloseTimer();
|
|
409
557
|
if (this.state.reconnectTimer) {
|
|
@@ -525,6 +673,91 @@ function isAccountSocketConnected() {
|
|
|
525
673
|
return defaultClient2.isConnected();
|
|
526
674
|
}
|
|
527
675
|
|
|
676
|
+
// src/types/generated/account.ts
|
|
677
|
+
var AccountResponseAvatarColor = {
|
|
678
|
+
teal: "teal",
|
|
679
|
+
sky: "sky",
|
|
680
|
+
blue: "blue",
|
|
681
|
+
indigo: "indigo",
|
|
682
|
+
violet: "violet",
|
|
683
|
+
fuchsia: "fuchsia",
|
|
684
|
+
slate: "slate"
|
|
685
|
+
};
|
|
686
|
+
var AccountResponseAvatarIcon = {
|
|
687
|
+
user: "user",
|
|
688
|
+
stethoscope: "stethoscope",
|
|
689
|
+
heart: "heart",
|
|
690
|
+
shield: "shield",
|
|
691
|
+
sparkles: "sparkles",
|
|
692
|
+
star: "star"
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
// src/realtime/editor-collaboration.ts
|
|
696
|
+
function editorCollaborationChannel(resource, resourceId) {
|
|
697
|
+
return `collaboration:${resource}:${resourceId}`;
|
|
698
|
+
}
|
|
699
|
+
function editorCollaborationItemKey(item) {
|
|
700
|
+
return `${item.kind}:${String(item.id)}`;
|
|
701
|
+
}
|
|
702
|
+
function parseCollaborator(value) {
|
|
703
|
+
if (typeof value !== "object" || value === null) return null;
|
|
704
|
+
const record = value;
|
|
705
|
+
if (typeof record.memberId !== "number" || !Number.isInteger(record.memberId)) return null;
|
|
706
|
+
const name = record.name;
|
|
707
|
+
const avatarUrl = record.avatarUrl;
|
|
708
|
+
const avatarIcon = record.avatarIcon;
|
|
709
|
+
const avatarColor = record.avatarColor;
|
|
710
|
+
return {
|
|
711
|
+
kind: record.kind === "manager" ? "manager" : "member",
|
|
712
|
+
memberId: record.memberId,
|
|
713
|
+
name: typeof name === "string" ? name : null,
|
|
714
|
+
avatarUrl: typeof avatarUrl === "string" ? avatarUrl : null,
|
|
715
|
+
avatarIcon: typeof avatarIcon === "string" && avatarIcon in AccountResponseAvatarIcon ? avatarIcon : null,
|
|
716
|
+
avatarColor: typeof avatarColor === "string" && avatarColor in AccountResponseAvatarColor ? avatarColor : null
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function parseItem(value) {
|
|
720
|
+
if (typeof value !== "object" || value === null) return null;
|
|
721
|
+
const item = value;
|
|
722
|
+
const kind = item.kind;
|
|
723
|
+
const id = item.id;
|
|
724
|
+
const validKind = kind === "workflow" || kind === "task" || kind === "note" || kind === "journey" || kind === "step" || kind === "route" || kind === "ending" || kind === "enrollment" || kind === "goal" || kind === "connection" || kind === "wait" || kind === "action";
|
|
725
|
+
if (!validKind) return null;
|
|
726
|
+
if (typeof id !== "number" && typeof id !== "string") return null;
|
|
727
|
+
if (!String(id)) return null;
|
|
728
|
+
return { kind, id };
|
|
729
|
+
}
|
|
730
|
+
function parseEditorCollaborationEvent(event) {
|
|
731
|
+
const data = event.data;
|
|
732
|
+
if (typeof data !== "object" || data === null) return null;
|
|
733
|
+
const record = data;
|
|
734
|
+
if (event.type === "collaborators.changed") {
|
|
735
|
+
if (!Array.isArray(record.collaborators)) return null;
|
|
736
|
+
const collaborators = record.collaborators.flatMap((value) => {
|
|
737
|
+
const parsed = parseCollaborator(value);
|
|
738
|
+
return parsed ? [parsed] : [];
|
|
739
|
+
});
|
|
740
|
+
return { type: event.type, collaborators };
|
|
741
|
+
}
|
|
742
|
+
if (event.type === "editor.updated") {
|
|
743
|
+
const editor = parseCollaborator(record.editor);
|
|
744
|
+
const rawItems = record.items;
|
|
745
|
+
if (!editor || !Array.isArray(rawItems) || rawItems.length === 0 || rawItems.length > 100 || typeof record.originId !== "string" || typeof record.updatedAt !== "string") {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
const items = rawItems.map(parseItem);
|
|
749
|
+
if (items.some((item) => item === null)) return null;
|
|
750
|
+
return {
|
|
751
|
+
type: event.type,
|
|
752
|
+
editor,
|
|
753
|
+
items,
|
|
754
|
+
originId: record.originId,
|
|
755
|
+
updatedAt: record.updatedAt
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
|
|
528
761
|
// src/realtime/operator-session-client.ts
|
|
529
762
|
var OperatorSessionClient = class {
|
|
530
763
|
constructor(handlers = {}) {
|
|
@@ -630,6 +863,10 @@ var OperatorSessionClient = class {
|
|
|
630
863
|
handleMessage(msg, resolveLogin, rejectLogin) {
|
|
631
864
|
if (msg.type === "RUN_ERROR" || msg.type === "error") {
|
|
632
865
|
const message = msg.message ?? "Operator session error";
|
|
866
|
+
if (msg.code === "org_auth_required") {
|
|
867
|
+
const requirement = parseOrgAuthRequirement(msg);
|
|
868
|
+
if (requirement) this.handlers.onOrgAuthRequired?.(requirement);
|
|
869
|
+
}
|
|
633
870
|
if (this.sessionState === "connecting") {
|
|
634
871
|
this.setSessionState("error");
|
|
635
872
|
rejectLogin(new Error(message));
|
|
@@ -955,6 +1192,8 @@ export {
|
|
|
955
1192
|
WorkspaceRealtimeClient,
|
|
956
1193
|
buildAccountWsUrl,
|
|
957
1194
|
buildWorkspaceWsUrl,
|
|
1195
|
+
editorCollaborationChannel,
|
|
1196
|
+
editorCollaborationItemKey,
|
|
958
1197
|
initAccountSocket,
|
|
959
1198
|
initWorkspaceSocket,
|
|
960
1199
|
isAccountSocketConnected,
|
|
@@ -963,6 +1202,9 @@ export {
|
|
|
963
1202
|
isWorkspaceSocketConnected,
|
|
964
1203
|
onAccountSocketConnection,
|
|
965
1204
|
onWorkspaceSocketConnection,
|
|
1205
|
+
parseEditorCollaborationEvent,
|
|
1206
|
+
parseOrgAuthRequirement,
|
|
1207
|
+
parseOrgAuthRequirements,
|
|
966
1208
|
subscribeAccountChannel,
|
|
967
1209
|
subscribeWorkspaceChannel,
|
|
968
1210
|
workspaceChannel
|