@andocorp/sdk 0.1.0 → 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/README.md +26 -4
- 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 +131 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +523 -57
- package/dist/client.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 +23 -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 -160
- package/dist/realtime-events.js.map +1 -1
- package/dist/realtime-runtime.d.ts +5 -17
- package/dist/realtime-runtime.d.ts.map +1 -1
- package/dist/realtime-runtime.js +41 -67
- package/dist/realtime-runtime.js.map +1 -1
- package/dist/realtime-types.d.ts +58 -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 +281 -145
- 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 -23
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -6
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,129 +135,67 @@ function buildNormalizedMessageContext(context) {
|
|
|
120
135
|
threadHistoryBody: context.thread_history_body ?? undefined,
|
|
121
136
|
};
|
|
122
137
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const mentionsMe = messageMentionsAndoAgent({
|
|
128
|
-
text: params.event.message.markdown_content,
|
|
129
|
-
memberGroupIds: [
|
|
130
|
-
params.selfMember.member_group_id,
|
|
131
|
-
conversation?.everyone_member_group_id,
|
|
132
|
-
],
|
|
133
|
-
});
|
|
134
|
-
return {
|
|
135
|
-
conversation,
|
|
136
|
-
isDirectMessage,
|
|
137
|
-
skip: params.event.message.type === ANDO_CONVERSATION_MESSAGE_TYPE_SYSTEM ||
|
|
138
|
-
params.event.message.author_id === params.selfMember.id ||
|
|
139
|
-
(delivery === "mentions" && !mentionsMe),
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function handleControlEvent({ socket, roomId, conversations, event, }) {
|
|
143
|
-
if (event.eventId === "heartbeat/ping") {
|
|
144
|
-
(0, realtime_runtime_1.sendJson)(socket, { eventId: "heartbeat/pong" });
|
|
145
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
146
|
-
socket,
|
|
147
|
-
roomId,
|
|
148
|
-
ackId: event._clientAckId,
|
|
149
|
-
});
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
if (isMembershipNewEvent(event)) {
|
|
153
|
-
conversations.set(event.membership.conversation.id, event.membership.conversation);
|
|
154
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
155
|
-
socket,
|
|
156
|
-
roomId,
|
|
157
|
-
ackId: event._clientAckId,
|
|
158
|
-
});
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
if (!isMessageNewEvent(event)) {
|
|
162
|
-
(0, realtime_runtime_1.acknowledgeEvent)({
|
|
163
|
-
socket,
|
|
164
|
-
roomId,
|
|
165
|
-
ackId: event._clientAckId,
|
|
166
|
-
});
|
|
138
|
+
function isNonRetryableContextError(error) {
|
|
139
|
+
if (error instanceof Error &&
|
|
140
|
+
error.message.includes("/conversation-messages/") &&
|
|
141
|
+
error.message.includes("returned null")) {
|
|
167
142
|
return true;
|
|
168
143
|
}
|
|
169
|
-
return
|
|
144
|
+
return (error instanceof Error &&
|
|
145
|
+
"status" in error &&
|
|
146
|
+
error.status != null &&
|
|
147
|
+
[404, 410, 422].includes(Number(error.status)));
|
|
170
148
|
}
|
|
171
|
-
async function
|
|
172
|
-
|
|
173
|
-
api,
|
|
174
|
-
|
|
175
|
-
conversations,
|
|
176
|
-
seenMessages,
|
|
177
|
-
selfMember,
|
|
178
|
-
delivery: options.delivery,
|
|
179
|
-
signal: options.signal,
|
|
180
|
-
});
|
|
181
|
-
if (preparedMessage.markSeen) {
|
|
182
|
-
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;
|
|
183
153
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
roomId,
|
|
187
|
-
ackId: event._clientAckId,
|
|
188
|
-
});
|
|
189
|
-
if (preparedMessage.kind !== "deliver") {
|
|
190
|
-
return;
|
|
154
|
+
catch {
|
|
155
|
+
return undefined;
|
|
191
156
|
}
|
|
192
|
-
await options.onMessage?.(preparedMessage.messageEvent);
|
|
193
157
|
}
|
|
194
|
-
async function prepareAndoRealtimeIncomingEvent({ api,
|
|
195
|
-
if (
|
|
196
|
-
return {
|
|
197
|
-
kind: "drop",
|
|
198
|
-
markSeen: false,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
if (!conversations.has(event.message.conversation_id)) {
|
|
202
|
-
const memberships = await (0, realtime_runtime_1.listAllMemberships)(api, signal);
|
|
203
|
-
(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 };
|
|
204
161
|
}
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
selfMember,
|
|
209
|
-
delivery,
|
|
210
|
-
});
|
|
211
|
-
if (messageEvaluation.skip) {
|
|
212
|
-
return {
|
|
213
|
-
kind: "drop",
|
|
214
|
-
markSeen: false,
|
|
215
|
-
};
|
|
162
|
+
const message = toRealtimeMessage(frame.payload);
|
|
163
|
+
if (seenMessages.has(message.id)) {
|
|
164
|
+
return { kind: "drop", cursor: frame.cursor };
|
|
216
165
|
}
|
|
217
|
-
let
|
|
166
|
+
let context;
|
|
218
167
|
try {
|
|
219
|
-
|
|
168
|
+
context = buildNormalizedMessageContext(await api.getMessageContext(message.id, signal, {
|
|
169
|
+
threadRootId: message.thread_root_id,
|
|
170
|
+
}), message);
|
|
220
171
|
}
|
|
221
172
|
catch (error) {
|
|
222
|
-
if (isNonRetryableContextError(error)) {
|
|
223
|
-
|
|
224
|
-
kind: "drop",
|
|
225
|
-
markSeen: true,
|
|
226
|
-
};
|
|
173
|
+
if (!isNonRetryableContextError(error)) {
|
|
174
|
+
throw error;
|
|
227
175
|
}
|
|
228
|
-
|
|
176
|
+
context = null;
|
|
229
177
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return {
|
|
233
|
-
kind: "drop",
|
|
234
|
-
markSeen: false,
|
|
235
|
-
};
|
|
178
|
+
if (!context?.currentText && !messageText(message)) {
|
|
179
|
+
return { kind: "drop", cursor: frame.cursor };
|
|
236
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
|
+
};
|
|
237
195
|
return {
|
|
238
196
|
kind: "deliver",
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
message: event.message,
|
|
242
|
-
conversation: messageEvaluation.conversation,
|
|
243
|
-
isDirectMessage: messageEvaluation.isDirectMessage,
|
|
244
|
-
context,
|
|
245
|
-
},
|
|
197
|
+
cursor: frame.cursor,
|
|
198
|
+
event,
|
|
246
199
|
};
|
|
247
200
|
}
|
|
248
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,CAAC,OAAO,EAAE,IAAI,EAAE,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AChD,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,30 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AndoRawRealtimeEvent, AndoRealtimeApi, AndoSocket, AndoWebSocketProtocols, 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;
|
|
14
|
-
export declare function buildAndoRealtimeWebSocketAuthProtocols(
|
|
10
|
+
export declare function buildAndoRealtimeWebSocketAuthProtocols(): string[];
|
|
11
|
+
export declare function redactRealtimeConnectionSecrets(value: string): string;
|
|
15
12
|
export declare function addSocketListener(socket: AndoSocket, event: string, listener: SocketListener): () => void;
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function parseAndoRealtimeEvent(raw: unknown): AndoRawRealtimeEvent | null;
|
|
19
|
-
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;
|
|
20
15
|
export declare function closeSocket(socket: AndoSocket): void;
|
|
21
|
-
export declare function acknowledgeEvent(params: {
|
|
22
|
-
socket: AndoSocket;
|
|
23
|
-
roomId: string;
|
|
24
|
-
ackId?: string;
|
|
25
|
-
}): void;
|
|
26
16
|
export declare function openSocket(url: string, abortSignal?: AbortSignal, setup?: (socket: AndoSocket) => void, protocols?: AndoWebSocketProtocols): Promise<AndoSocket>;
|
|
27
17
|
export declare function waitForSocketClose(socket: AndoSocket, abortSignal?: AbortSignal): Promise<void>;
|
|
28
|
-
export declare function listAllMemberships(api: Pick<AndoRealtimeApi, "getMyMemberships">, signal?: AbortSignal): Promise<AndoMembership[]>;
|
|
29
|
-
export declare function updateConversationCache(conversations: Map<string, AndoMembership["conversation"]>, memberships: AndoMembership[]): void;
|
|
30
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":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"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,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,32 +5,26 @@ 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;
|
|
10
9
|
exports.buildAndoRealtimeWebSocketAuthProtocols = buildAndoRealtimeWebSocketAuthProtocols;
|
|
10
|
+
exports.redactRealtimeConnectionSecrets = redactRealtimeConnectionSecrets;
|
|
11
11
|
exports.addSocketListener = addSocketListener;
|
|
12
|
-
exports.addSocketOnceListener = addSocketOnceListener;
|
|
13
|
-
exports.readAndoRealtimeData = readAndoRealtimeData;
|
|
14
12
|
exports.parseAndoRealtimeEvent = parseAndoRealtimeEvent;
|
|
15
13
|
exports.sendJson = sendJson;
|
|
16
14
|
exports.closeSocket = closeSocket;
|
|
17
|
-
exports.acknowledgeEvent = acknowledgeEvent;
|
|
18
15
|
exports.openSocket = openSocket;
|
|
19
16
|
exports.waitForSocketClose = waitForSocketClose;
|
|
20
|
-
exports.listAllMemberships = listAllMemberships;
|
|
21
|
-
exports.updateConversationCache = updateConversationCache;
|
|
22
17
|
const SOCKET_CONNECTING = 0;
|
|
23
18
|
const SOCKET_OPEN = 1;
|
|
24
19
|
const SOCKET_CLOSING = 2;
|
|
25
20
|
const SOCKET_CLOSED = 3;
|
|
26
21
|
const TEXT_DECODER = new TextDecoder();
|
|
27
|
-
const ANDO_REALTIME_WEBSOCKET_PROTOCOL = "ando.sokachu.v1";
|
|
28
|
-
const ANDO_REALTIME_WEBSOCKET_TOKEN_PROTOCOL_PREFIX = "ando.sokachu.token.";
|
|
29
22
|
function isNodeRuntime() {
|
|
30
23
|
if (typeof process === "undefined") {
|
|
31
24
|
return false;
|
|
32
25
|
}
|
|
33
|
-
|
|
26
|
+
const versions = process.versions;
|
|
27
|
+
return typeof versions?.node === "string";
|
|
34
28
|
}
|
|
35
29
|
function delay(ms, abortSignal) {
|
|
36
30
|
return new Promise((resolve) => {
|
|
@@ -74,30 +68,43 @@ function toUnixTimestamp(value) {
|
|
|
74
68
|
}
|
|
75
69
|
return value instanceof Date ? value.getTime() : Date.parse(value);
|
|
76
70
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
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);
|
|
84
77
|
}
|
|
85
|
-
function
|
|
86
|
-
const base =
|
|
87
|
-
|
|
78
|
+
function toWebSocketBase(value) {
|
|
79
|
+
const base = stripTrailingSlashes(value);
|
|
80
|
+
return base.startsWith("http://")
|
|
88
81
|
? `ws://${base.slice("http://".length)}`
|
|
89
82
|
: base.startsWith("https://")
|
|
90
83
|
? `wss://${base.slice("https://".length)}`
|
|
91
84
|
: base.startsWith("ws://") || base.startsWith("wss://")
|
|
92
85
|
? base
|
|
93
86
|
: `wss://${base}`;
|
|
94
|
-
return `${wsBase}/parties/main/${params.roomId}`;
|
|
95
87
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
];
|
|
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]");
|
|
101
108
|
}
|
|
102
109
|
function isNodeStyleSocket(socket) {
|
|
103
110
|
return typeof socket.on === "function" && typeof socket.off === "function";
|
|
@@ -169,7 +176,9 @@ function readAndoRealtimeData(raw) {
|
|
|
169
176
|
return TEXT_DECODER.decode(toUint8Array(raw));
|
|
170
177
|
}
|
|
171
178
|
if (Array.isArray(raw)) {
|
|
172
|
-
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))));
|
|
173
182
|
}
|
|
174
183
|
throw new Error("[ando-sdk] unsupported websocket payload");
|
|
175
184
|
}
|
|
@@ -187,25 +196,16 @@ function parseAndoRealtimeEvent(raw) {
|
|
|
187
196
|
}
|
|
188
197
|
function sendJson(socket, payload) {
|
|
189
198
|
if (socket.readyState !== SOCKET_OPEN) {
|
|
190
|
-
return;
|
|
199
|
+
return false;
|
|
191
200
|
}
|
|
192
201
|
socket.send(JSON.stringify(payload));
|
|
202
|
+
return true;
|
|
193
203
|
}
|
|
194
204
|
function closeSocket(socket) {
|
|
195
|
-
if (socket.readyState === SOCKET_CONNECTING ||
|
|
196
|
-
socket.readyState === SOCKET_OPEN) {
|
|
205
|
+
if (socket.readyState === SOCKET_CONNECTING || socket.readyState === SOCKET_OPEN) {
|
|
197
206
|
socket.close();
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
|
-
function acknowledgeEvent(params) {
|
|
201
|
-
if (!params.ackId) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
sendJson(params.socket, {
|
|
205
|
-
_clientAck: params.ackId,
|
|
206
|
-
_room: params.roomId,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
209
|
async function openSocket(url, abortSignal, setup, protocols) {
|
|
210
210
|
if (abortSignal?.aborted) {
|
|
211
211
|
throw new Error("aborted");
|
|
@@ -230,9 +230,7 @@ async function openSocket(url, abortSignal, setup, protocols) {
|
|
|
230
230
|
};
|
|
231
231
|
const onError = (error) => {
|
|
232
232
|
cleanup();
|
|
233
|
-
reject(error instanceof Error
|
|
234
|
-
? error
|
|
235
|
-
: new Error("[ando-sdk] websocket error"));
|
|
233
|
+
reject(error instanceof Error ? error : new Error("[ando-sdk] websocket error"));
|
|
236
234
|
};
|
|
237
235
|
const onUnexpectedResponse = (...args) => {
|
|
238
236
|
const response = args[1];
|
|
@@ -269,8 +267,7 @@ async function openSocket(url, abortSignal, setup, protocols) {
|
|
|
269
267
|
return socket;
|
|
270
268
|
}
|
|
271
269
|
async function waitForSocketClose(socket, abortSignal) {
|
|
272
|
-
if (socket.readyState === SOCKET_CLOSING ||
|
|
273
|
-
socket.readyState === SOCKET_CLOSED) {
|
|
270
|
+
if (socket.readyState === SOCKET_CLOSING || socket.readyState === SOCKET_CLOSED) {
|
|
274
271
|
return;
|
|
275
272
|
}
|
|
276
273
|
if (abortSignal?.aborted) {
|
|
@@ -292,8 +289,7 @@ async function waitForSocketClose(socket, abortSignal) {
|
|
|
292
289
|
abortSignal?.removeEventListener("abort", onAbort);
|
|
293
290
|
};
|
|
294
291
|
const removeClose = addSocketOnceListener(socket, "close", onClose);
|
|
295
|
-
if (socket.readyState === SOCKET_CLOSING ||
|
|
296
|
-
socket.readyState === SOCKET_CLOSED) {
|
|
292
|
+
if (socket.readyState === SOCKET_CLOSING || socket.readyState === SOCKET_CLOSED) {
|
|
297
293
|
cleanup();
|
|
298
294
|
resolve();
|
|
299
295
|
return;
|
|
@@ -305,28 +301,6 @@ async function waitForSocketClose(socket, abortSignal) {
|
|
|
305
301
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
306
302
|
});
|
|
307
303
|
}
|
|
308
|
-
async function listAllMemberships(api, signal) {
|
|
309
|
-
const memberships = [];
|
|
310
|
-
let cursor;
|
|
311
|
-
do {
|
|
312
|
-
const response = await api.getMyMemberships({
|
|
313
|
-
limit: 200,
|
|
314
|
-
cursor,
|
|
315
|
-
signal,
|
|
316
|
-
});
|
|
317
|
-
memberships.push(...(response.items ?? []));
|
|
318
|
-
cursor = response.pageInfo?.hasNextPage
|
|
319
|
-
? response.pageInfo?.nextCursor
|
|
320
|
-
: undefined;
|
|
321
|
-
} while (cursor);
|
|
322
|
-
return memberships;
|
|
323
|
-
}
|
|
324
|
-
function updateConversationCache(conversations, memberships) {
|
|
325
|
-
conversations.clear();
|
|
326
|
-
for (const membership of memberships) {
|
|
327
|
-
conversations.set(membership.conversation.id, membership.conversation);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
304
|
let wsConstructorPromise = null;
|
|
331
305
|
async function getWebSocketConstructor() {
|
|
332
306
|
if (!isNodeRuntime() && typeof globalThis.WebSocket === "function") {
|