@emmanuel-nike/ark-notify-js 0.1.1 → 0.1.2
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 +46 -6
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +0 -27
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -10
- package/dist/react/index.d.ts +4 -10
- package/dist/react/index.js +1 -27
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +128 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +31 -0
- package/dist/server/index.d.ts +31 -0
- package/dist/server/index.js +121 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-tQECeZab.d.cts +257 -0
- package/dist/types-tQECeZab.d.ts +257 -0
- package/dist/utils-BATAvEjJ.d.cts +146 -0
- package/dist/utils-DnRGShUO.d.ts +146 -0
- package/package.json +12 -1
- package/dist/utils-Zj1Ees3H.d.cts +0 -409
- package/dist/utils-Zj1Ees3H.d.ts +0 -409
package/dist/utils-Zj1Ees3H.d.ts
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
declare const DEFAULT_BASE_URL = "https://ark-notify-933303906015.europe-north1.run.app";
|
|
2
|
-
interface ArkNotifyGlobalConfig {
|
|
3
|
-
baseUrl?: string;
|
|
4
|
-
}
|
|
5
|
-
/** Set the default base URL once at application startup. */
|
|
6
|
-
declare function configureArkNotify(config: ArkNotifyGlobalConfig): void;
|
|
7
|
-
declare function resolveBaseUrl(baseUrl?: string): string;
|
|
8
|
-
|
|
9
|
-
type UserRole = 'SYSTEM_ADMIN' | 'ACCOUNT_ADMIN' | 'ACCOUNT_USER';
|
|
10
|
-
interface User {
|
|
11
|
-
id: string;
|
|
12
|
-
email: string;
|
|
13
|
-
firstName: string;
|
|
14
|
-
lastName: string;
|
|
15
|
-
role: UserRole;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
}
|
|
18
|
-
interface ApiError {
|
|
19
|
-
error: string;
|
|
20
|
-
message: string;
|
|
21
|
-
reason?: string;
|
|
22
|
-
retryAfterSec?: number;
|
|
23
|
-
}
|
|
24
|
-
interface ConnectionCapabilities {
|
|
25
|
-
subscribe: boolean;
|
|
26
|
-
publish: boolean;
|
|
27
|
-
presence: boolean;
|
|
28
|
-
}
|
|
29
|
-
interface Application {
|
|
30
|
-
id: string;
|
|
31
|
-
name: string;
|
|
32
|
-
appKey: string;
|
|
33
|
-
tenantId: string;
|
|
34
|
-
authWebhookUrl: string | null;
|
|
35
|
-
requireClientAuth: boolean;
|
|
36
|
-
serverAuthUrl: string | null;
|
|
37
|
-
messageHistorySize: number;
|
|
38
|
-
createdAt: string;
|
|
39
|
-
updatedAt: string;
|
|
40
|
-
secret?: string;
|
|
41
|
-
}
|
|
42
|
-
interface CreateApplicationInput {
|
|
43
|
-
name: string;
|
|
44
|
-
authWebhookUrl?: string | null;
|
|
45
|
-
requireClientAuth?: boolean;
|
|
46
|
-
serverAuthUrl?: string | null;
|
|
47
|
-
messageHistorySize?: number;
|
|
48
|
-
}
|
|
49
|
-
interface UpdateApplicationInput {
|
|
50
|
-
name?: string;
|
|
51
|
-
authWebhookUrl?: string | null;
|
|
52
|
-
requireClientAuth?: boolean;
|
|
53
|
-
serverAuthUrl?: string | null;
|
|
54
|
-
messageHistorySize?: number;
|
|
55
|
-
}
|
|
56
|
-
interface LoginInput {
|
|
57
|
-
email: string;
|
|
58
|
-
password: string;
|
|
59
|
-
}
|
|
60
|
-
interface AuthResponse {
|
|
61
|
-
user: User;
|
|
62
|
-
token: string;
|
|
63
|
-
}
|
|
64
|
-
interface PublishEventInput {
|
|
65
|
-
channel: string;
|
|
66
|
-
event: string;
|
|
67
|
-
data?: unknown;
|
|
68
|
-
}
|
|
69
|
-
interface PublishEventResponse {
|
|
70
|
-
published: boolean;
|
|
71
|
-
channel: string;
|
|
72
|
-
event: string;
|
|
73
|
-
}
|
|
74
|
-
interface ChannelAuthInput {
|
|
75
|
-
socket_id?: string;
|
|
76
|
-
connection_id?: string;
|
|
77
|
-
channel_name: string;
|
|
78
|
-
user_data?: Record<string, unknown>;
|
|
79
|
-
}
|
|
80
|
-
interface ChannelAuthResponse {
|
|
81
|
-
auth: string;
|
|
82
|
-
}
|
|
83
|
-
interface ConnectionTokenInput {
|
|
84
|
-
client_id?: string;
|
|
85
|
-
clientId?: string;
|
|
86
|
-
user_data?: Record<string, unknown>;
|
|
87
|
-
userData?: Record<string, unknown>;
|
|
88
|
-
serverAuthUrl?: string | null;
|
|
89
|
-
server_auth_url?: string | null;
|
|
90
|
-
ttl?: number;
|
|
91
|
-
capabilities?: Partial<ConnectionCapabilities>;
|
|
92
|
-
}
|
|
93
|
-
interface ConnectionTokenResponse {
|
|
94
|
-
token: string;
|
|
95
|
-
client_id: string;
|
|
96
|
-
expires_at: number;
|
|
97
|
-
capabilities: ConnectionCapabilities;
|
|
98
|
-
}
|
|
99
|
-
interface PresenceMember {
|
|
100
|
-
connectionId: string;
|
|
101
|
-
clientId: string;
|
|
102
|
-
data: Record<string, unknown>;
|
|
103
|
-
updatedAt: number;
|
|
104
|
-
}
|
|
105
|
-
interface AdminConnection {
|
|
106
|
-
connectionId: string;
|
|
107
|
-
clientId: string;
|
|
108
|
-
transport: 'websocket' | 'sse';
|
|
109
|
-
authenticated: boolean;
|
|
110
|
-
connectedAt: number;
|
|
111
|
-
}
|
|
112
|
-
interface AdminChannel {
|
|
113
|
-
tenantId: string;
|
|
114
|
-
channel: string;
|
|
115
|
-
applicationId: string;
|
|
116
|
-
applicationName: string;
|
|
117
|
-
appKey: string;
|
|
118
|
-
subscriberCount: number;
|
|
119
|
-
presenceMemberCount: number;
|
|
120
|
-
presenceMembers: PresenceMember[];
|
|
121
|
-
connections: AdminConnection[];
|
|
122
|
-
analytics: {
|
|
123
|
-
eventsByType: Record<string, number>;
|
|
124
|
-
totalEvents: number;
|
|
125
|
-
lastEventAt: string | null;
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
interface AdminChannelsResponse {
|
|
129
|
-
generatedAt: string;
|
|
130
|
-
summary: {
|
|
131
|
-
totalApplications: number;
|
|
132
|
-
totalChannels: number;
|
|
133
|
-
totalConnections: number;
|
|
134
|
-
totalPresenceMembers: number;
|
|
135
|
-
totalSubscribers: number;
|
|
136
|
-
totalAnalyticsEvents: number;
|
|
137
|
-
};
|
|
138
|
-
channels: AdminChannel[];
|
|
139
|
-
connections: AdminConnection[];
|
|
140
|
-
analytics: {
|
|
141
|
-
eventsByType: Array<{
|
|
142
|
-
eventType: string;
|
|
143
|
-
eventCount: number;
|
|
144
|
-
}>;
|
|
145
|
-
recentEvents: unknown[];
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
|
|
149
|
-
interface ConnectedMessage {
|
|
150
|
-
type: 'connected';
|
|
151
|
-
connection_id: string;
|
|
152
|
-
client_id: string;
|
|
153
|
-
app_key: string;
|
|
154
|
-
authenticated: boolean;
|
|
155
|
-
channels?: string[];
|
|
156
|
-
}
|
|
157
|
-
interface EventMessage {
|
|
158
|
-
type: 'event';
|
|
159
|
-
channel: string;
|
|
160
|
-
event: string;
|
|
161
|
-
data: unknown;
|
|
162
|
-
clientId: string | null;
|
|
163
|
-
timestamp: number;
|
|
164
|
-
}
|
|
165
|
-
interface PresenceMemberInfo {
|
|
166
|
-
connectionId: string;
|
|
167
|
-
clientId: string;
|
|
168
|
-
data: Record<string, unknown>;
|
|
169
|
-
updatedAt: number;
|
|
170
|
-
}
|
|
171
|
-
type PresenceAction = 'enter' | 'leave' | 'update' | 'sync';
|
|
172
|
-
interface PresenceMessage {
|
|
173
|
-
type: 'presence';
|
|
174
|
-
channel: string;
|
|
175
|
-
action: PresenceAction;
|
|
176
|
-
member: PresenceMemberInfo | null;
|
|
177
|
-
members: PresenceMemberInfo[] | null;
|
|
178
|
-
timestamp: number;
|
|
179
|
-
}
|
|
180
|
-
interface SubscribedMessage {
|
|
181
|
-
type: 'subscribed';
|
|
182
|
-
channel: string;
|
|
183
|
-
}
|
|
184
|
-
interface UnsubscribedMessage {
|
|
185
|
-
type: 'unsubscribed';
|
|
186
|
-
channel: string;
|
|
187
|
-
}
|
|
188
|
-
interface PublishedMessage {
|
|
189
|
-
type: 'published';
|
|
190
|
-
channel: string;
|
|
191
|
-
event: string;
|
|
192
|
-
}
|
|
193
|
-
interface PongMessage {
|
|
194
|
-
type: 'pong';
|
|
195
|
-
timestamp: number;
|
|
196
|
-
}
|
|
197
|
-
interface PingMessage {
|
|
198
|
-
type: 'ping';
|
|
199
|
-
}
|
|
200
|
-
interface ServerErrorMessage {
|
|
201
|
-
type: 'error';
|
|
202
|
-
code: string;
|
|
203
|
-
message: string;
|
|
204
|
-
}
|
|
205
|
-
interface PresenceUpdatedMessage {
|
|
206
|
-
type: 'presence_updated';
|
|
207
|
-
channel: string;
|
|
208
|
-
data: Record<string, unknown>;
|
|
209
|
-
}
|
|
210
|
-
interface PresenceLeftMessage {
|
|
211
|
-
type: 'presence_left';
|
|
212
|
-
channel: string;
|
|
213
|
-
}
|
|
214
|
-
type ServerMessage = ConnectedMessage | EventMessage | PresenceMessage | SubscribedMessage | UnsubscribedMessage | PublishedMessage | PongMessage | PingMessage | ServerErrorMessage | PresenceUpdatedMessage | PresenceLeftMessage;
|
|
215
|
-
interface ArkNotifyClientConfig {
|
|
216
|
-
baseUrl?: string;
|
|
217
|
-
token?: string | (() => string | null | undefined);
|
|
218
|
-
fetch?: typeof fetch;
|
|
219
|
-
}
|
|
220
|
-
interface AppCredentials {
|
|
221
|
-
appKey: string;
|
|
222
|
-
secret: string;
|
|
223
|
-
}
|
|
224
|
-
type PrivateChannelAuthHandler = (channel: string, connectionId: string) => Promise<string>;
|
|
225
|
-
interface ArkNotifyConnectionConfig {
|
|
226
|
-
baseUrl?: string;
|
|
227
|
-
appKey: string;
|
|
228
|
-
clientId?: string;
|
|
229
|
-
/** Signed connection token, or a resolver. Omit to auto-fetch when `clientId` is set. */
|
|
230
|
-
token?: string | (() => string | null | undefined);
|
|
231
|
-
/** App credentials for auto-fetching a connection token (backend-only when no serverAuthUrl). */
|
|
232
|
-
credentials?: AppCredentials;
|
|
233
|
-
/** Override server auth URL when auto-fetching a token; uses the application default when omitted. */
|
|
234
|
-
serverAuthUrl?: string | null;
|
|
235
|
-
/** Forwarded to the connection-token endpoint when auto-fetching a token. */
|
|
236
|
-
user_data?: Record<string, unknown>;
|
|
237
|
-
autoReconnect?: boolean;
|
|
238
|
-
reconnectDelayMs?: number;
|
|
239
|
-
maxReconnectDelayMs?: number;
|
|
240
|
-
onPrivateChannelAuth?: PrivateChannelAuthHandler;
|
|
241
|
-
fetch?: typeof fetch;
|
|
242
|
-
WebSocket?: typeof WebSocket;
|
|
243
|
-
}
|
|
244
|
-
interface SubscribeOptions {
|
|
245
|
-
history?: boolean;
|
|
246
|
-
presence?: boolean;
|
|
247
|
-
presence_data?: Record<string, unknown>;
|
|
248
|
-
auth?: string;
|
|
249
|
-
}
|
|
250
|
-
interface ArkNotifySSEConfig {
|
|
251
|
-
baseUrl?: string;
|
|
252
|
-
appKey: string;
|
|
253
|
-
channels: string[];
|
|
254
|
-
clientId?: string;
|
|
255
|
-
token?: string | (() => string | null | undefined);
|
|
256
|
-
auth?: Record<string, string>;
|
|
257
|
-
user_data?: Record<string, unknown>;
|
|
258
|
-
history?: boolean;
|
|
259
|
-
onPrivateChannelAuth?: PrivateChannelAuthHandler;
|
|
260
|
-
EventSource?: typeof EventSource;
|
|
261
|
-
}
|
|
262
|
-
interface ChannelEventHandler<T = unknown> {
|
|
263
|
-
(data: T, message: EventMessage): void;
|
|
264
|
-
}
|
|
265
|
-
interface ChannelHandlers {
|
|
266
|
-
[eventName: string]: ChannelEventHandler;
|
|
267
|
-
}
|
|
268
|
-
interface HealthResponse {
|
|
269
|
-
status: string;
|
|
270
|
-
uptime: number;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
declare class ArkNotifyClient {
|
|
274
|
-
private readonly baseUrl;
|
|
275
|
-
private readonly fetchFn;
|
|
276
|
-
private token?;
|
|
277
|
-
constructor(config: ArkNotifyClientConfig);
|
|
278
|
-
setToken(token: string | null): void;
|
|
279
|
-
private getAuthHeader;
|
|
280
|
-
private request;
|
|
281
|
-
health(): Promise<HealthResponse>;
|
|
282
|
-
login(input: LoginInput): Promise<AuthResponse>;
|
|
283
|
-
me(): Promise<{
|
|
284
|
-
user: User;
|
|
285
|
-
}>;
|
|
286
|
-
listApplications(): Promise<{
|
|
287
|
-
apps: Application[];
|
|
288
|
-
}>;
|
|
289
|
-
createApplication(input: CreateApplicationInput): Promise<{
|
|
290
|
-
app: Application;
|
|
291
|
-
}>;
|
|
292
|
-
getApplication(id: string): Promise<{
|
|
293
|
-
app: Application;
|
|
294
|
-
}>;
|
|
295
|
-
updateApplication(id: string, input: UpdateApplicationInput): Promise<{
|
|
296
|
-
app: Application;
|
|
297
|
-
}>;
|
|
298
|
-
deleteApplication(id: string): Promise<{
|
|
299
|
-
deleted: boolean;
|
|
300
|
-
id: string;
|
|
301
|
-
}>;
|
|
302
|
-
regenerateSecret(id: string): Promise<{
|
|
303
|
-
app: Application;
|
|
304
|
-
}>;
|
|
305
|
-
adminChannels(): Promise<AdminChannelsResponse>;
|
|
306
|
-
publishEvent(appKey: string, credentials: AppCredentials, input: PublishEventInput): Promise<PublishEventResponse>;
|
|
307
|
-
authorizeChannel(appKey: string, credentials: AppCredentials, input: ChannelAuthInput): Promise<ChannelAuthResponse>;
|
|
308
|
-
issueConnectionToken(appKey: string, input: ConnectionTokenInput, credentials?: AppCredentials): Promise<ConnectionTokenResponse>;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
type EventMap = {
|
|
312
|
-
state: (state: ConnectionState) => void;
|
|
313
|
-
connected: (message: ConnectedMessage) => void;
|
|
314
|
-
event: (message: EventMessage) => void;
|
|
315
|
-
presence: (message: PresenceMessage) => void;
|
|
316
|
-
message: (message: ServerMessage) => void;
|
|
317
|
-
error: (error: {
|
|
318
|
-
code: string;
|
|
319
|
-
message: string;
|
|
320
|
-
}) => void;
|
|
321
|
-
close: (event: {
|
|
322
|
-
code: number;
|
|
323
|
-
reason: string;
|
|
324
|
-
}) => void;
|
|
325
|
-
};
|
|
326
|
-
type EventName = keyof EventMap;
|
|
327
|
-
declare class ArkNotifyConnection {
|
|
328
|
-
private readonly config;
|
|
329
|
-
private ws;
|
|
330
|
-
private state;
|
|
331
|
-
private connectionId;
|
|
332
|
-
private clientId;
|
|
333
|
-
private authenticated;
|
|
334
|
-
private subscribedChannels;
|
|
335
|
-
private pendingSubscriptions;
|
|
336
|
-
private listeners;
|
|
337
|
-
private reconnectAttempt;
|
|
338
|
-
private reconnectTimer;
|
|
339
|
-
private intentionalClose;
|
|
340
|
-
private connectPromise;
|
|
341
|
-
private readonly WebSocketCtor;
|
|
342
|
-
constructor(config: ArkNotifyConnectionConfig);
|
|
343
|
-
getConnectionState(): ConnectionState;
|
|
344
|
-
getConnectionId(): string | null;
|
|
345
|
-
getClientId(): string | null;
|
|
346
|
-
isAuthenticated(): boolean;
|
|
347
|
-
getSubscribedChannels(): string[];
|
|
348
|
-
on<E extends EventName>(event: E, handler: EventMap[E]): () => void;
|
|
349
|
-
off<E extends EventName>(event: E, handler: EventMap[E]): void;
|
|
350
|
-
private emit;
|
|
351
|
-
private setState;
|
|
352
|
-
connect(): Promise<void>;
|
|
353
|
-
private doConnect;
|
|
354
|
-
disconnect(): void;
|
|
355
|
-
private scheduleReconnect;
|
|
356
|
-
private clearReconnectTimer;
|
|
357
|
-
private send;
|
|
358
|
-
private handleMessage;
|
|
359
|
-
private resubscribeAll;
|
|
360
|
-
subscribe(channel: string, options?: SubscribeOptions): Promise<void>;
|
|
361
|
-
unsubscribe(channel: string): void;
|
|
362
|
-
publish(channel: string, event: string, data?: unknown): void;
|
|
363
|
-
presenceEnter(channel: string, data: Record<string, unknown>): void;
|
|
364
|
-
presenceUpdate(channel: string, data: Record<string, unknown>): void;
|
|
365
|
-
presenceLeave(channel: string): void;
|
|
366
|
-
presenceSync(channel: string): void;
|
|
367
|
-
ping(): void;
|
|
368
|
-
bind(channel: string, event: string, handler: ChannelEventHandler): () => void;
|
|
369
|
-
bindAll(channel: string, handler: ChannelEventHandler): () => void;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
type SSEEventMap = {
|
|
373
|
-
connected: (message: ConnectedMessage) => void;
|
|
374
|
-
event: (message: EventMessage) => void;
|
|
375
|
-
presence: (message: PresenceMessage) => void;
|
|
376
|
-
message: (message: ServerMessage) => void;
|
|
377
|
-
error: (error: Error) => void;
|
|
378
|
-
close: () => void;
|
|
379
|
-
};
|
|
380
|
-
type SSEEventName = keyof SSEEventMap;
|
|
381
|
-
declare class ArkNotifySSE {
|
|
382
|
-
private readonly config;
|
|
383
|
-
private es;
|
|
384
|
-
private connectionId;
|
|
385
|
-
private listeners;
|
|
386
|
-
private readonly EventSourceCtor;
|
|
387
|
-
constructor(config: ArkNotifySSEConfig);
|
|
388
|
-
getConnectionId(): string | null;
|
|
389
|
-
on<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): () => void;
|
|
390
|
-
off<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): void;
|
|
391
|
-
private emit;
|
|
392
|
-
connect(): Promise<void>;
|
|
393
|
-
disconnect(): void;
|
|
394
|
-
bind(channel: string, event: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
395
|
-
bindAll(channel: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
declare class ArkNotifyError extends Error {
|
|
399
|
-
readonly status: number;
|
|
400
|
-
readonly code: string;
|
|
401
|
-
readonly retryAfterSec?: number;
|
|
402
|
-
readonly reason?: string;
|
|
403
|
-
constructor(status: number, body: ApiError);
|
|
404
|
-
}
|
|
405
|
-
declare function toWebSocketUrl(baseUrl: string, path: string): string;
|
|
406
|
-
declare function resolveValue<T>(value: T | (() => T)): T;
|
|
407
|
-
declare function isPrivateChannel(channel: string): boolean;
|
|
408
|
-
|
|
409
|
-
export { toWebSocketUrl as $, type AppCredentials as A, type PresenceMember as B, type ConnectionTokenInput as C, DEFAULT_BASE_URL as D, type EventMessage as E, type PresenceMemberInfo as F, type PresenceMessage as G, type HealthResponse as H, type PresenceUpdatedMessage as I, type PrivateChannelAuthHandler as J, type PublishEventInput as K, type LoginInput as L, type PublishEventResponse as M, type PublishedMessage as N, type ServerMessage as O, type PingMessage as P, type SubscribeOptions as Q, type SubscribedMessage as R, type ServerErrorMessage as S, type UpdateApplicationInput as T, type UnsubscribedMessage as U, type User as V, type UserRole as W, configureArkNotify as X, isPrivateChannel as Y, resolveBaseUrl as Z, resolveValue as _, type ConnectionTokenResponse as a, type AdminChannel as b, type AdminChannelsResponse as c, type AdminConnection as d, type ApiError as e, type Application as f, ArkNotifyClient as g, type ArkNotifyClientConfig as h, ArkNotifyConnection as i, type ArkNotifyConnectionConfig as j, ArkNotifyError as k, type ArkNotifyGlobalConfig as l, ArkNotifySSE as m, type ArkNotifySSEConfig as n, type AuthResponse as o, type ChannelAuthInput as p, type ChannelAuthResponse as q, type ChannelEventHandler as r, type ChannelHandlers as s, type ConnectedMessage as t, type ConnectionCapabilities as u, type ConnectionState as v, type CreateApplicationInput as w, type PongMessage as x, type PresenceAction as y, type PresenceLeftMessage as z };
|