@trycourier/courier-js 2.0.2-beta → 2.0.4-beta
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 +2 -2
- package/dist/__tests__/courier-inbox-socket.test.d.ts +1 -0
- package/dist/__tests__/courier-inbox-transaction-manager.test.d.ts +1 -0
- package/dist/__tests__/courier-socket.test.d.ts +1 -0
- package/dist/client/inbox-client.d.ts +14 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +612 -146
- package/dist/index.mjs.map +1 -0
- package/dist/socket/courier-inbox-socket.d.ts +87 -0
- package/dist/socket/courier-inbox-transaction-manager.d.ts +54 -0
- package/dist/socket/courier-socket.d.ts +146 -17
- package/dist/socket/inbox-message-utils.d.ts +8 -0
- package/dist/socket/version.d.ts +1 -0
- package/dist/types/socket/protocol/errors.d.ts +15 -0
- package/dist/types/socket/protocol/messages.d.ts +119 -0
- package/dist/utils/uuid.d.ts +11 -1
- package/package.json +3 -1
- package/dist/socket/inbox-socket.d.ts +0 -19
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { InboxMessage } from '../../inbox';
|
|
2
|
+
/** Client actions. */
|
|
3
|
+
export declare enum ClientAction {
|
|
4
|
+
/** Subscribe to various events for a particular channel. */
|
|
5
|
+
Subscribe = "subscribe",
|
|
6
|
+
/** Unsubscribe from a channel. */
|
|
7
|
+
Unsubscribe = "unsubscribe",
|
|
8
|
+
/** Pong response to a ping message from the server. */
|
|
9
|
+
Pong = "pong",
|
|
10
|
+
/** Ping the server to keep the connection alive. */
|
|
11
|
+
Ping = "ping",
|
|
12
|
+
/** Get the current configuration. */
|
|
13
|
+
GetConfig = "get-config"
|
|
14
|
+
}
|
|
15
|
+
/** Client request envelope. */
|
|
16
|
+
export interface ClientMessageEnvelope {
|
|
17
|
+
/**
|
|
18
|
+
* Transaction ID.
|
|
19
|
+
*
|
|
20
|
+
* This is a UUID generated per-socket message.
|
|
21
|
+
*
|
|
22
|
+
* The server response should include the same transaction ID.
|
|
23
|
+
*/
|
|
24
|
+
tid: string;
|
|
25
|
+
/** Requested action for the server to perform. */
|
|
26
|
+
action: ClientAction;
|
|
27
|
+
/** Optional: Statistics describing past requests and/or client state. */
|
|
28
|
+
stats?: Record<string, any>;
|
|
29
|
+
/** Optional: Payload for the request, varying by action. */
|
|
30
|
+
data?: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
export declare enum ServerAction {
|
|
33
|
+
/** Ping message from the server. */
|
|
34
|
+
Ping = "ping"
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Server action envelope.
|
|
38
|
+
*
|
|
39
|
+
* This is a request for the client to perform an action and respond to the server.
|
|
40
|
+
*/
|
|
41
|
+
export interface ServerActionEnvelope {
|
|
42
|
+
/** Transaction ID. */
|
|
43
|
+
tid: string;
|
|
44
|
+
/** Action from the server. */
|
|
45
|
+
action: ServerAction;
|
|
46
|
+
}
|
|
47
|
+
/** Server response types. */
|
|
48
|
+
export declare enum ServerResponse {
|
|
49
|
+
/** Response to an action request. */
|
|
50
|
+
Ack = "ack",
|
|
51
|
+
/** Response to a ping request. */
|
|
52
|
+
Pong = "pong"
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Server response envelope.
|
|
56
|
+
*
|
|
57
|
+
* This is a response from the server to a {@link ClientAction} (ping, subscribe, get-config, etc.).
|
|
58
|
+
*/
|
|
59
|
+
export interface ServerResponseEnvelope {
|
|
60
|
+
/** Transaction ID. */
|
|
61
|
+
tid: string;
|
|
62
|
+
/** Response from the server. */
|
|
63
|
+
response: ServerResponse;
|
|
64
|
+
/** Optional: Payload for the response, varying by response. */
|
|
65
|
+
data?: Record<string, any>;
|
|
66
|
+
}
|
|
67
|
+
/** Message event types broadcast by the server. */
|
|
68
|
+
export declare enum InboxMessageEvent {
|
|
69
|
+
NewMessage = "message",
|
|
70
|
+
Archive = "archive",
|
|
71
|
+
ArchiveAll = "archive-all",
|
|
72
|
+
ArchiveRead = "archive-read",
|
|
73
|
+
Clicked = "clicked",
|
|
74
|
+
MarkAllRead = "mark-all-read",
|
|
75
|
+
Opened = "opened",
|
|
76
|
+
Read = "read",
|
|
77
|
+
Unarchive = "unarchive",
|
|
78
|
+
Unopened = "unopened",
|
|
79
|
+
Unread = "unread"
|
|
80
|
+
}
|
|
81
|
+
/** Envelope for an inbox message event. */
|
|
82
|
+
export interface InboxMessageEventEnvelope {
|
|
83
|
+
/** Event type indicating a new message, or a mutation to one or more existing messages. */
|
|
84
|
+
event: InboxMessageEvent;
|
|
85
|
+
/** Message ID. */
|
|
86
|
+
messageId?: string;
|
|
87
|
+
/** Optional: Message data, varying by event. */
|
|
88
|
+
data?: InboxMessage;
|
|
89
|
+
}
|
|
90
|
+
/** Message sent by the server to indicate that the client should reconnect. */
|
|
91
|
+
export interface ReconnectMessage {
|
|
92
|
+
/** Event type indicating a reconnection. */
|
|
93
|
+
event: 'reconnect';
|
|
94
|
+
/** Message describing the reason for the reconnection. */
|
|
95
|
+
message: string;
|
|
96
|
+
/** Seconds after which the client should retry the connection. */
|
|
97
|
+
retryAfter: number;
|
|
98
|
+
/** https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code */
|
|
99
|
+
code: number;
|
|
100
|
+
}
|
|
101
|
+
/** Configuration for the client. */
|
|
102
|
+
export interface Config {
|
|
103
|
+
/** The time interval in milliseconds between client ping messages to the server. */
|
|
104
|
+
pingInterval: number;
|
|
105
|
+
/**
|
|
106
|
+
* Maximum number of outstanding pings before the client should
|
|
107
|
+
* close the connection and retry connecting.
|
|
108
|
+
*/
|
|
109
|
+
maxOutstandingPings: number;
|
|
110
|
+
}
|
|
111
|
+
/** Envelope for a config response. */
|
|
112
|
+
export interface ConfigResponseEnvelope {
|
|
113
|
+
/** Transaction ID. */
|
|
114
|
+
tid: string;
|
|
115
|
+
response: 'config';
|
|
116
|
+
/** Configuration data for the client. */
|
|
117
|
+
data: Config;
|
|
118
|
+
}
|
|
119
|
+
export type ServerMessage = ConfigResponseEnvelope | InboxMessageEventEnvelope | ReconnectMessage | ServerActionEnvelope | ServerResponseEnvelope;
|
package/dist/utils/uuid.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export declare class UUID {
|
|
2
|
-
static
|
|
2
|
+
private static readonly ALPHABET;
|
|
3
|
+
/**
|
|
4
|
+
* nanoid
|
|
5
|
+
* Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
|
6
|
+
*
|
|
7
|
+
* https://github.com/ai/nanoid/blob/main/LICENSE
|
|
8
|
+
*
|
|
9
|
+
* @param size - The size of the UUID to generate.
|
|
10
|
+
* @returns A string representing the UUID.
|
|
11
|
+
*/
|
|
12
|
+
static nanoid(size?: number): string;
|
|
3
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4-beta",
|
|
4
4
|
"description": "A browser-safe API wrapper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"jest": "29.7.0",
|
|
32
32
|
"jest-environment-jsdom": "29.7.0",
|
|
33
33
|
"jest-fetch-mock": "^3.0.3",
|
|
34
|
+
"jest-websocket-mock": "^2.5.0",
|
|
35
|
+
"rollup-plugin-visualizer": "^5.14.0",
|
|
34
36
|
"terser": "5.39.0",
|
|
35
37
|
"ts-jest": "29.1.1",
|
|
36
38
|
"vite": "6.2.6",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CourierSocket } from './courier-socket';
|
|
2
|
-
import { CourierClientOptions } from '../client/courier-client';
|
|
3
|
-
import { InboxMessage } from '../types/inbox';
|
|
4
|
-
export interface MessageEvent {
|
|
5
|
-
event: EventType;
|
|
6
|
-
messageId?: string;
|
|
7
|
-
type: string;
|
|
8
|
-
}
|
|
9
|
-
export type EventType = 'archive-read' | 'archive' | 'click' | 'mark-all-read' | 'opened' | 'read' | 'unarchive' | 'unopened' | 'unread';
|
|
10
|
-
export declare class InboxSocket extends CourierSocket {
|
|
11
|
-
receivedMessage?: (message: InboxMessage) => void;
|
|
12
|
-
receivedMessageEvent?: (event: MessageEvent) => void;
|
|
13
|
-
constructor(options: CourierClientOptions);
|
|
14
|
-
private convertToType;
|
|
15
|
-
sendSubscribe(props?: {
|
|
16
|
-
version?: number;
|
|
17
|
-
}): Promise<void>;
|
|
18
|
-
private static buildUrl;
|
|
19
|
-
}
|