arifa-client 1.0.1 → 1.0.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/dist/ArifaClient.d.ts +5 -1
- package/dist/ArifaClient.js +15 -5
- package/package.json +1 -1
package/dist/ArifaClient.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ interface NotifyPayload {
|
|
|
11
11
|
payload: Record<string, any>;
|
|
12
12
|
client?: "web" | "mobile";
|
|
13
13
|
}
|
|
14
|
+
interface NotifyResponse {
|
|
15
|
+
success: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
14
18
|
type ConnectionCallback = (state: ConnectionState) => void;
|
|
15
19
|
export declare class ArifaClient {
|
|
16
20
|
private apiKey;
|
|
@@ -37,7 +41,7 @@ export declare class ArifaClient {
|
|
|
37
41
|
/** Connect WebSocket */
|
|
38
42
|
private connect;
|
|
39
43
|
/** Send notification */
|
|
40
|
-
notify({ recipient, payload, client }: NotifyPayload): Promise<
|
|
44
|
+
notify({ recipient, payload, client, }: NotifyPayload): Promise<NotifyResponse>;
|
|
41
45
|
/** Disconnect WS */
|
|
42
46
|
disconnect(): void;
|
|
43
47
|
/** Return connection state */
|
package/dist/ArifaClient.js
CHANGED
|
@@ -80,9 +80,10 @@ export class ArifaClient {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
/** Send notification */
|
|
83
|
-
async notify({ recipient, payload, client }) {
|
|
84
|
-
if (!recipient || !payload)
|
|
83
|
+
async notify({ recipient, payload, client, }) {
|
|
84
|
+
if (!recipient || !payload) {
|
|
85
85
|
throw new Error("recipient and payload are required");
|
|
86
|
+
}
|
|
86
87
|
const body = {
|
|
87
88
|
recipient,
|
|
88
89
|
payload,
|
|
@@ -97,11 +98,20 @@ export class ArifaClient {
|
|
|
97
98
|
},
|
|
98
99
|
body: JSON.stringify(body),
|
|
99
100
|
});
|
|
101
|
+
let json;
|
|
102
|
+
try {
|
|
103
|
+
json = await res.json();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error("Invalid server response");
|
|
107
|
+
}
|
|
100
108
|
if (!res.ok) {
|
|
101
|
-
|
|
102
|
-
throw new Error(`Failed to send notification: ${res.status} ${res.statusText} ${text}`);
|
|
109
|
+
throw new Error(json.message || "Notification request failed");
|
|
103
110
|
}
|
|
104
|
-
return
|
|
111
|
+
return {
|
|
112
|
+
success: json.success,
|
|
113
|
+
message: json.message,
|
|
114
|
+
};
|
|
105
115
|
}
|
|
106
116
|
/** Disconnect WS */
|
|
107
117
|
disconnect() {
|