@rivium/push-node 0.1.2 → 0.1.3
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/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/modules/receipts.d.ts +44 -0
- package/dist/modules/receipts.js +57 -0
- package/dist/types.d.ts +38 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { InApp } from './modules/in-app';
|
|
|
8
8
|
import { ABTesting } from './modules/ab-testing';
|
|
9
9
|
import { Webhooks } from './modules/webhooks';
|
|
10
10
|
import { Analytics } from './modules/analytics';
|
|
11
|
+
import { Receipts } from './modules/receipts';
|
|
11
12
|
import { RiviumPushConfig } from './types';
|
|
12
13
|
export declare class RiviumPush {
|
|
13
14
|
private client;
|
|
@@ -31,6 +32,8 @@ export declare class RiviumPush {
|
|
|
31
32
|
webhooks: Webhooks;
|
|
32
33
|
/** Analytics */
|
|
33
34
|
analytics: Analytics;
|
|
35
|
+
/** Per-device delivery receipts for messages you have sent. */
|
|
36
|
+
receipts: Receipts;
|
|
34
37
|
constructor(config: RiviumPushConfig);
|
|
35
38
|
}
|
|
36
39
|
export { RiviumPushError } from './client';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const in_app_1 = require("./modules/in-app");
|
|
|
26
26
|
const ab_testing_1 = require("./modules/ab-testing");
|
|
27
27
|
const webhooks_1 = require("./modules/webhooks");
|
|
28
28
|
const analytics_1 = require("./modules/analytics");
|
|
29
|
+
const receipts_1 = require("./modules/receipts");
|
|
29
30
|
class RiviumPush {
|
|
30
31
|
constructor(config) {
|
|
31
32
|
this.client = new client_1.HttpClient(config);
|
|
@@ -39,6 +40,7 @@ class RiviumPush {
|
|
|
39
40
|
this.abTesting = new ab_testing_1.ABTesting(this.client);
|
|
40
41
|
this.webhooks = new webhooks_1.Webhooks(this.client);
|
|
41
42
|
this.analytics = new analytics_1.Analytics(this.client);
|
|
43
|
+
this.receipts = new receipts_1.Receipts(this.client);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
exports.RiviumPush = RiviumPush;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HttpClient } from '../client';
|
|
2
|
+
import { DeliveryReceipt, MessageDeliveryStats } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Delivery receipts — what actually happened to a notification, per device.
|
|
5
|
+
*
|
|
6
|
+
* A send returns `success` / `failed`, but those count what the push service
|
|
7
|
+
* *accepted*: APNs, FCM and Web Push confirm acceptance, never delivery.
|
|
8
|
+
* Receipts carry the rest of the story — which device, over which transport,
|
|
9
|
+
* why it failed, and whether the device confirmed receipt.
|
|
10
|
+
*
|
|
11
|
+
* Receipts are written for targeted sends (`sendToUser`, `sendToDevices`).
|
|
12
|
+
* Broadcasts record an aggregated per-platform breakdown on the message
|
|
13
|
+
* instead, since a row per device does not scale to a large audience.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Receipts {
|
|
16
|
+
private client;
|
|
17
|
+
constructor(client: HttpClient);
|
|
18
|
+
/**
|
|
19
|
+
* Get every receipt for a message.
|
|
20
|
+
*
|
|
21
|
+
* @param messageId `messageId` from the SendResult of the original send.
|
|
22
|
+
*/
|
|
23
|
+
getForMessage(messageId: string): Promise<DeliveryReceipt[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Get delivery/open/click rates for one message.
|
|
26
|
+
*/
|
|
27
|
+
getMessageStats(messageId: string): Promise<MessageDeliveryStats>;
|
|
28
|
+
/**
|
|
29
|
+
* Get click counts per notification action button for one message.
|
|
30
|
+
*/
|
|
31
|
+
getActionStats(messageId: string): Promise<{
|
|
32
|
+
actionId: string;
|
|
33
|
+
count: number;
|
|
34
|
+
}[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Get recent receipts for one device — useful for answering
|
|
37
|
+
* "did this user receive anything?".
|
|
38
|
+
*/
|
|
39
|
+
getForDevice(deviceId: string, limit?: number): Promise<DeliveryReceipt[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Get aggregate delivery stats for the project over a date range.
|
|
42
|
+
*/
|
|
43
|
+
getStats(startDate: Date | string, endDate: Date | string): Promise<MessageDeliveryStats>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Receipts = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Delivery receipts — what actually happened to a notification, per device.
|
|
6
|
+
*
|
|
7
|
+
* A send returns `success` / `failed`, but those count what the push service
|
|
8
|
+
* *accepted*: APNs, FCM and Web Push confirm acceptance, never delivery.
|
|
9
|
+
* Receipts carry the rest of the story — which device, over which transport,
|
|
10
|
+
* why it failed, and whether the device confirmed receipt.
|
|
11
|
+
*
|
|
12
|
+
* Receipts are written for targeted sends (`sendToUser`, `sendToDevices`).
|
|
13
|
+
* Broadcasts record an aggregated per-platform breakdown on the message
|
|
14
|
+
* instead, since a row per device does not scale to a large audience.
|
|
15
|
+
*/
|
|
16
|
+
class Receipts {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get every receipt for a message.
|
|
22
|
+
*
|
|
23
|
+
* @param messageId `messageId` from the SendResult of the original send.
|
|
24
|
+
*/
|
|
25
|
+
async getForMessage(messageId) {
|
|
26
|
+
return this.client.get(`/receipts/message/${encodeURIComponent(messageId)}`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get delivery/open/click rates for one message.
|
|
30
|
+
*/
|
|
31
|
+
async getMessageStats(messageId) {
|
|
32
|
+
return this.client.get(`/receipts/message/${encodeURIComponent(messageId)}/stats`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get click counts per notification action button for one message.
|
|
36
|
+
*/
|
|
37
|
+
async getActionStats(messageId) {
|
|
38
|
+
return this.client.get(`/receipts/message/${encodeURIComponent(messageId)}/actions`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get recent receipts for one device — useful for answering
|
|
42
|
+
* "did this user receive anything?".
|
|
43
|
+
*/
|
|
44
|
+
async getForDevice(deviceId, limit) {
|
|
45
|
+
return this.client.get(`/receipts/device/${encodeURIComponent(deviceId)}`, { limit });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get aggregate delivery stats for the project over a date range.
|
|
49
|
+
*/
|
|
50
|
+
async getStats(startDate, endDate) {
|
|
51
|
+
return this.client.get('/receipts/stats', {
|
|
52
|
+
startDate: startDate instanceof Date ? startDate.toISOString() : startDate,
|
|
53
|
+
endDate: endDate instanceof Date ? endDate.toISOString() : endDate,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Receipts = Receipts;
|
package/dist/types.d.ts
CHANGED
|
@@ -17,6 +17,44 @@ export interface SendResult {
|
|
|
17
17
|
failed: number;
|
|
18
18
|
reason?: 'no_recipients';
|
|
19
19
|
billing?: BillingInfo;
|
|
20
|
+
/**
|
|
21
|
+
* Id of the message this send created. Use it to fetch delivery receipts
|
|
22
|
+
* later — `success` only means the push service accepted the notification,
|
|
23
|
+
* not that any device received it.
|
|
24
|
+
*/
|
|
25
|
+
messageId?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Which transport carried a notification to a device. */
|
|
28
|
+
export type DeliveryTransport = 'apns' | 'voip' | 'webpush' | 'pn';
|
|
29
|
+
export type ReceiptStatus = 'sent' | 'delivered' | 'opened' | 'clicked' | 'failed' | 'dismissed';
|
|
30
|
+
export interface DeliveryReceipt {
|
|
31
|
+
id: string;
|
|
32
|
+
messageId: string;
|
|
33
|
+
deviceId: string;
|
|
34
|
+
userId?: string;
|
|
35
|
+
platform?: string;
|
|
36
|
+
/** `sent` = accepted by the transport; `delivered` = confirmed by the device. */
|
|
37
|
+
status: ReceiptStatus;
|
|
38
|
+
transport?: DeliveryTransport;
|
|
39
|
+
/** The push service's own id — APNs `apns-id`. Quote it when escalating. */
|
|
40
|
+
providerMessageId?: string;
|
|
41
|
+
/** Failure reason, e.g. 'Unregistered', 'Gone', 'BadDeviceToken'. */
|
|
42
|
+
error?: string;
|
|
43
|
+
sentAt: string;
|
|
44
|
+
deliveredAt?: string;
|
|
45
|
+
openedAt?: string;
|
|
46
|
+
clickedAt?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface MessageDeliveryStats {
|
|
49
|
+
total: number;
|
|
50
|
+
sent: number;
|
|
51
|
+
delivered: number;
|
|
52
|
+
opened: number;
|
|
53
|
+
clicked: number;
|
|
54
|
+
failed: number;
|
|
55
|
+
deliveryRate: number;
|
|
56
|
+
openRate: number;
|
|
57
|
+
clickRate: number;
|
|
20
58
|
}
|
|
21
59
|
export interface NotificationAction {
|
|
22
60
|
id: string;
|