@andocorp/sdk 0.0.1 → 0.2.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 +21 -0
- package/README.md +63 -0
- package/dist/agent-endpoints.d.ts +89 -0
- package/dist/agent-endpoints.d.ts.map +1 -0
- package/dist/agent-endpoints.js +229 -0
- package/dist/agent-endpoints.js.map +1 -0
- package/dist/agent-types.d.ts +81 -0
- package/dist/agent-types.d.ts.map +1 -0
- package/dist/agent-types.js +3 -0
- package/dist/agent-types.js.map +1 -0
- package/dist/client.d.ts +133 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +525 -57
- package/dist/client.js.map +1 -1
- package/dist/generated/contracts.d.ts +326 -11
- package/dist/generated/contracts.d.ts.map +1 -1
- package/dist/generated/contracts.js +21 -1
- package/dist/generated/contracts.js.map +1 -1
- package/dist/generated/public-api.d.ts +856 -0
- package/dist/generated/public-api.d.ts.map +1 -0
- package/dist/generated/public-api.js +382 -0
- package/dist/generated/public-api.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/realtime-events.d.ts +9 -4
- package/dist/realtime-events.d.ts.map +1 -1
- package/dist/realtime-events.js +113 -157
- package/dist/realtime-events.js.map +1 -1
- package/dist/realtime-runtime.d.ts +6 -17
- package/dist/realtime-runtime.d.ts.map +1 -1
- package/dist/realtime-runtime.js +45 -62
- package/dist/realtime-runtime.js.map +1 -1
- package/dist/realtime-types.d.ts +60 -77
- package/dist/realtime-types.d.ts.map +1 -1
- package/dist/realtime-types.js +2 -0
- package/dist/realtime-types.js.map +1 -1
- package/dist/realtime.d.ts +6 -5
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +282 -144
- package/dist/realtime.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js.map +1 -1
- package/dist/types.d.ts +61 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +24 -16
package/dist/realtime-events.js
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAndoMessageDedupeCache = createAndoMessageDedupeCache;
|
|
4
|
-
exports.
|
|
5
|
-
exports.handleAndoRealtimeIncomingEvent = handleAndoRealtimeIncomingEvent;
|
|
4
|
+
exports.isRealtimeEventFrame = isRealtimeEventFrame;
|
|
6
5
|
exports.prepareAndoRealtimeIncomingEvent = prepareAndoRealtimeIncomingEvent;
|
|
6
|
+
const contracts_1 = require("./generated/contracts");
|
|
7
7
|
const realtime_runtime_1 = require("./realtime-runtime");
|
|
8
|
-
const ANDO_CONVERSATION_TYPE_DIRECT_MESSAGE = 1;
|
|
9
|
-
const ANDO_CONVERSATION_MESSAGE_TYPE_SYSTEM = 1;
|
|
10
8
|
function isRecord(value) {
|
|
11
|
-
return typeof value === "object" && value != null;
|
|
9
|
+
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
12
10
|
}
|
|
13
|
-
function
|
|
14
|
-
return typeof value
|
|
11
|
+
function asString(value) {
|
|
12
|
+
return typeof value === "string" ? value : null;
|
|
15
13
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
function messageText(message) {
|
|
15
|
+
const markdown = message.markdown_content?.trim();
|
|
16
|
+
if (markdown) {
|
|
17
|
+
return markdown;
|
|
18
|
+
}
|
|
19
|
+
const content = message.content?.trim();
|
|
20
|
+
if (content) {
|
|
21
|
+
return content;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
function subscriptionMentionTarget(target) {
|
|
26
|
+
if (target?.type === "workspace_membership") {
|
|
27
|
+
return {
|
|
28
|
+
targetType: "workspace_membership",
|
|
29
|
+
targetId: target.id,
|
|
30
|
+
};
|
|
26
31
|
}
|
|
27
|
-
return
|
|
28
|
-
const id = memberGroupId?.trim();
|
|
29
|
-
if (!id) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return new RegExp(`<!member_group:${id}\\|[^>]+>`).test(normalized);
|
|
33
|
-
});
|
|
32
|
+
return null;
|
|
34
33
|
}
|
|
35
|
-
function
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
error.message.includes("returned null")) {
|
|
39
|
-
return true;
|
|
34
|
+
function isDirectMessageEvent(params) {
|
|
35
|
+
if (params.conversationType != null) {
|
|
36
|
+
return params.conversationType === contracts_1.ConversationType.DIRECT_MESSAGE;
|
|
40
37
|
}
|
|
41
|
-
return (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
return !params.message.conversation_name?.trim();
|
|
39
|
+
}
|
|
40
|
+
function isMessageResult(value) {
|
|
41
|
+
return (isRecord(value) &&
|
|
42
|
+
typeof value["id"] === "string" &&
|
|
43
|
+
typeof value["conversation_id"] === "string" &&
|
|
44
|
+
typeof value["author_id"] === "string" &&
|
|
45
|
+
Array.isArray(value["image_urls"]) &&
|
|
46
|
+
Array.isArray(value["reactions"]));
|
|
45
47
|
}
|
|
46
48
|
function createAndoMessageDedupeCache(options) {
|
|
47
49
|
const messages = new Map();
|
|
@@ -84,35 +86,48 @@ function createAndoMessageDedupeCache(options) {
|
|
|
84
86
|
},
|
|
85
87
|
};
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const conversation = event.membership.conversation;
|
|
95
|
-
return isRecord(conversation) && isStringProperty(conversation, "id");
|
|
89
|
+
function isRealtimeEventFrame(value) {
|
|
90
|
+
return (isRecord(value) &&
|
|
91
|
+
value["type"] === "event" &&
|
|
92
|
+
typeof value["envelope_id"] === "string" &&
|
|
93
|
+
typeof value["subscription_id"] === "string" &&
|
|
94
|
+
typeof value["cursor"] === "string" &&
|
|
95
|
+
isRecord(value["payload"]));
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
return (isStringProperty(event.message, "id") &&
|
|
105
|
-
isStringProperty(event.message, "conversation_id"));
|
|
97
|
+
function isMessageCreatedProductEvent(value) {
|
|
98
|
+
return (isRecord(value) &&
|
|
99
|
+
value["type"] === "message.created" &&
|
|
100
|
+
isRecord(value["data"]) &&
|
|
101
|
+
isMessageResult(value["data"]["object"]));
|
|
106
102
|
}
|
|
107
|
-
function
|
|
103
|
+
function toRealtimeMessage(event) {
|
|
104
|
+
const object = event.data.object;
|
|
105
|
+
const related = isRecord(event.related) ? event.related : {};
|
|
106
|
+
const threadRootId = asString(related.thread_root_message_id);
|
|
107
|
+
const callId = asString(related.call_id);
|
|
108
|
+
return {
|
|
109
|
+
...object,
|
|
110
|
+
author: {
|
|
111
|
+
id: object.author_id,
|
|
112
|
+
display_name: object.author_name,
|
|
113
|
+
},
|
|
114
|
+
call_id: callId,
|
|
115
|
+
content: object.content,
|
|
116
|
+
files: [],
|
|
117
|
+
markdown_content: object.content,
|
|
118
|
+
thread_root_id: threadRootId,
|
|
119
|
+
type: 0,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function buildNormalizedMessageContext(context, message) {
|
|
108
123
|
if (!context?.current_text) {
|
|
109
124
|
return null;
|
|
110
125
|
}
|
|
111
126
|
return {
|
|
112
127
|
currentText: context.current_text,
|
|
113
|
-
replyThreadRootId:
|
|
128
|
+
replyThreadRootId: message.thread_root_id ?? context.reply_thread_root_id,
|
|
114
129
|
inboundHistory: context.inbound_history.map((entry) => ({
|
|
115
|
-
sender: entry.author_name?.trim()
|
|
130
|
+
sender: entry.author_name?.trim() ? entry.author_name.trim() : entry.author_id,
|
|
116
131
|
body: entry.body,
|
|
117
132
|
timestamp: (0, realtime_runtime_1.toUnixTimestamp)(entry.created_at),
|
|
118
133
|
})),
|
|
@@ -120,126 +135,67 @@ function buildNormalizedMessageContext(context) {
|
|
|
120
135
|
threadHistoryBody: context.thread_history_body ?? undefined,
|
|
121
136
|
};
|
|
122
137
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
text: params.event.message.markdown_content,
|
|
128
|
-
memberGroupIds: [
|
|
129
|
-
params.selfMember.member_group_id,
|
|
130
|
-
conversation?.everyone_member_group_id,
|
|
131
|
-
],
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
conversation,
|
|
135
|
-
isDirectMessage,
|
|
136
|
-
skip: params.event.message.type === ANDO_CONVERSATION_MESSAGE_TYPE_SYSTEM ||
|
|
137
|
-
params.event.message.author_id === params.selfMember.id ||
|
|
138
|
-
!mentionsMe,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function handleControlEvent({ socket, roomId, conversations, event, }) {
|
|
142
|
-
if (event.eventId === "heartbeat/ping") {
|
|
143
|
-
(0, realtime_runtime_1.sendJson)(socket, { eventId: "heartbeat/pong" });
|
|
144
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
145
|
-
socket,
|
|
146
|
-
roomId,
|
|
147
|
-
ackId: event._clientAckId,
|
|
148
|
-
});
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
if (isMembershipNewEvent(event)) {
|
|
152
|
-
conversations.set(event.membership.conversation.id, event.membership.conversation);
|
|
153
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
154
|
-
socket,
|
|
155
|
-
roomId,
|
|
156
|
-
ackId: event._clientAckId,
|
|
157
|
-
});
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
if (!isMessageNewEvent(event)) {
|
|
161
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
162
|
-
socket,
|
|
163
|
-
roomId,
|
|
164
|
-
ackId: event._clientAckId,
|
|
165
|
-
});
|
|
138
|
+
function isNonRetryableContextError(error) {
|
|
139
|
+
if (error instanceof Error &&
|
|
140
|
+
error.message.includes("/conversation-messages/") &&
|
|
141
|
+
error.message.includes("returned null")) {
|
|
166
142
|
return true;
|
|
167
143
|
}
|
|
168
|
-
return
|
|
144
|
+
return (error instanceof Error &&
|
|
145
|
+
"status" in error &&
|
|
146
|
+
error.status != null &&
|
|
147
|
+
[404, 410, 422].includes(Number(error.status)));
|
|
169
148
|
}
|
|
170
|
-
async function
|
|
171
|
-
|
|
172
|
-
api,
|
|
173
|
-
|
|
174
|
-
conversations,
|
|
175
|
-
seenMessages,
|
|
176
|
-
selfMember,
|
|
177
|
-
signal: options.signal,
|
|
178
|
-
});
|
|
179
|
-
if (preparedMessage.markSeen) {
|
|
180
|
-
seenMessages.mark(event.message.id);
|
|
149
|
+
async function getConversationMetadata(api, conversationId, signal) {
|
|
150
|
+
try {
|
|
151
|
+
const conversation = await api.getConversation?.(conversationId, signal);
|
|
152
|
+
return conversation ?? undefined;
|
|
181
153
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
roomId,
|
|
185
|
-
ackId: event._clientAckId,
|
|
186
|
-
});
|
|
187
|
-
if (preparedMessage.kind !== "deliver") {
|
|
188
|
-
return;
|
|
154
|
+
catch {
|
|
155
|
+
return undefined;
|
|
189
156
|
}
|
|
190
|
-
await options.onMessage?.(preparedMessage.messageEvent);
|
|
191
157
|
}
|
|
192
|
-
async function prepareAndoRealtimeIncomingEvent({ api,
|
|
193
|
-
if (
|
|
194
|
-
return {
|
|
195
|
-
kind: "drop",
|
|
196
|
-
markSeen: false,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (!conversations.has(event.message.conversation_id)) {
|
|
200
|
-
const memberships = await (0, realtime_runtime_1.listAllMemberships)(api, signal);
|
|
201
|
-
(0, realtime_runtime_1.updateConversationCache)(conversations, memberships);
|
|
158
|
+
async function prepareAndoRealtimeIncomingEvent({ api, frame, seenMessages, signal, subscriptionTarget, }) {
|
|
159
|
+
if (!isMessageCreatedProductEvent(frame.payload)) {
|
|
160
|
+
return { kind: "drop", cursor: frame.cursor };
|
|
202
161
|
}
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
selfMember,
|
|
207
|
-
});
|
|
208
|
-
if (messageEvaluation.skip) {
|
|
209
|
-
return {
|
|
210
|
-
kind: "drop",
|
|
211
|
-
markSeen: false,
|
|
212
|
-
};
|
|
162
|
+
const message = toRealtimeMessage(frame.payload);
|
|
163
|
+
if (seenMessages.has(message.id)) {
|
|
164
|
+
return { kind: "drop", cursor: frame.cursor };
|
|
213
165
|
}
|
|
214
|
-
let
|
|
166
|
+
let context;
|
|
215
167
|
try {
|
|
216
|
-
|
|
168
|
+
context = buildNormalizedMessageContext(await api.getMessageContext(message.id, signal, {
|
|
169
|
+
threadRootId: message.thread_root_id,
|
|
170
|
+
}), message);
|
|
217
171
|
}
|
|
218
172
|
catch (error) {
|
|
219
|
-
if (isNonRetryableContextError(error)) {
|
|
220
|
-
|
|
221
|
-
kind: "drop",
|
|
222
|
-
markSeen: true,
|
|
223
|
-
};
|
|
173
|
+
if (!isNonRetryableContextError(error)) {
|
|
174
|
+
throw error;
|
|
224
175
|
}
|
|
225
|
-
|
|
176
|
+
context = null;
|
|
226
177
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
kind: "drop",
|
|
231
|
-
markSeen: false,
|
|
232
|
-
};
|
|
178
|
+
if (!context?.currentText && !messageText(message)) {
|
|
179
|
+
return { kind: "drop", cursor: frame.cursor };
|
|
233
180
|
}
|
|
181
|
+
const conversation = await getConversationMetadata(api, message.conversation_id, signal);
|
|
182
|
+
const conversationType = conversation?.type ?? null;
|
|
183
|
+
const event = {
|
|
184
|
+
message,
|
|
185
|
+
conversation,
|
|
186
|
+
conversationType,
|
|
187
|
+
isDirectMessage: isDirectMessageEvent({ conversationType, message }),
|
|
188
|
+
wasMentioned: true,
|
|
189
|
+
selfMentionTargets: [subscriptionMentionTarget(subscriptionTarget)].filter((target) => target != null),
|
|
190
|
+
context,
|
|
191
|
+
cursor: frame.cursor,
|
|
192
|
+
productEventId: frame.payload.id,
|
|
193
|
+
subscriptionId: frame.subscription_id,
|
|
194
|
+
};
|
|
234
195
|
return {
|
|
235
196
|
kind: "deliver",
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
message: event.message,
|
|
239
|
-
conversation: messageEvaluation.conversation,
|
|
240
|
-
isDirectMessage: messageEvaluation.isDirectMessage,
|
|
241
|
-
context,
|
|
242
|
-
},
|
|
197
|
+
cursor: frame.cursor,
|
|
198
|
+
event,
|
|
243
199
|
};
|
|
244
200
|
}
|
|
245
201
|
//# sourceMappingURL=realtime-events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-events.js","sourceRoot":"","sources":["../src/realtime-events.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"realtime-events.js","sourceRoot":"","sources":["../src/realtime-events.ts"],"names":[],"mappings":";;AA6EA,oEAiDC;AAED,oDASC;AAqFD,4EAmEC;AA3RD,qDAAyD;AACzD,yDAAqD;AAWrD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,OAA4B;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,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AAK,CAAC,MAAM,EAAE,CAAC;IAChD,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,uBAAuB,CAChD,GAAG,EACH,OAAO,CAAC,eAAe,EACvB,MAAM,CACP,CAAC;IACF,MAAM,gBAAgB,GAAG,YAAY,EAAE,IAAI,IAAI,IAAI,CAAC;IACpD,MAAM,KAAK,GAAsC;QAC/C,OAAO;QACP,YAAY;QACZ,gBAAgB;QAChB,eAAe,EAAE,oBAAoB,CAAC,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;QACpE,YAAY,EAAE,IAAI;QAClB,kBAAkB,EAAE,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CACxE,CAAC,MAAM,EAA+B,EAAE,CAAC,MAAM,IAAI,IAAI,CACxD;QACD,OAAO;QACP,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE;QAChC,cAAc,EAAE,KAAK,CAAC,eAAe;KACtC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AndoRawRealtimeEvent, AndoRealtimeApi, AndoSocket, SelfMember, SocketListener } from "./realtime-types";
|
|
1
|
+
import { AndoSocket, AndoWebSocketProtocols, SocketListener } from "./realtime-types";
|
|
3
2
|
export declare function delay(ms: number, abortSignal?: AbortSignal): Promise<void>;
|
|
4
3
|
export declare function isAbortError(error: unknown): boolean;
|
|
5
4
|
export declare function isPermanentAuthFailure(error: unknown): boolean;
|
|
6
5
|
export declare function toAbortError(reason?: unknown): Error;
|
|
7
6
|
export declare function toUnixTimestamp(value: string | Date | undefined): number | undefined;
|
|
8
|
-
export declare function pickSelfMember(me: Awaited<ReturnType<AndoRealtimeApi["getMe"]>>, memberGroupId: string | null): SelfMember;
|
|
9
7
|
export declare function buildAndoRealtimeWebSocketUrl(params: {
|
|
10
8
|
realtimeHost: string;
|
|
11
|
-
roomId: string;
|
|
12
|
-
token: string;
|
|
13
9
|
}): string;
|
|
10
|
+
export declare function buildAndoRealtimeWebSocketAuthProtocols(): string[];
|
|
11
|
+
export declare function redactRealtimeConnectionSecrets(value: string): string;
|
|
14
12
|
export declare function addSocketListener(socket: AndoSocket, event: string, listener: SocketListener): () => void;
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function parseAndoRealtimeEvent(raw: unknown): AndoRawRealtimeEvent | null;
|
|
18
|
-
export declare function sendJson(socket: AndoSocket, payload: unknown): void;
|
|
13
|
+
export declare function parseAndoRealtimeEvent(raw: unknown): unknown | null;
|
|
14
|
+
export declare function sendJson(socket: AndoSocket, payload: unknown): boolean;
|
|
19
15
|
export declare function closeSocket(socket: AndoSocket): void;
|
|
20
|
-
export declare function
|
|
21
|
-
socket: AndoSocket;
|
|
22
|
-
roomId: string;
|
|
23
|
-
ackId?: string;
|
|
24
|
-
}): void;
|
|
25
|
-
export declare function openSocket(url: string, abortSignal?: AbortSignal, setup?: (socket: AndoSocket) => void): Promise<AndoSocket>;
|
|
16
|
+
export declare function openSocket(url: string, abortSignal?: AbortSignal, setup?: (socket: AndoSocket) => void, protocols?: AndoWebSocketProtocols): Promise<AndoSocket>;
|
|
26
17
|
export declare function waitForSocketClose(socket: AndoSocket, abortSignal?: AbortSignal): Promise<void>;
|
|
27
|
-
export declare function listAllMemberships(api: Pick<AndoRealtimeApi, "getMyMemberships">, signal?: AbortSignal): Promise<AndoMembership[]>;
|
|
28
|
-
export declare function updateConversationCache(conversations: Map<string, AndoMembership["conversation"]>, memberships: AndoMembership[]): void;
|
|
29
18
|
//# sourceMappingURL=realtime-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-runtime.d.ts","sourceRoot":"","sources":["../src/realtime-runtime.ts"],"names":[],"mappings":"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AAK,IAAI,EACpC,SAAS,CAAC,EAAE,sBAAsB,GACjC,OAAO,CAAC,UAAU,CAAC,CAwErB;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,iBAqCrF"}
|
package/dist/realtime-runtime.js
CHANGED
|
@@ -5,19 +5,15 @@ exports.isAbortError = isAbortError;
|
|
|
5
5
|
exports.isPermanentAuthFailure = isPermanentAuthFailure;
|
|
6
6
|
exports.toAbortError = toAbortError;
|
|
7
7
|
exports.toUnixTimestamp = toUnixTimestamp;
|
|
8
|
-
exports.pickSelfMember = pickSelfMember;
|
|
9
8
|
exports.buildAndoRealtimeWebSocketUrl = buildAndoRealtimeWebSocketUrl;
|
|
9
|
+
exports.buildAndoRealtimeWebSocketAuthProtocols = buildAndoRealtimeWebSocketAuthProtocols;
|
|
10
|
+
exports.redactRealtimeConnectionSecrets = redactRealtimeConnectionSecrets;
|
|
10
11
|
exports.addSocketListener = addSocketListener;
|
|
11
|
-
exports.addSocketOnceListener = addSocketOnceListener;
|
|
12
|
-
exports.readAndoRealtimeData = readAndoRealtimeData;
|
|
13
12
|
exports.parseAndoRealtimeEvent = parseAndoRealtimeEvent;
|
|
14
13
|
exports.sendJson = sendJson;
|
|
15
14
|
exports.closeSocket = closeSocket;
|
|
16
|
-
exports.acknowledgeEvent = acknowledgeEvent;
|
|
17
15
|
exports.openSocket = openSocket;
|
|
18
16
|
exports.waitForSocketClose = waitForSocketClose;
|
|
19
|
-
exports.listAllMemberships = listAllMemberships;
|
|
20
|
-
exports.updateConversationCache = updateConversationCache;
|
|
21
17
|
const SOCKET_CONNECTING = 0;
|
|
22
18
|
const SOCKET_OPEN = 1;
|
|
23
19
|
const SOCKET_CLOSING = 2;
|
|
@@ -27,7 +23,8 @@ function isNodeRuntime() {
|
|
|
27
23
|
if (typeof process === "undefined") {
|
|
28
24
|
return false;
|
|
29
25
|
}
|
|
30
|
-
|
|
26
|
+
const versions = process.versions;
|
|
27
|
+
return typeof versions?.node === "string";
|
|
31
28
|
}
|
|
32
29
|
function delay(ms, abortSignal) {
|
|
33
30
|
return new Promise((resolve) => {
|
|
@@ -71,24 +68,43 @@ function toUnixTimestamp(value) {
|
|
|
71
68
|
}
|
|
72
69
|
return value instanceof Date ? value.getTime() : Date.parse(value);
|
|
73
70
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
71
|
+
function stripTrailingSlashes(value) {
|
|
72
|
+
let end = value.length;
|
|
73
|
+
while (end > 0 && value[end - 1] === "/") {
|
|
74
|
+
end -= 1;
|
|
75
|
+
}
|
|
76
|
+
return value.slice(0, end);
|
|
81
77
|
}
|
|
82
|
-
function
|
|
83
|
-
const base =
|
|
84
|
-
|
|
78
|
+
function toWebSocketBase(value) {
|
|
79
|
+
const base = stripTrailingSlashes(value);
|
|
80
|
+
return base.startsWith("http://")
|
|
85
81
|
? `ws://${base.slice("http://".length)}`
|
|
86
82
|
: base.startsWith("https://")
|
|
87
83
|
? `wss://${base.slice("https://".length)}`
|
|
88
84
|
: base.startsWith("ws://") || base.startsWith("wss://")
|
|
89
85
|
? base
|
|
90
86
|
: `wss://${base}`;
|
|
91
|
-
|
|
87
|
+
}
|
|
88
|
+
function buildAndoRealtimeWebSocketUrl(params) {
|
|
89
|
+
return `${toWebSocketBase(params.realtimeHost)}/link`;
|
|
90
|
+
}
|
|
91
|
+
function buildAndoRealtimeWebSocketAuthProtocols() {
|
|
92
|
+
return ["ando.realtime.v1"];
|
|
93
|
+
}
|
|
94
|
+
function redactRealtimeConnectionSecrets(value) {
|
|
95
|
+
try {
|
|
96
|
+
const url = new URL(value);
|
|
97
|
+
if (url.searchParams.has("ticket")) {
|
|
98
|
+
url.searchParams.set("ticket", "[redacted]");
|
|
99
|
+
return url.toString();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Fall through to text redaction.
|
|
104
|
+
}
|
|
105
|
+
return value
|
|
106
|
+
.replace(/(\bticket=)[^&\s]+/gu, "$1[redacted]")
|
|
107
|
+
.replace(/\brtconn_v1_[A-Za-z0-9_.-]+/gu, "rtconn_v1_[redacted]");
|
|
92
108
|
}
|
|
93
109
|
function isNodeStyleSocket(socket) {
|
|
94
110
|
return typeof socket.on === "function" && typeof socket.off === "function";
|
|
@@ -160,7 +176,9 @@ function readAndoRealtimeData(raw) {
|
|
|
160
176
|
return TEXT_DECODER.decode(toUint8Array(raw));
|
|
161
177
|
}
|
|
162
178
|
if (Array.isArray(raw)) {
|
|
163
|
-
return TEXT_DECODER.decode(concatUint8Arrays(raw
|
|
179
|
+
return TEXT_DECODER.decode(concatUint8Arrays(raw
|
|
180
|
+
.filter((chunk) => chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk))
|
|
181
|
+
.map((chunk) => toUint8Array(chunk))));
|
|
164
182
|
}
|
|
165
183
|
throw new Error("[ando-sdk] unsupported websocket payload");
|
|
166
184
|
}
|
|
@@ -178,31 +196,22 @@ function parseAndoRealtimeEvent(raw) {
|
|
|
178
196
|
}
|
|
179
197
|
function sendJson(socket, payload) {
|
|
180
198
|
if (socket.readyState !== SOCKET_OPEN) {
|
|
181
|
-
return;
|
|
199
|
+
return false;
|
|
182
200
|
}
|
|
183
201
|
socket.send(JSON.stringify(payload));
|
|
202
|
+
return true;
|
|
184
203
|
}
|
|
185
204
|
function closeSocket(socket) {
|
|
186
|
-
if (socket.readyState === SOCKET_CONNECTING ||
|
|
187
|
-
socket.readyState === SOCKET_OPEN) {
|
|
205
|
+
if (socket.readyState === SOCKET_CONNECTING || socket.readyState === SOCKET_OPEN) {
|
|
188
206
|
socket.close();
|
|
189
207
|
}
|
|
190
208
|
}
|
|
191
|
-
function
|
|
192
|
-
if (!params.ackId) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
sendJson(params.socket, {
|
|
196
|
-
_clientAck: params.ackId,
|
|
197
|
-
_room: params.roomId,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
async function openSocket(url, abortSignal, setup) {
|
|
209
|
+
async function openSocket(url, abortSignal, setup, protocols) {
|
|
201
210
|
if (abortSignal?.aborted) {
|
|
202
211
|
throw new Error("aborted");
|
|
203
212
|
}
|
|
204
213
|
const WebSocketConstructor = await getWebSocketConstructor();
|
|
205
|
-
const socket = new WebSocketConstructor(url);
|
|
214
|
+
const socket = new WebSocketConstructor(url, protocols);
|
|
206
215
|
if ("binaryType" in socket) {
|
|
207
216
|
socket.binaryType = "arraybuffer";
|
|
208
217
|
}
|
|
@@ -221,9 +230,7 @@ async function openSocket(url, abortSignal, setup) {
|
|
|
221
230
|
};
|
|
222
231
|
const onError = (error) => {
|
|
223
232
|
cleanup();
|
|
224
|
-
reject(error instanceof Error
|
|
225
|
-
? error
|
|
226
|
-
: new Error("[ando-sdk] websocket error"));
|
|
233
|
+
reject(error instanceof Error ? error : new Error("[ando-sdk] websocket error"));
|
|
227
234
|
};
|
|
228
235
|
const onUnexpectedResponse = (...args) => {
|
|
229
236
|
const response = args[1];
|
|
@@ -260,8 +267,7 @@ async function openSocket(url, abortSignal, setup) {
|
|
|
260
267
|
return socket;
|
|
261
268
|
}
|
|
262
269
|
async function waitForSocketClose(socket, abortSignal) {
|
|
263
|
-
if (socket.readyState === SOCKET_CLOSING ||
|
|
264
|
-
socket.readyState === SOCKET_CLOSED) {
|
|
270
|
+
if (socket.readyState === SOCKET_CLOSING || socket.readyState === SOCKET_CLOSED) {
|
|
265
271
|
return;
|
|
266
272
|
}
|
|
267
273
|
if (abortSignal?.aborted) {
|
|
@@ -283,8 +289,7 @@ async function waitForSocketClose(socket, abortSignal) {
|
|
|
283
289
|
abortSignal?.removeEventListener("abort", onAbort);
|
|
284
290
|
};
|
|
285
291
|
const removeClose = addSocketOnceListener(socket, "close", onClose);
|
|
286
|
-
if (socket.readyState === SOCKET_CLOSING ||
|
|
287
|
-
socket.readyState === SOCKET_CLOSED) {
|
|
292
|
+
if (socket.readyState === SOCKET_CLOSING || socket.readyState === SOCKET_CLOSED) {
|
|
288
293
|
cleanup();
|
|
289
294
|
resolve();
|
|
290
295
|
return;
|
|
@@ -296,28 +301,6 @@ async function waitForSocketClose(socket, abortSignal) {
|
|
|
296
301
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
297
302
|
});
|
|
298
303
|
}
|
|
299
|
-
async function listAllMemberships(api, signal) {
|
|
300
|
-
const memberships = [];
|
|
301
|
-
let cursor;
|
|
302
|
-
do {
|
|
303
|
-
const response = await api.getMyMemberships({
|
|
304
|
-
limit: 200,
|
|
305
|
-
cursor,
|
|
306
|
-
signal,
|
|
307
|
-
});
|
|
308
|
-
memberships.push(...(response.items ?? []));
|
|
309
|
-
cursor = response.pageInfo?.hasNextPage
|
|
310
|
-
? response.pageInfo?.nextCursor
|
|
311
|
-
: undefined;
|
|
312
|
-
} while (cursor);
|
|
313
|
-
return memberships;
|
|
314
|
-
}
|
|
315
|
-
function updateConversationCache(conversations, memberships) {
|
|
316
|
-
conversations.clear();
|
|
317
|
-
for (const membership of memberships) {
|
|
318
|
-
conversations.set(membership.conversation.id, membership.conversation);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
304
|
let wsConstructorPromise = null;
|
|
322
305
|
async function getWebSocketConstructor() {
|
|
323
306
|
if (!isNodeRuntime() && typeof globalThis.WebSocket === "function") {
|