@emmanuel-nike/ark-notify-js 0.1.0 → 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 +115 -57
- package/dist/index.cjs +88 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +88 -58
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +89 -82
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +8 -11
- package/dist/react/index.d.ts +8 -11
- package/dist/react/index.js +90 -82
- 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-Cw2SnD6p.d.cts +0 -407
- package/dist/utils-Cw2SnD6p.d.ts +0 -407
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
type UserRole = 'SYSTEM_ADMIN' | 'ACCOUNT_ADMIN' | 'ACCOUNT_USER';
|
|
2
|
+
interface User {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
firstName: string;
|
|
6
|
+
lastName: string;
|
|
7
|
+
role: UserRole;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
}
|
|
10
|
+
interface ApiError {
|
|
11
|
+
error: string;
|
|
12
|
+
message: string;
|
|
13
|
+
reason?: string;
|
|
14
|
+
retryAfterSec?: number;
|
|
15
|
+
}
|
|
16
|
+
interface ConnectionCapabilities {
|
|
17
|
+
subscribe: boolean;
|
|
18
|
+
publish: boolean;
|
|
19
|
+
presence: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface Application {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
appKey: string;
|
|
25
|
+
tenantId: string;
|
|
26
|
+
authWebhookUrl: string | null;
|
|
27
|
+
requireClientAuth: boolean;
|
|
28
|
+
serverAuthUrl: string | null;
|
|
29
|
+
messageHistorySize: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
secret?: string;
|
|
33
|
+
}
|
|
34
|
+
interface CreateApplicationInput {
|
|
35
|
+
name: string;
|
|
36
|
+
authWebhookUrl?: string | null;
|
|
37
|
+
requireClientAuth?: boolean;
|
|
38
|
+
serverAuthUrl?: string | null;
|
|
39
|
+
messageHistorySize?: number;
|
|
40
|
+
}
|
|
41
|
+
interface UpdateApplicationInput {
|
|
42
|
+
name?: string;
|
|
43
|
+
authWebhookUrl?: string | null;
|
|
44
|
+
requireClientAuth?: boolean;
|
|
45
|
+
serverAuthUrl?: string | null;
|
|
46
|
+
messageHistorySize?: number;
|
|
47
|
+
}
|
|
48
|
+
interface LoginInput {
|
|
49
|
+
email: string;
|
|
50
|
+
password: string;
|
|
51
|
+
}
|
|
52
|
+
interface AuthResponse {
|
|
53
|
+
user: User;
|
|
54
|
+
token: string;
|
|
55
|
+
}
|
|
56
|
+
interface PublishEventInput {
|
|
57
|
+
channel: string;
|
|
58
|
+
event: string;
|
|
59
|
+
data?: unknown;
|
|
60
|
+
}
|
|
61
|
+
interface PublishEventResponse {
|
|
62
|
+
published: boolean;
|
|
63
|
+
channel: string;
|
|
64
|
+
event: string;
|
|
65
|
+
}
|
|
66
|
+
interface ChannelAuthInput {
|
|
67
|
+
socket_id?: string;
|
|
68
|
+
connection_id?: string;
|
|
69
|
+
channel_name: string;
|
|
70
|
+
user_data?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
interface ChannelAuthResponse {
|
|
73
|
+
auth: string;
|
|
74
|
+
}
|
|
75
|
+
interface ConnectionTokenInput {
|
|
76
|
+
client_id?: string;
|
|
77
|
+
clientId?: string;
|
|
78
|
+
user_data?: Record<string, unknown>;
|
|
79
|
+
userData?: Record<string, unknown>;
|
|
80
|
+
serverAuthUrl?: string | null;
|
|
81
|
+
server_auth_url?: string | null;
|
|
82
|
+
ttl?: number;
|
|
83
|
+
capabilities?: Partial<ConnectionCapabilities>;
|
|
84
|
+
}
|
|
85
|
+
interface ConnectionTokenResponse {
|
|
86
|
+
token: string;
|
|
87
|
+
client_id: string;
|
|
88
|
+
expires_at: number;
|
|
89
|
+
capabilities: ConnectionCapabilities;
|
|
90
|
+
}
|
|
91
|
+
/** Payload Ark Notify POSTs to your `serverAuthUrl`. */
|
|
92
|
+
interface ServerAuthRequest {
|
|
93
|
+
client_id: string;
|
|
94
|
+
user_data?: Record<string, unknown> | null;
|
|
95
|
+
capabilities?: Partial<ConnectionCapabilities> | null;
|
|
96
|
+
ttl?: number | null;
|
|
97
|
+
}
|
|
98
|
+
/** Approve a connection token request (option A). */
|
|
99
|
+
interface ServerAuthAllowedResponse {
|
|
100
|
+
allowed: true;
|
|
101
|
+
client_id: string;
|
|
102
|
+
capabilities?: ConnectionCapabilities;
|
|
103
|
+
ttl?: number;
|
|
104
|
+
}
|
|
105
|
+
/** Approve with a pre-signed token (option B). */
|
|
106
|
+
interface ServerAuthTokenResponse {
|
|
107
|
+
token: string;
|
|
108
|
+
}
|
|
109
|
+
type ServerAuthApprovedResponse = ServerAuthAllowedResponse | ServerAuthTokenResponse;
|
|
110
|
+
interface ServerAuthDeniedResponse {
|
|
111
|
+
allowed: false;
|
|
112
|
+
reason?: string;
|
|
113
|
+
}
|
|
114
|
+
type ServerAuthResponse = ServerAuthApprovedResponse | ServerAuthDeniedResponse;
|
|
115
|
+
interface CreateAuthorizedServerAuthResponseOptions {
|
|
116
|
+
clientId: string;
|
|
117
|
+
capabilities?: Partial<ConnectionCapabilities>;
|
|
118
|
+
ttl?: number;
|
|
119
|
+
/** When provided, returns a pre-signed token instead of `{ allowed: true }`. */
|
|
120
|
+
credentials?: AppCredentials;
|
|
121
|
+
}
|
|
122
|
+
type ServerAuthDecision = false | {
|
|
123
|
+
clientId?: string;
|
|
124
|
+
capabilities?: Partial<ConnectionCapabilities>;
|
|
125
|
+
ttl?: number;
|
|
126
|
+
};
|
|
127
|
+
interface HandleServerAuthOptions {
|
|
128
|
+
request: ServerAuthRequest;
|
|
129
|
+
isAuthorized: (request: ServerAuthRequest) => ServerAuthDecision | Promise<ServerAuthDecision>;
|
|
130
|
+
credentials?: AppCredentials;
|
|
131
|
+
}
|
|
132
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
|
|
133
|
+
interface ConnectedMessage {
|
|
134
|
+
type: 'connected';
|
|
135
|
+
connection_id: string;
|
|
136
|
+
client_id: string;
|
|
137
|
+
app_key: string;
|
|
138
|
+
authenticated: boolean;
|
|
139
|
+
channels?: string[];
|
|
140
|
+
}
|
|
141
|
+
interface EventMessage {
|
|
142
|
+
type: 'event';
|
|
143
|
+
channel: string;
|
|
144
|
+
event: string;
|
|
145
|
+
data: unknown;
|
|
146
|
+
clientId: string | null;
|
|
147
|
+
timestamp: number;
|
|
148
|
+
}
|
|
149
|
+
interface PresenceMemberInfo {
|
|
150
|
+
connectionId: string;
|
|
151
|
+
clientId: string;
|
|
152
|
+
data: Record<string, unknown>;
|
|
153
|
+
updatedAt: number;
|
|
154
|
+
}
|
|
155
|
+
type PresenceAction = 'enter' | 'leave' | 'update' | 'sync';
|
|
156
|
+
interface PresenceMessage {
|
|
157
|
+
type: 'presence';
|
|
158
|
+
channel: string;
|
|
159
|
+
action: PresenceAction;
|
|
160
|
+
member: PresenceMemberInfo | null;
|
|
161
|
+
members: PresenceMemberInfo[] | null;
|
|
162
|
+
timestamp: number;
|
|
163
|
+
}
|
|
164
|
+
interface SubscribedMessage {
|
|
165
|
+
type: 'subscribed';
|
|
166
|
+
channel: string;
|
|
167
|
+
}
|
|
168
|
+
interface UnsubscribedMessage {
|
|
169
|
+
type: 'unsubscribed';
|
|
170
|
+
channel: string;
|
|
171
|
+
}
|
|
172
|
+
interface PublishedMessage {
|
|
173
|
+
type: 'published';
|
|
174
|
+
channel: string;
|
|
175
|
+
event: string;
|
|
176
|
+
}
|
|
177
|
+
interface PongMessage {
|
|
178
|
+
type: 'pong';
|
|
179
|
+
timestamp: number;
|
|
180
|
+
}
|
|
181
|
+
interface PingMessage {
|
|
182
|
+
type: 'ping';
|
|
183
|
+
}
|
|
184
|
+
interface ServerErrorMessage {
|
|
185
|
+
type: 'error';
|
|
186
|
+
code: string;
|
|
187
|
+
message: string;
|
|
188
|
+
}
|
|
189
|
+
interface PresenceUpdatedMessage {
|
|
190
|
+
type: 'presence_updated';
|
|
191
|
+
channel: string;
|
|
192
|
+
data: Record<string, unknown>;
|
|
193
|
+
}
|
|
194
|
+
interface PresenceLeftMessage {
|
|
195
|
+
type: 'presence_left';
|
|
196
|
+
channel: string;
|
|
197
|
+
}
|
|
198
|
+
type ServerMessage = ConnectedMessage | EventMessage | PresenceMessage | SubscribedMessage | UnsubscribedMessage | PublishedMessage | PongMessage | PingMessage | ServerErrorMessage | PresenceUpdatedMessage | PresenceLeftMessage;
|
|
199
|
+
interface ArkNotifyClientConfig {
|
|
200
|
+
baseUrl?: string;
|
|
201
|
+
token?: string | (() => string | null | undefined);
|
|
202
|
+
fetch?: typeof fetch;
|
|
203
|
+
}
|
|
204
|
+
interface AppCredentials {
|
|
205
|
+
appKey: string;
|
|
206
|
+
secret: string;
|
|
207
|
+
}
|
|
208
|
+
type PrivateChannelAuthHandler = (channel: string, connectionId: string) => Promise<string>;
|
|
209
|
+
interface ArkNotifyConnectionConfig {
|
|
210
|
+
baseUrl?: string;
|
|
211
|
+
appKey: string;
|
|
212
|
+
clientId?: string;
|
|
213
|
+
/** Signed connection token, or a resolver. Omit to auto-fetch when `clientId` is set. */
|
|
214
|
+
token?: string | (() => string | null | undefined);
|
|
215
|
+
/** App credentials for auto-fetching a connection token (backend-only when no serverAuthUrl). */
|
|
216
|
+
credentials?: AppCredentials;
|
|
217
|
+
/** Override server auth URL when auto-fetching a token; uses the application default when omitted. */
|
|
218
|
+
serverAuthUrl?: string | null;
|
|
219
|
+
/** Forwarded to the connection-token endpoint when auto-fetching a token. */
|
|
220
|
+
user_data?: Record<string, unknown>;
|
|
221
|
+
autoReconnect?: boolean;
|
|
222
|
+
reconnectDelayMs?: number;
|
|
223
|
+
maxReconnectDelayMs?: number;
|
|
224
|
+
onPrivateChannelAuth?: PrivateChannelAuthHandler;
|
|
225
|
+
fetch?: typeof fetch;
|
|
226
|
+
WebSocket?: typeof WebSocket;
|
|
227
|
+
}
|
|
228
|
+
interface SubscribeOptions {
|
|
229
|
+
history?: boolean;
|
|
230
|
+
presence?: boolean;
|
|
231
|
+
presence_data?: Record<string, unknown>;
|
|
232
|
+
auth?: string;
|
|
233
|
+
}
|
|
234
|
+
interface ArkNotifySSEConfig {
|
|
235
|
+
baseUrl?: string;
|
|
236
|
+
appKey: string;
|
|
237
|
+
channels: string[];
|
|
238
|
+
clientId?: string;
|
|
239
|
+
token?: string | (() => string | null | undefined);
|
|
240
|
+
auth?: Record<string, string>;
|
|
241
|
+
user_data?: Record<string, unknown>;
|
|
242
|
+
history?: boolean;
|
|
243
|
+
onPrivateChannelAuth?: PrivateChannelAuthHandler;
|
|
244
|
+
EventSource?: typeof EventSource;
|
|
245
|
+
}
|
|
246
|
+
interface ChannelEventHandler<T = unknown> {
|
|
247
|
+
(data: T, message: EventMessage): void;
|
|
248
|
+
}
|
|
249
|
+
interface ChannelHandlers {
|
|
250
|
+
[eventName: string]: ChannelEventHandler;
|
|
251
|
+
}
|
|
252
|
+
interface HealthResponse {
|
|
253
|
+
status: string;
|
|
254
|
+
uptime: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type { AppCredentials as A, PublishedMessage as B, ConnectionTokenInput as C, ServerAuthApprovedResponse as D, EventMessage as E, ServerAuthDecision as F, ServerAuthDeniedResponse as G, HandleServerAuthOptions as H, ServerAuthRequest as I, ServerAuthResponse as J, ServerAuthTokenResponse as K, LoginInput as L, ServerErrorMessage as M, ServerMessage as N, SubscribeOptions as O, PingMessage as P, SubscribedMessage as Q, UpdateApplicationInput as R, ServerAuthAllowedResponse as S, User as T, UnsubscribedMessage as U, UserRole as V, ConnectionTokenResponse as a, ApiError as b, Application as c, ArkNotifyClientConfig as d, ArkNotifyConnectionConfig as e, ArkNotifySSEConfig as f, AuthResponse as g, ChannelAuthInput as h, ChannelAuthResponse as i, ChannelEventHandler as j, ChannelHandlers as k, ConnectedMessage as l, ConnectionCapabilities as m, ConnectionState as n, CreateApplicationInput as o, CreateAuthorizedServerAuthResponseOptions as p, HealthResponse as q, PongMessage as r, PresenceAction as s, PresenceLeftMessage as t, PresenceMemberInfo as u, PresenceMessage as v, PresenceUpdatedMessage as w, PrivateChannelAuthHandler as x, PublishEventInput as y, PublishEventResponse as z };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { d as ArkNotifyClientConfig, q as HealthResponse, L as LoginInput, g as AuthResponse, T as User, c as Application, o as CreateApplicationInput, R as UpdateApplicationInput, A as AppCredentials, y as PublishEventInput, z as PublishEventResponse, h as ChannelAuthInput, i as ChannelAuthResponse, C as ConnectionTokenInput, a as ConnectionTokenResponse, e as ArkNotifyConnectionConfig, n as ConnectionState, l as ConnectedMessage, E as EventMessage, v as PresenceMessage, N as ServerMessage, O as SubscribeOptions, j as ChannelEventHandler, f as ArkNotifySSEConfig, b as ApiError } from './types-tQECeZab.cjs';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_BASE_URL = "https://ark-notify-933303906015.europe-north1.run.app";
|
|
4
|
+
interface ArkNotifyGlobalConfig {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Set the default base URL once at application startup. */
|
|
8
|
+
declare function configureArkNotify(config: ArkNotifyGlobalConfig): void;
|
|
9
|
+
declare function resolveBaseUrl(baseUrl?: string): string;
|
|
10
|
+
|
|
11
|
+
declare class ArkNotifyClient {
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly fetchFn;
|
|
14
|
+
private token?;
|
|
15
|
+
constructor(config: ArkNotifyClientConfig);
|
|
16
|
+
setToken(token: string | null): void;
|
|
17
|
+
private getAuthHeader;
|
|
18
|
+
private request;
|
|
19
|
+
health(): Promise<HealthResponse>;
|
|
20
|
+
login(input: LoginInput): Promise<AuthResponse>;
|
|
21
|
+
me(): Promise<{
|
|
22
|
+
user: User;
|
|
23
|
+
}>;
|
|
24
|
+
listApplications(): Promise<{
|
|
25
|
+
apps: Application[];
|
|
26
|
+
}>;
|
|
27
|
+
createApplication(input: CreateApplicationInput): Promise<{
|
|
28
|
+
app: Application;
|
|
29
|
+
}>;
|
|
30
|
+
getApplication(id: string): Promise<{
|
|
31
|
+
app: Application;
|
|
32
|
+
}>;
|
|
33
|
+
updateApplication(id: string, input: UpdateApplicationInput): Promise<{
|
|
34
|
+
app: Application;
|
|
35
|
+
}>;
|
|
36
|
+
deleteApplication(id: string): Promise<{
|
|
37
|
+
deleted: boolean;
|
|
38
|
+
id: string;
|
|
39
|
+
}>;
|
|
40
|
+
regenerateSecret(id: string): Promise<{
|
|
41
|
+
app: Application;
|
|
42
|
+
}>;
|
|
43
|
+
publishEvent(appKey: string, credentials: AppCredentials, input: PublishEventInput): Promise<PublishEventResponse>;
|
|
44
|
+
authorizeChannel(appKey: string, credentials: AppCredentials, input: ChannelAuthInput): Promise<ChannelAuthResponse>;
|
|
45
|
+
issueConnectionToken(appKey: string, input: ConnectionTokenInput, credentials?: AppCredentials): Promise<ConnectionTokenResponse>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type EventMap = {
|
|
49
|
+
state: (state: ConnectionState) => void;
|
|
50
|
+
connected: (message: ConnectedMessage) => void;
|
|
51
|
+
event: (message: EventMessage) => void;
|
|
52
|
+
presence: (message: PresenceMessage) => void;
|
|
53
|
+
message: (message: ServerMessage) => void;
|
|
54
|
+
error: (error: {
|
|
55
|
+
code: string;
|
|
56
|
+
message: string;
|
|
57
|
+
}) => void;
|
|
58
|
+
close: (event: {
|
|
59
|
+
code: number;
|
|
60
|
+
reason: string;
|
|
61
|
+
}) => void;
|
|
62
|
+
};
|
|
63
|
+
type EventName = keyof EventMap;
|
|
64
|
+
declare class ArkNotifyConnection {
|
|
65
|
+
private readonly config;
|
|
66
|
+
private ws;
|
|
67
|
+
private state;
|
|
68
|
+
private connectionId;
|
|
69
|
+
private clientId;
|
|
70
|
+
private authenticated;
|
|
71
|
+
private subscribedChannels;
|
|
72
|
+
private pendingSubscriptions;
|
|
73
|
+
private listeners;
|
|
74
|
+
private reconnectAttempt;
|
|
75
|
+
private reconnectTimer;
|
|
76
|
+
private intentionalClose;
|
|
77
|
+
private connectPromise;
|
|
78
|
+
private readonly WebSocketCtor;
|
|
79
|
+
constructor(config: ArkNotifyConnectionConfig);
|
|
80
|
+
getConnectionState(): ConnectionState;
|
|
81
|
+
getConnectionId(): string | null;
|
|
82
|
+
getClientId(): string | null;
|
|
83
|
+
isAuthenticated(): boolean;
|
|
84
|
+
getSubscribedChannels(): string[];
|
|
85
|
+
on<E extends EventName>(event: E, handler: EventMap[E]): () => void;
|
|
86
|
+
off<E extends EventName>(event: E, handler: EventMap[E]): void;
|
|
87
|
+
private emit;
|
|
88
|
+
private setState;
|
|
89
|
+
connect(): Promise<void>;
|
|
90
|
+
private doConnect;
|
|
91
|
+
disconnect(): void;
|
|
92
|
+
private scheduleReconnect;
|
|
93
|
+
private clearReconnectTimer;
|
|
94
|
+
private send;
|
|
95
|
+
private handleMessage;
|
|
96
|
+
private resubscribeAll;
|
|
97
|
+
subscribe(channel: string, options?: SubscribeOptions): Promise<void>;
|
|
98
|
+
unsubscribe(channel: string): void;
|
|
99
|
+
publish(channel: string, event: string, data?: unknown): void;
|
|
100
|
+
presenceEnter(channel: string, data: Record<string, unknown>): void;
|
|
101
|
+
presenceUpdate(channel: string, data: Record<string, unknown>): void;
|
|
102
|
+
presenceLeave(channel: string): void;
|
|
103
|
+
presenceSync(channel: string): void;
|
|
104
|
+
ping(): void;
|
|
105
|
+
bind(channel: string, event: string, handler: ChannelEventHandler): () => void;
|
|
106
|
+
bindAll(channel: string, handler: ChannelEventHandler): () => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type SSEEventMap = {
|
|
110
|
+
connected: (message: ConnectedMessage) => void;
|
|
111
|
+
event: (message: EventMessage) => void;
|
|
112
|
+
presence: (message: PresenceMessage) => void;
|
|
113
|
+
message: (message: ServerMessage) => void;
|
|
114
|
+
error: (error: Error) => void;
|
|
115
|
+
close: () => void;
|
|
116
|
+
};
|
|
117
|
+
type SSEEventName = keyof SSEEventMap;
|
|
118
|
+
declare class ArkNotifySSE {
|
|
119
|
+
private readonly config;
|
|
120
|
+
private es;
|
|
121
|
+
private connectionId;
|
|
122
|
+
private listeners;
|
|
123
|
+
private readonly EventSourceCtor;
|
|
124
|
+
constructor(config: ArkNotifySSEConfig);
|
|
125
|
+
getConnectionId(): string | null;
|
|
126
|
+
on<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): () => void;
|
|
127
|
+
off<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): void;
|
|
128
|
+
private emit;
|
|
129
|
+
connect(): Promise<void>;
|
|
130
|
+
disconnect(): void;
|
|
131
|
+
bind(channel: string, event: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
132
|
+
bindAll(channel: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class ArkNotifyError extends Error {
|
|
136
|
+
readonly status: number;
|
|
137
|
+
readonly code: string;
|
|
138
|
+
readonly retryAfterSec?: number;
|
|
139
|
+
readonly reason?: string;
|
|
140
|
+
constructor(status: number, body: ApiError);
|
|
141
|
+
}
|
|
142
|
+
declare function toWebSocketUrl(baseUrl: string, path: string): string;
|
|
143
|
+
declare function resolveValue<T>(value: T | (() => T)): T;
|
|
144
|
+
declare function isPrivateChannel(channel: string): boolean;
|
|
145
|
+
|
|
146
|
+
export { ArkNotifyClient as A, DEFAULT_BASE_URL as D, ArkNotifyConnection as a, ArkNotifyError as b, type ArkNotifyGlobalConfig as c, ArkNotifySSE as d, configureArkNotify as e, resolveValue as f, isPrivateChannel as i, resolveBaseUrl as r, toWebSocketUrl as t };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { d as ArkNotifyClientConfig, q as HealthResponse, L as LoginInput, g as AuthResponse, T as User, c as Application, o as CreateApplicationInput, R as UpdateApplicationInput, A as AppCredentials, y as PublishEventInput, z as PublishEventResponse, h as ChannelAuthInput, i as ChannelAuthResponse, C as ConnectionTokenInput, a as ConnectionTokenResponse, e as ArkNotifyConnectionConfig, n as ConnectionState, l as ConnectedMessage, E as EventMessage, v as PresenceMessage, N as ServerMessage, O as SubscribeOptions, j as ChannelEventHandler, f as ArkNotifySSEConfig, b as ApiError } from './types-tQECeZab.js';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_BASE_URL = "https://ark-notify-933303906015.europe-north1.run.app";
|
|
4
|
+
interface ArkNotifyGlobalConfig {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Set the default base URL once at application startup. */
|
|
8
|
+
declare function configureArkNotify(config: ArkNotifyGlobalConfig): void;
|
|
9
|
+
declare function resolveBaseUrl(baseUrl?: string): string;
|
|
10
|
+
|
|
11
|
+
declare class ArkNotifyClient {
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly fetchFn;
|
|
14
|
+
private token?;
|
|
15
|
+
constructor(config: ArkNotifyClientConfig);
|
|
16
|
+
setToken(token: string | null): void;
|
|
17
|
+
private getAuthHeader;
|
|
18
|
+
private request;
|
|
19
|
+
health(): Promise<HealthResponse>;
|
|
20
|
+
login(input: LoginInput): Promise<AuthResponse>;
|
|
21
|
+
me(): Promise<{
|
|
22
|
+
user: User;
|
|
23
|
+
}>;
|
|
24
|
+
listApplications(): Promise<{
|
|
25
|
+
apps: Application[];
|
|
26
|
+
}>;
|
|
27
|
+
createApplication(input: CreateApplicationInput): Promise<{
|
|
28
|
+
app: Application;
|
|
29
|
+
}>;
|
|
30
|
+
getApplication(id: string): Promise<{
|
|
31
|
+
app: Application;
|
|
32
|
+
}>;
|
|
33
|
+
updateApplication(id: string, input: UpdateApplicationInput): Promise<{
|
|
34
|
+
app: Application;
|
|
35
|
+
}>;
|
|
36
|
+
deleteApplication(id: string): Promise<{
|
|
37
|
+
deleted: boolean;
|
|
38
|
+
id: string;
|
|
39
|
+
}>;
|
|
40
|
+
regenerateSecret(id: string): Promise<{
|
|
41
|
+
app: Application;
|
|
42
|
+
}>;
|
|
43
|
+
publishEvent(appKey: string, credentials: AppCredentials, input: PublishEventInput): Promise<PublishEventResponse>;
|
|
44
|
+
authorizeChannel(appKey: string, credentials: AppCredentials, input: ChannelAuthInput): Promise<ChannelAuthResponse>;
|
|
45
|
+
issueConnectionToken(appKey: string, input: ConnectionTokenInput, credentials?: AppCredentials): Promise<ConnectionTokenResponse>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type EventMap = {
|
|
49
|
+
state: (state: ConnectionState) => void;
|
|
50
|
+
connected: (message: ConnectedMessage) => void;
|
|
51
|
+
event: (message: EventMessage) => void;
|
|
52
|
+
presence: (message: PresenceMessage) => void;
|
|
53
|
+
message: (message: ServerMessage) => void;
|
|
54
|
+
error: (error: {
|
|
55
|
+
code: string;
|
|
56
|
+
message: string;
|
|
57
|
+
}) => void;
|
|
58
|
+
close: (event: {
|
|
59
|
+
code: number;
|
|
60
|
+
reason: string;
|
|
61
|
+
}) => void;
|
|
62
|
+
};
|
|
63
|
+
type EventName = keyof EventMap;
|
|
64
|
+
declare class ArkNotifyConnection {
|
|
65
|
+
private readonly config;
|
|
66
|
+
private ws;
|
|
67
|
+
private state;
|
|
68
|
+
private connectionId;
|
|
69
|
+
private clientId;
|
|
70
|
+
private authenticated;
|
|
71
|
+
private subscribedChannels;
|
|
72
|
+
private pendingSubscriptions;
|
|
73
|
+
private listeners;
|
|
74
|
+
private reconnectAttempt;
|
|
75
|
+
private reconnectTimer;
|
|
76
|
+
private intentionalClose;
|
|
77
|
+
private connectPromise;
|
|
78
|
+
private readonly WebSocketCtor;
|
|
79
|
+
constructor(config: ArkNotifyConnectionConfig);
|
|
80
|
+
getConnectionState(): ConnectionState;
|
|
81
|
+
getConnectionId(): string | null;
|
|
82
|
+
getClientId(): string | null;
|
|
83
|
+
isAuthenticated(): boolean;
|
|
84
|
+
getSubscribedChannels(): string[];
|
|
85
|
+
on<E extends EventName>(event: E, handler: EventMap[E]): () => void;
|
|
86
|
+
off<E extends EventName>(event: E, handler: EventMap[E]): void;
|
|
87
|
+
private emit;
|
|
88
|
+
private setState;
|
|
89
|
+
connect(): Promise<void>;
|
|
90
|
+
private doConnect;
|
|
91
|
+
disconnect(): void;
|
|
92
|
+
private scheduleReconnect;
|
|
93
|
+
private clearReconnectTimer;
|
|
94
|
+
private send;
|
|
95
|
+
private handleMessage;
|
|
96
|
+
private resubscribeAll;
|
|
97
|
+
subscribe(channel: string, options?: SubscribeOptions): Promise<void>;
|
|
98
|
+
unsubscribe(channel: string): void;
|
|
99
|
+
publish(channel: string, event: string, data?: unknown): void;
|
|
100
|
+
presenceEnter(channel: string, data: Record<string, unknown>): void;
|
|
101
|
+
presenceUpdate(channel: string, data: Record<string, unknown>): void;
|
|
102
|
+
presenceLeave(channel: string): void;
|
|
103
|
+
presenceSync(channel: string): void;
|
|
104
|
+
ping(): void;
|
|
105
|
+
bind(channel: string, event: string, handler: ChannelEventHandler): () => void;
|
|
106
|
+
bindAll(channel: string, handler: ChannelEventHandler): () => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type SSEEventMap = {
|
|
110
|
+
connected: (message: ConnectedMessage) => void;
|
|
111
|
+
event: (message: EventMessage) => void;
|
|
112
|
+
presence: (message: PresenceMessage) => void;
|
|
113
|
+
message: (message: ServerMessage) => void;
|
|
114
|
+
error: (error: Error) => void;
|
|
115
|
+
close: () => void;
|
|
116
|
+
};
|
|
117
|
+
type SSEEventName = keyof SSEEventMap;
|
|
118
|
+
declare class ArkNotifySSE {
|
|
119
|
+
private readonly config;
|
|
120
|
+
private es;
|
|
121
|
+
private connectionId;
|
|
122
|
+
private listeners;
|
|
123
|
+
private readonly EventSourceCtor;
|
|
124
|
+
constructor(config: ArkNotifySSEConfig);
|
|
125
|
+
getConnectionId(): string | null;
|
|
126
|
+
on<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): () => void;
|
|
127
|
+
off<E extends SSEEventName>(event: E, handler: SSEEventMap[E]): void;
|
|
128
|
+
private emit;
|
|
129
|
+
connect(): Promise<void>;
|
|
130
|
+
disconnect(): void;
|
|
131
|
+
bind(channel: string, event: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
132
|
+
bindAll(channel: string, handler: (data: unknown, message: EventMessage) => void): () => void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class ArkNotifyError extends Error {
|
|
136
|
+
readonly status: number;
|
|
137
|
+
readonly code: string;
|
|
138
|
+
readonly retryAfterSec?: number;
|
|
139
|
+
readonly reason?: string;
|
|
140
|
+
constructor(status: number, body: ApiError);
|
|
141
|
+
}
|
|
142
|
+
declare function toWebSocketUrl(baseUrl: string, path: string): string;
|
|
143
|
+
declare function resolveValue<T>(value: T | (() => T)): T;
|
|
144
|
+
declare function isPrivateChannel(channel: string): boolean;
|
|
145
|
+
|
|
146
|
+
export { ArkNotifyClient as A, DEFAULT_BASE_URL as D, ArkNotifyConnection as a, ArkNotifyError as b, type ArkNotifyGlobalConfig as c, ArkNotifySSE as d, configureArkNotify as e, resolveValue as f, isPrivateChannel as i, resolveBaseUrl as r, toWebSocketUrl as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emmanuel-nike/ark-notify-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "JavaScript SDK for Ark Notify — real-time pub/sub, presence, and platform management",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,16 @@
|
|
|
27
27
|
"types": "./dist/react/index.d.cts",
|
|
28
28
|
"default": "./dist/react/index.cjs"
|
|
29
29
|
}
|
|
30
|
+
},
|
|
31
|
+
"./server": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/server/index.d.ts",
|
|
34
|
+
"default": "./dist/server/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/server/index.d.cts",
|
|
38
|
+
"default": "./dist/server/index.cjs"
|
|
39
|
+
}
|
|
30
40
|
}
|
|
31
41
|
},
|
|
32
42
|
"files": [
|
|
@@ -49,6 +59,7 @@
|
|
|
49
59
|
}
|
|
50
60
|
},
|
|
51
61
|
"devDependencies": {
|
|
62
|
+
"@types/node": "^25.9.3",
|
|
52
63
|
"@types/react": "^19.1.8",
|
|
53
64
|
"react": "^19.1.0",
|
|
54
65
|
"tsup": "^8.5.0",
|