@signalapp/libsignal-client 0.52.4 → 0.54.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/dist/net.d.ts CHANGED
@@ -81,108 +81,93 @@ export interface ChatServiceListener {
81
81
  }
82
82
  /**
83
83
  * Provides API methods to connect and communicate with the Chat Service.
84
- * Before using either authenticated or unauthenticated channels,
85
- * a corresponding `connect*` method must be called.
84
+ * Before sending/receiving requests, a {@link #connect()} method must be called.
86
85
  * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
87
86
  */
88
- export declare class ChatService {
89
- private readonly asyncContext;
90
- readonly chatService: Wrapper<Native.Chat>;
91
- constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager);
92
- /**
93
- * Sets the listener for server push messages on the authenticated connection.
94
- *
95
- * Note that this creates a **non-garbage-collectable** reference to `listener`. If `listener`
96
- * contains a reference to this ChatService (directly or indirectly), both objects will be kept
97
- * alive even with no other references. This may be fine if `listener` is a long-lived object
98
- * anyway, but if not, make sure to eventually break the cycle, possibly by calling
99
- * {@link #clearListener}.
100
- */
101
- setListener(listener: ChatServiceListener): void;
102
- clearListener(): void;
103
- /**
104
- * Initiates termination of the underlying connection to the Chat Service. After the service is
105
- * disconnected, it will not attempt to automatically reconnect until you call
106
- * {@link #connectAuthenticated()} and/or {@link #connectUnauthenticated()}.
107
- *
108
- * Note: the same instance of `ChatService` can be reused after `disconnect()` was
109
- * called.
110
- */
111
- disconnect(): Promise<void>;
87
+ export type ChatService = {
112
88
  /**
113
- * Initiates establishing of the underlying unauthenticated connection to the Chat Service. Once
114
- * the service is connected, all the requests will be using the established connection. Also, if
115
- * the connection is lost for any reason other than the call to {@link #disconnect()}, an
116
- * automatic reconnect attempt will be made.
117
- *
118
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
119
- * @throws {LibSignalError} with other codes for other failures.
120
- */
121
- connectUnauthenticated(options?: {
122
- abortSignal?: AbortSignal;
123
- }): Promise<Native.ChatServiceDebugInfo>;
124
- /**
125
- * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
89
+ * Initiates establishing of the underlying connection to the Chat Service. Once the
126
90
  * service is connected, all the requests will be using the established connection. Also, if the
127
91
  * connection is lost for any reason other than the call to {@link #disconnect()}, an automatic
128
92
  * reconnect attempt will be made.
129
93
  *
130
94
  * Calling this method will result in starting to accept incoming requests from the Chat Service.
131
- * You should set a listener first using {@link #setListener()}.
132
95
  *
133
96
  * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
134
97
  * @throws {DeviceDelinkedError} if the current device has been delinked.
135
98
  * @throws {LibSignalError} with other codes for other failures.
136
99
  */
137
- connectAuthenticated(options?: {
100
+ connect(options?: {
138
101
  abortSignal?: AbortSignal;
139
102
  }): Promise<Native.ChatServiceDebugInfo>;
140
103
  /**
141
- * Sends request to the Chat Service over an unauthenticated channel.
104
+ * Initiates termination of the underlying connection to the Chat Service. After the service is
105
+ * disconnected, it will not attempt to automatically reconnect until you call
106
+ * {@link #connect()}.
107
+ *
108
+ * Note: the same instance of `ChatService` can be reused after {@link #disconnect()} was
109
+ * called.
110
+ */
111
+ disconnect(): Promise<void>;
112
+ /**
113
+ * Sends request to the Chat Service.
142
114
  *
143
115
  * In addition to the response, an object containing debug information about the request flow is
144
116
  * returned.
145
117
  *
146
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
118
+ * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
147
119
  * rejection of the promise).
148
120
  */
149
- unauthenticatedFetchAndDebug(chatRequest: ChatRequest, options?: {
121
+ fetchAndDebug(chatRequest: ChatRequest, options?: {
150
122
  abortSignal?: AbortSignal;
151
123
  }): Promise<Native.ResponseAndDebugInfo>;
152
124
  /**
153
- * Sends request to the Chat Service over an unauthenticated channel.
125
+ * Sends request to the Chat Service.
154
126
  *
155
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
127
+ * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
156
128
  * rejection of the promise).
157
129
  */
158
- unauthenticatedFetch(chatRequest: ChatRequest, options?: {
130
+ fetch(chatRequest: ChatRequest, options?: {
159
131
  abortSignal?: AbortSignal;
160
132
  }): Promise<Native.ChatResponse>;
161
- /**
162
- * Sends request to the Chat Service over an authenticated channel.
163
- *
164
- * In addition to the response, an object containing debug information about the request flow is
165
- * returned.
166
- *
167
- * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
168
- * rejection of the promise).
169
- */
170
- authenticatedFetchAndDebug(chatRequest: ChatRequest, options?: {
133
+ };
134
+ /**
135
+ * Provides API methods to connect and communicate with the Chat Service over an authenticated channel.
136
+ */
137
+ export declare class AuthenticatedChatService implements ChatService {
138
+ private readonly asyncContext;
139
+ readonly chatService: Wrapper<Native.Chat>;
140
+ constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager, username: string, password: string, receiveStories: boolean, listener: ChatServiceListener);
141
+ disconnect(): Promise<void>;
142
+ connect(options?: {
143
+ abortSignal?: AbortSignal;
144
+ }): Promise<Native.ChatServiceDebugInfo>;
145
+ fetchAndDebug(chatRequest: ChatRequest, options?: {
171
146
  abortSignal?: AbortSignal;
172
147
  }): Promise<Native.ResponseAndDebugInfo>;
173
- /**
174
- * Sends request to the Chat Service over an authenticated channel.
175
- *
176
- * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
177
- * rejection of the promise).
178
- */
179
- authenticatedFetch(chatRequest: ChatRequest, options?: {
148
+ fetch(chatRequest: ChatRequest, options?: {
180
149
  abortSignal?: AbortSignal;
181
150
  }): Promise<Native.ChatResponse>;
182
- static buildHttpRequest(chatRequest: ChatRequest): {
183
- _nativeHandle: Native.HttpRequest;
184
- };
185
151
  }
152
+ /**
153
+ * Provides API methods to connect and communicate with the Chat Service over an unauthenticated channel.
154
+ */
155
+ export declare class UnauthenticatedChatService implements ChatService {
156
+ private readonly asyncContext;
157
+ readonly chatService: Wrapper<Native.Chat>;
158
+ constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager);
159
+ disconnect(): Promise<void>;
160
+ connect(options?: {
161
+ abortSignal?: AbortSignal;
162
+ }): Promise<Native.ChatServiceDebugInfo>;
163
+ fetchAndDebug(chatRequest: ChatRequest, options?: {
164
+ abortSignal?: AbortSignal;
165
+ }): Promise<Native.ResponseAndDebugInfo>;
166
+ fetch(chatRequest: ChatRequest, options?: {
167
+ abortSignal?: AbortSignal;
168
+ }): Promise<Native.ChatResponse>;
169
+ }
170
+ export declare function buildHttpRequest(chatRequest: ChatRequest): Wrapper<Native.HttpRequest>;
186
171
  export declare class Net {
187
172
  private readonly asyncContext;
188
173
  private readonly connectionManager;
@@ -192,9 +177,18 @@ export declare class Net {
192
177
  svr3: Svr3Client;
193
178
  constructor(env: Environment, userAgent: string);
194
179
  /**
195
- * Creates a new instance of {@link ChatService}.
180
+ * Creates a new instance of {@link AuthenticatedChatService}.
181
+ *
182
+ * Note that created `AuthenticatedChatService` will hold a **non-garbage-collectable** reference to `listener`.
183
+ * If `listener` contains a strong reference to this ChatService (directly or indirectly), both objects will be kept
184
+ * alive even with no other references. If such reference cycle is created, it's the responsibility of the caller
185
+ * to eventually break it (either using a weak reference or by assigning over the strong reference).
186
+ */
187
+ newAuthenticatedChatService(username: string, password: string, receiveStories: boolean, listener: ChatServiceListener): AuthenticatedChatService;
188
+ /**
189
+ * Creates a new instance of {@link UnauthenticatedChatService}.
196
190
  */
197
- newChatService(): ChatService;
191
+ newUnauthenticatedChatService(): UnauthenticatedChatService;
198
192
  /**
199
193
  * Enables/disables IPv6 for all new connections (until changed).
200
194
  *
package/dist/net.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.RestoredSecret = exports.Net = exports.ChatService = exports.ChatServerMessageAck = exports.TokioAsyncContext = exports.newNativeHandle = exports.Environment = void 0;
7
+ exports.RestoredSecret = exports.Net = exports.buildHttpRequest = exports.UnauthenticatedChatService = exports.AuthenticatedChatService = exports.ChatServerMessageAck = exports.TokioAsyncContext = exports.newNativeHandle = exports.Environment = void 0;
8
8
  const Native = require("../Native");
9
9
  const Address_1 = require("./Address");
10
10
  const node_buffer_1 = require("node:buffer");
@@ -60,27 +60,12 @@ class ChatServerMessageAck {
60
60
  }
61
61
  exports.ChatServerMessageAck = ChatServerMessageAck;
62
62
  /**
63
- * Provides API methods to connect and communicate with the Chat Service.
64
- * Before using either authenticated or unauthenticated channels,
65
- * a corresponding `connect*` method must be called.
66
- * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
63
+ * Provides API methods to connect and communicate with the Chat Service over an authenticated channel.
67
64
  */
68
- class ChatService {
69
- constructor(asyncContext, connectionManager) {
65
+ class AuthenticatedChatService {
66
+ constructor(asyncContext, connectionManager, username, password, receiveStories, listener) {
70
67
  this.asyncContext = asyncContext;
71
- this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, '', ''));
72
- }
73
- /**
74
- * Sets the listener for server push messages on the authenticated connection.
75
- *
76
- * Note that this creates a **non-garbage-collectable** reference to `listener`. If `listener`
77
- * contains a reference to this ChatService (directly or indirectly), both objects will be kept
78
- * alive even with no other references. This may be fine if `listener` is a long-lived object
79
- * anyway, but if not, make sure to eventually break the cycle, possibly by calling
80
- * {@link #clearListener}.
81
- */
82
- setListener(listener) {
83
- const asyncContext = this.asyncContext;
68
+ this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, username, password, receiveStories));
84
69
  const nativeChatListener = {
85
70
  _incoming_message(envelope, timestamp, ack) {
86
71
  listener.onIncomingMessage(envelope, timestamp, new ChatServerMessageAck(asyncContext, ack));
@@ -94,104 +79,55 @@ class ChatService {
94
79
  };
95
80
  Native.ChatServer_SetListener(asyncContext, this.chatService, nativeChatListener);
96
81
  }
97
- clearListener() {
98
- Native.ChatServer_SetListener(this.asyncContext, this.chatService, null);
99
- }
100
- /**
101
- * Initiates termination of the underlying connection to the Chat Service. After the service is
102
- * disconnected, it will not attempt to automatically reconnect until you call
103
- * {@link #connectAuthenticated()} and/or {@link #connectUnauthenticated()}.
104
- *
105
- * Note: the same instance of `ChatService` can be reused after `disconnect()` was
106
- * called.
107
- */
108
82
  disconnect() {
109
83
  return Native.ChatService_disconnect(this.asyncContext, this.chatService);
110
84
  }
111
- /**
112
- * Initiates establishing of the underlying unauthenticated connection to the Chat Service. Once
113
- * the service is connected, all the requests will be using the established connection. Also, if
114
- * the connection is lost for any reason other than the call to {@link #disconnect()}, an
115
- * automatic reconnect attempt will be made.
116
- *
117
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
118
- * @throws {LibSignalError} with other codes for other failures.
119
- */
120
- connectUnauthenticated(options) {
121
- return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_unauth(this.asyncContext, this.chatService));
122
- }
123
- /**
124
- * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
125
- * service is connected, all the requests will be using the established connection. Also, if the
126
- * connection is lost for any reason other than the call to {@link #disconnect()}, an automatic
127
- * reconnect attempt will be made.
128
- *
129
- * Calling this method will result in starting to accept incoming requests from the Chat Service.
130
- * You should set a listener first using {@link #setListener()}.
131
- *
132
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
133
- * @throws {DeviceDelinkedError} if the current device has been delinked.
134
- * @throws {LibSignalError} with other codes for other failures.
135
- */
136
- connectAuthenticated(options) {
85
+ connect(options) {
137
86
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_auth(this.asyncContext, this.chatService));
138
87
  }
139
- /**
140
- * Sends request to the Chat Service over an unauthenticated channel.
141
- *
142
- * In addition to the response, an object containing debug information about the request flow is
143
- * returned.
144
- *
145
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
146
- * rejection of the promise).
147
- */
148
- unauthenticatedFetchAndDebug(chatRequest, options) {
149
- return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
88
+ fetchAndDebug(chatRequest, options) {
89
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
150
90
  }
151
- /**
152
- * Sends request to the Chat Service over an unauthenticated channel.
153
- *
154
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
155
- * rejection of the promise).
156
- */
157
- unauthenticatedFetch(chatRequest, options) {
158
- return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
91
+ fetch(chatRequest, options) {
92
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
159
93
  }
160
- /**
161
- * Sends request to the Chat Service over an authenticated channel.
162
- *
163
- * In addition to the response, an object containing debug information about the request flow is
164
- * returned.
165
- *
166
- * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
167
- * rejection of the promise).
168
- */
169
- authenticatedFetchAndDebug(chatRequest, options) {
170
- return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
94
+ }
95
+ exports.AuthenticatedChatService = AuthenticatedChatService;
96
+ /**
97
+ * Provides API methods to connect and communicate with the Chat Service over an unauthenticated channel.
98
+ */
99
+ class UnauthenticatedChatService {
100
+ constructor(asyncContext, connectionManager) {
101
+ this.asyncContext = asyncContext;
102
+ this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, '', '', false));
171
103
  }
172
- /**
173
- * Sends request to the Chat Service over an authenticated channel.
174
- *
175
- * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
176
- * rejection of the promise).
177
- */
178
- authenticatedFetch(chatRequest, options) {
179
- return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
104
+ disconnect() {
105
+ return Native.ChatService_disconnect(this.asyncContext, this.chatService);
180
106
  }
181
- static buildHttpRequest(chatRequest) {
182
- const { verb, path, body, headers } = chatRequest;
183
- const bodyBuffer = body !== undefined ? node_buffer_1.Buffer.from(body) : null;
184
- const httpRequest = {
185
- _nativeHandle: Native.HttpRequest_new(verb, path, bodyBuffer),
186
- };
187
- headers.forEach((header) => {
188
- const [name, value] = header;
189
- Native.HttpRequest_add_header(httpRequest, name, value);
190
- });
191
- return httpRequest;
107
+ connect(options) {
108
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_unauth(this.asyncContext, this.chatService));
109
+ }
110
+ fetchAndDebug(chatRequest, options) {
111
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
112
+ }
113
+ fetch(chatRequest, options) {
114
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
192
115
  }
193
116
  }
194
- exports.ChatService = ChatService;
117
+ exports.UnauthenticatedChatService = UnauthenticatedChatService;
118
+ function buildHttpRequest(chatRequest) {
119
+ const { verb, path, body, headers } = chatRequest;
120
+ const bodyBuffer = body !== undefined ? node_buffer_1.Buffer.from(body) : null;
121
+ const httpRequest = {
122
+ _nativeHandle: Native.HttpRequest_new(verb, path, bodyBuffer),
123
+ };
124
+ headers.forEach((header) => {
125
+ const [name, value] = header;
126
+ Native.HttpRequest_add_header(httpRequest, name, value);
127
+ });
128
+ return httpRequest;
129
+ }
130
+ exports.buildHttpRequest = buildHttpRequest;
195
131
  class Net {
196
132
  constructor(env, userAgent) {
197
133
  this.asyncContext = new TokioAsyncContext(Native.TokioAsyncContext_new());
@@ -199,10 +135,21 @@ class Net {
199
135
  this.svr3 = new Svr3ClientImpl(this.asyncContext, this.connectionManager);
200
136
  }
201
137
  /**
202
- * Creates a new instance of {@link ChatService}.
138
+ * Creates a new instance of {@link AuthenticatedChatService}.
139
+ *
140
+ * Note that created `AuthenticatedChatService` will hold a **non-garbage-collectable** reference to `listener`.
141
+ * If `listener` contains a strong reference to this ChatService (directly or indirectly), both objects will be kept
142
+ * alive even with no other references. If such reference cycle is created, it's the responsibility of the caller
143
+ * to eventually break it (either using a weak reference or by assigning over the strong reference).
144
+ */
145
+ newAuthenticatedChatService(username, password, receiveStories, listener) {
146
+ return new AuthenticatedChatService(this.asyncContext, this.connectionManager, username, password, receiveStories, listener);
147
+ }
148
+ /**
149
+ * Creates a new instance of {@link UnauthenticatedChatService}.
203
150
  */
204
- newChatService() {
205
- return new ChatService(this.asyncContext, this.connectionManager);
151
+ newUnauthenticatedChatService() {
152
+ return new UnauthenticatedChatService(this.asyncContext, this.connectionManager);
206
153
  }
207
154
  /**
208
155
  * Enables/disables IPv6 for all new connections (until changed).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.52.4",
3
+ "version": "0.54.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",