@holo-js/broadcast 0.2.6 → 0.3.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/auth.d.ts +3 -1
- package/dist/auth.mjs +3 -2
- package/dist/{chunk-TTKGDABI.mjs → chunk-6DCCSFFM.mjs} +97 -4
- package/dist/{chunk-U5JDBKXC.mjs → chunk-JVDFH2TW.mjs} +3 -3
- package/dist/chunk-XLUGF257.mjs +268 -0
- package/dist/client-config.d.ts +3 -3
- package/dist/config.d.ts +138 -0
- package/dist/config.mjs +34 -0
- package/dist/contracts.d.ts +1 -1
- package/dist/index.d.ts +88 -24
- package/dist/index.mjs +328 -227
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.mjs +2 -1
- package/package.json +10 -3
package/dist/contracts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizedHoloBroadcastConfig } from '
|
|
1
|
+
import { NormalizedHoloBroadcastConfig } from './config.js';
|
|
2
2
|
import { ValidationSchema, InferSchemaData } from '@holo-js/validation';
|
|
3
3
|
|
|
4
4
|
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,37 @@ import { authorizeBroadcastChannel, parseBroadcastAuthEndpointPayload, renderBro
|
|
|
4
4
|
export { broadcastAuthInternals } from './auth.js';
|
|
5
5
|
import { renderBroadcastClientConfigResponse, resolveBroadcastClientConfig } from './client-config.js';
|
|
6
6
|
export { BroadcastClientConfig } from './client-config.js';
|
|
7
|
-
import { NormalizedHoloBroadcastConfig
|
|
8
|
-
export { HoloBroadcastConfig,
|
|
7
|
+
import { NormalizedHoloBroadcastConfig } from './config.js';
|
|
8
|
+
export { HoloBroadcastConfig, defineBroadcastConfig, holoBroadcastDefaults, normalizeBroadcastConfig } from './config.js';
|
|
9
|
+
import { NormalizedHoloRedisConfig } from '@holo-js/kernel';
|
|
10
|
+
import { NormalizedHoloQueueConfig } from '@holo-js/queue';
|
|
11
|
+
import { ServerResponse } from 'node:http';
|
|
9
12
|
import { broadcast, broadcastRaw, configureBroadcastRuntime, getBroadcastRuntime, getBroadcastRuntimeBindings, resetBroadcastRuntime } from './runtime.js';
|
|
10
13
|
export { broadcastRuntimeInternals } from './runtime.js';
|
|
11
14
|
import '@holo-js/validation';
|
|
12
15
|
|
|
16
|
+
type WorkerPublishBody = {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly channels: readonly string[];
|
|
19
|
+
readonly data: string;
|
|
20
|
+
readonly socket_id?: string;
|
|
21
|
+
};
|
|
22
|
+
declare function parseWorkerSocketMessage(rawMessage: string): {
|
|
23
|
+
readonly event: string;
|
|
24
|
+
readonly channel?: string;
|
|
25
|
+
readonly data: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
declare function normalizeWorkerPublishBody(value: unknown): WorkerPublishBody;
|
|
28
|
+
declare function createWorkerPusherSignature(secret: string, method: string, pathname: string, params: URLSearchParams): string;
|
|
29
|
+
declare function verifyWorkerPusherSignature(providedSignature: string, expectedSignature: string): boolean;
|
|
30
|
+
declare function parseWorkerChannelKind(channel: string): {
|
|
31
|
+
readonly kind: 'public' | 'private' | 'presence';
|
|
32
|
+
readonly canonical: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
declare function readLimitedRequestText(request: Request, maxBytes: number): Promise<string>;
|
|
36
|
+
declare function writeNodeRequestBodyError(response: ServerResponse, error: unknown): void;
|
|
37
|
+
|
|
13
38
|
type WorkerConnectionInfo = {
|
|
14
39
|
readonly socketId: string;
|
|
15
40
|
readonly app: BroadcastWorkerApp;
|
|
@@ -19,12 +44,6 @@ type WorkerWebSocketConnection = WorkerConnectionInfo & {
|
|
|
19
44
|
readonly send: (payload: string) => void;
|
|
20
45
|
readonly close: (code?: number, reason?: string) => void;
|
|
21
46
|
};
|
|
22
|
-
type PublishBody = {
|
|
23
|
-
readonly name: string;
|
|
24
|
-
readonly channels: readonly string[];
|
|
25
|
-
readonly data: string;
|
|
26
|
-
readonly socket_id?: string;
|
|
27
|
-
};
|
|
28
47
|
type BroadcastWorkerApp = {
|
|
29
48
|
readonly connection: string;
|
|
30
49
|
readonly appId: string;
|
|
@@ -33,6 +52,10 @@ type BroadcastWorkerApp = {
|
|
|
33
52
|
readonly authEndpoint?: string;
|
|
34
53
|
};
|
|
35
54
|
type PresenceMember = Readonly<Record<string, unknown>>;
|
|
55
|
+
type ClientChannelAuth = {
|
|
56
|
+
readonly auth: string;
|
|
57
|
+
readonly channelData?: string;
|
|
58
|
+
};
|
|
36
59
|
type WorkerRuntimeOptions = {
|
|
37
60
|
readonly config: NormalizedHoloBroadcastConfig;
|
|
38
61
|
readonly channelAuth?: BroadcastChannelAuthRuntimeBindings;
|
|
@@ -75,6 +98,15 @@ interface StartedBroadcastWorker {
|
|
|
75
98
|
readonly port: number;
|
|
76
99
|
readonly stop: () => Promise<void>;
|
|
77
100
|
}
|
|
101
|
+
declare function isAllowedWorkerOrigin(request: Request, allowedOrigins: readonly string[]): boolean;
|
|
102
|
+
type RealtimeSocketAction = 'query' | 'mutation' | 'subscribe' | 'unsubscribe';
|
|
103
|
+
type RealtimeSocketMessage = {
|
|
104
|
+
readonly id: string;
|
|
105
|
+
readonly action: RealtimeSocketAction;
|
|
106
|
+
readonly name?: string;
|
|
107
|
+
readonly args: Record<string, unknown>;
|
|
108
|
+
};
|
|
109
|
+
type RealtimeWireErrorKind = 'authorization' | 'transport' | 'runtime';
|
|
78
110
|
type BroadcastRedisScalingConnection = {
|
|
79
111
|
readonly url?: string;
|
|
80
112
|
readonly clusters?: readonly {
|
|
@@ -103,27 +135,37 @@ type BroadcastWorkerScalingRuntime = {
|
|
|
103
135
|
readonly eventChannel: string;
|
|
104
136
|
readonly adapter: BroadcastScalingAdapter;
|
|
105
137
|
};
|
|
106
|
-
declare function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
138
|
+
declare function normalizeRealtimeAction(value: unknown): RealtimeSocketAction;
|
|
139
|
+
declare function normalizeRealtimeArgs(value: unknown): Record<string, unknown>;
|
|
140
|
+
declare function parseRealtimeSocketMessage(data: Record<string, unknown>): RealtimeSocketMessage;
|
|
141
|
+
declare function logSocketMessageError(socketId: string, error: unknown): void;
|
|
142
|
+
declare function logScalingMessageError(error: unknown): void;
|
|
143
|
+
declare function logSocketCleanupError(socketId: string, channel: string, error: unknown): void;
|
|
144
|
+
declare function logRealtimeSubscriptionCleanupError(socketId: string, subscriptionId: string, error: unknown): void;
|
|
145
|
+
declare function safeEqual(left: string, right: string): boolean;
|
|
146
|
+
declare function signChannelAuth(secret: string, socketId: string, channel: string, channelData: string): string;
|
|
147
|
+
declare function parseClientChannelAuth(data: Record<string, unknown>): ClientChannelAuth | undefined;
|
|
148
|
+
declare function parseSignedChannelData(value: string | undefined): {
|
|
149
|
+
readonly whispers: readonly string[];
|
|
150
|
+
readonly member?: PresenceMember;
|
|
110
151
|
};
|
|
111
|
-
declare function
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
declare function parseChannelKind(channel: string): {
|
|
115
|
-
readonly kind: 'public' | 'private' | 'presence';
|
|
116
|
-
readonly canonical: string;
|
|
152
|
+
declare function verifyClientChannelAuth(app: BroadcastWorkerApp, socketId: string, channel: string, clientAuth: ClientChannelAuth): {
|
|
153
|
+
readonly whispers: readonly string[];
|
|
154
|
+
readonly member?: PresenceMember;
|
|
117
155
|
};
|
|
118
156
|
declare function createSocketId(): string;
|
|
119
157
|
declare function createScalingNodeId(): string;
|
|
120
158
|
declare function resolveScalingEventChannel(connection: string): string;
|
|
159
|
+
declare function resolvePresenceMemberId(member: PresenceMember, fallback: string): string;
|
|
121
160
|
declare function parsePresenceHashMembers(values: Readonly<Record<string, string>>): Map<string, PresenceMember>;
|
|
122
161
|
declare function resolveRedisScalingConnection(queueConfig: NormalizedHoloQueueConfig | undefined, connectionName: string, redisConfig?: NormalizedHoloRedisConfig): BroadcastRedisScalingConnection;
|
|
123
162
|
declare function createRedisScalingAdapter(connection: BroadcastRedisScalingConnection, dependencies?: {
|
|
124
163
|
readonly loadRedisModule?: () => Promise<unknown>;
|
|
125
164
|
}): Promise<BroadcastScalingAdapter>;
|
|
126
165
|
declare function buildWorkerApps(config: NormalizedHoloBroadcastConfig): Readonly<Record<string, BroadcastWorkerApp>>;
|
|
166
|
+
declare function resolveRealtimeErrorStatus(error: unknown): number | undefined;
|
|
167
|
+
declare function resolveRealtimeErrorCode(error: unknown): string | undefined;
|
|
168
|
+
declare function resolveRealtimeErrorKind(error: unknown, status: number | undefined): RealtimeWireErrorKind;
|
|
127
169
|
declare function createBroadcastWorkerRuntime(options: WorkerRuntimeOptions): BroadcastWorkerRuntime;
|
|
128
170
|
declare function startBroadcastWorker(runtimeBindings: Pick<BroadcastRuntimeBindings, 'config' | 'channelAuth'> & {
|
|
129
171
|
readonly realtime?: BroadcastRealtimeRuntimeBindings;
|
|
@@ -139,17 +181,39 @@ declare const workerInternals: {
|
|
|
139
181
|
buildWorkerApps: typeof buildWorkerApps;
|
|
140
182
|
createScalingNodeId: typeof createScalingNodeId;
|
|
141
183
|
createRedisScalingAdapter: typeof createRedisScalingAdapter;
|
|
142
|
-
createPusherSignature: typeof
|
|
143
|
-
verifyPusherSignature: typeof
|
|
184
|
+
createPusherSignature: typeof createWorkerPusherSignature;
|
|
185
|
+
verifyPusherSignature: typeof verifyWorkerPusherSignature;
|
|
144
186
|
createSocketId: typeof createSocketId;
|
|
145
187
|
resolveRedisScalingConnection: typeof resolveRedisScalingConnection;
|
|
146
188
|
resolveScalingEventChannel: typeof resolveScalingEventChannel;
|
|
147
|
-
normalizePublishBody: typeof
|
|
148
|
-
parseChannelKind: typeof
|
|
189
|
+
normalizePublishBody: typeof normalizeWorkerPublishBody;
|
|
190
|
+
parseChannelKind: typeof parseWorkerChannelKind;
|
|
149
191
|
parsePresenceHashMembers: typeof parsePresenceHashMembers;
|
|
150
|
-
parseSocketMessage: typeof
|
|
192
|
+
parseSocketMessage: typeof parseWorkerSocketMessage;
|
|
193
|
+
isAllowedWorkerOrigin: typeof isAllowedWorkerOrigin;
|
|
194
|
+
readLimitedRequestText: typeof readLimitedRequestText;
|
|
195
|
+
normalizeRealtimeAction: typeof normalizeRealtimeAction;
|
|
196
|
+
normalizeRealtimeArgs: typeof normalizeRealtimeArgs;
|
|
197
|
+
parseRealtimeSocketMessage: typeof parseRealtimeSocketMessage;
|
|
198
|
+
logSocketMessageError: typeof logSocketMessageError;
|
|
199
|
+
logScalingMessageError: typeof logScalingMessageError;
|
|
200
|
+
logSocketCleanupError: typeof logSocketCleanupError;
|
|
201
|
+
logRealtimeSubscriptionCleanupError: typeof logRealtimeSubscriptionCleanupError;
|
|
202
|
+
safeEqual: typeof safeEqual;
|
|
203
|
+
signChannelAuth: typeof signChannelAuth;
|
|
204
|
+
parseClientChannelAuth: typeof parseClientChannelAuth;
|
|
205
|
+
parseSignedChannelData: typeof parseSignedChannelData;
|
|
206
|
+
verifyClientChannelAuth: typeof verifyClientChannelAuth;
|
|
207
|
+
resolvePresenceMemberId: typeof resolvePresenceMemberId;
|
|
208
|
+
resolveRealtimeErrorStatus: typeof resolveRealtimeErrorStatus;
|
|
209
|
+
resolveRealtimeErrorCode: typeof resolveRealtimeErrorCode;
|
|
210
|
+
resolveRealtimeErrorKind: typeof resolveRealtimeErrorKind;
|
|
211
|
+
writeNodeRequestBodyError: typeof writeNodeRequestBodyError;
|
|
151
212
|
};
|
|
152
213
|
|
|
214
|
+
declare function loadBroadcastPluginDrivers(projectRoot?: string, pluginNames?: readonly string[]): Promise<void>;
|
|
215
|
+
declare function resetBroadcastPluginDrivers(): void;
|
|
216
|
+
|
|
153
217
|
declare function normalizeDriverName(name: string): string;
|
|
154
218
|
declare function registerBroadcastDriver(name: string, driver: BroadcastDriver, options?: RegisterBroadcastDriverOptions): RegisteredBroadcastDriver;
|
|
155
219
|
declare function getRegisteredBroadcastDriver(name: string): BroadcastDriver | undefined;
|
|
@@ -183,4 +247,4 @@ declare const broadcastPackage: Readonly<{
|
|
|
183
247
|
createBroadcastWorkerRuntime: typeof createBroadcastWorkerRuntime;
|
|
184
248
|
}>;
|
|
185
249
|
|
|
186
|
-
export { BroadcastChannelAuthRuntimeBindings, BroadcastDriver, BroadcastRealtimeRuntimeBindings, BroadcastRuntimeBindings, type BroadcastWorkerRuntime, type BroadcastWorkerStats, RegisterBroadcastDriverOptions, RegisteredBroadcastDriver, type StartedBroadcastWorker, authorizeBroadcastChannel, broadcast, broadcastRaw, broadcastRegistryInternals, channel, configureBroadcastRuntime, createBroadcastWorkerRuntime, broadcastPackage as default, defineBroadcast, defineChannel, getBroadcastRuntime, getBroadcastRuntimeBindings, getRegisteredBroadcastDriver, listRegisteredBroadcastDrivers, parseBroadcastAuthEndpointPayload, presenceChannel, privateChannel, registerBroadcastDriver, renderBroadcastAuthResponse, renderBroadcastClientConfigResponse, resetBroadcastDriverRegistry, resetBroadcastRuntime, resolveBroadcastChannelGuard, resolveBroadcastClientConfig, resolveBroadcastWhisperSchema, startBroadcastWorker, validateBroadcastWhisperPayload, workerInternals };
|
|
250
|
+
export { BroadcastChannelAuthRuntimeBindings, BroadcastDriver, BroadcastRealtimeRuntimeBindings, BroadcastRuntimeBindings, type BroadcastWorkerRuntime, type BroadcastWorkerStats, NormalizedHoloBroadcastConfig, RegisterBroadcastDriverOptions, RegisteredBroadcastDriver, type StartedBroadcastWorker, authorizeBroadcastChannel, broadcast, broadcastRaw, broadcastRegistryInternals, channel, configureBroadcastRuntime, createBroadcastWorkerRuntime, broadcastPackage as default, defineBroadcast, defineChannel, getBroadcastRuntime, getBroadcastRuntimeBindings, getRegisteredBroadcastDriver, listRegisteredBroadcastDrivers, loadBroadcastPluginDrivers, parseBroadcastAuthEndpointPayload, presenceChannel, privateChannel, registerBroadcastDriver, renderBroadcastAuthResponse, renderBroadcastClientConfigResponse, resetBroadcastDriverRegistry, resetBroadcastPluginDrivers, resetBroadcastRuntime, resolveBroadcastChannelGuard, resolveBroadcastClientConfig, resolveBroadcastWhisperSchema, startBroadcastWorker, validateBroadcastWhisperPayload, workerInternals };
|