@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
|
@@ -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",
|