@rivium/push-node 0.1.1 → 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/modules/segments.d.ts +18 -1
- package/dist/modules/segments.js +21 -0
- package/dist/types.d.ts +58 -2
- 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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../client';
|
|
2
|
-
import { Segment, CreateSegmentOptions, UpdateSegmentOptions, Device } from '../types';
|
|
2
|
+
import { Segment, CreateSegmentOptions, UpdateSegmentOptions, Device, SegmentPreviewOptions, SegmentPreviewResult } from '../types';
|
|
3
3
|
export declare class Segments {
|
|
4
4
|
private client;
|
|
5
5
|
constructor(client: HttpClient);
|
|
@@ -41,4 +41,21 @@ export declare class Segments {
|
|
|
41
41
|
recalculateAll(): Promise<{
|
|
42
42
|
success: boolean;
|
|
43
43
|
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Preview a set of filters without saving. Returns the total match count
|
|
46
|
+
* plus a small sample of matching devices — useful for validating filters
|
|
47
|
+
* before creating a segment.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const { count, preview } = await rivium.segments.preview({
|
|
52
|
+
* filters: [
|
|
53
|
+
* { field: 'platform', operator: 'equals', value: 'ios' },
|
|
54
|
+
* { field: 'metadata.plan', operator: 'equals', value: 'premium' },
|
|
55
|
+
* ],
|
|
56
|
+
* });
|
|
57
|
+
* console.log(`${count} devices match`);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
preview(options?: SegmentPreviewOptions): Promise<SegmentPreviewResult>;
|
|
44
61
|
}
|
package/dist/modules/segments.js
CHANGED
|
@@ -53,5 +53,26 @@ class Segments {
|
|
|
53
53
|
async recalculateAll() {
|
|
54
54
|
return this.client.post('/segments/recalculate-all');
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Preview a set of filters without saving. Returns the total match count
|
|
58
|
+
* plus a small sample of matching devices — useful for validating filters
|
|
59
|
+
* before creating a segment.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const { count, preview } = await rivium.segments.preview({
|
|
64
|
+
* filters: [
|
|
65
|
+
* { field: 'platform', operator: 'equals', value: 'ios' },
|
|
66
|
+
* { field: 'metadata.plan', operator: 'equals', value: 'premium' },
|
|
67
|
+
* ],
|
|
68
|
+
* });
|
|
69
|
+
* console.log(`${count} devices match`);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async preview(options = {}) {
|
|
73
|
+
const { limit, ...body } = options;
|
|
74
|
+
const path = limit ? `/segments/preview?limit=${limit}` : '/segments/preview';
|
|
75
|
+
return this.client.post(path, body);
|
|
76
|
+
}
|
|
56
77
|
}
|
|
57
78
|
exports.Segments = Segments;
|
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;
|
|
@@ -112,10 +150,11 @@ export interface Template {
|
|
|
112
150
|
createdAt: string;
|
|
113
151
|
updatedAt: string;
|
|
114
152
|
}
|
|
153
|
+
export type SegmentFilterOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'greater_than' | 'less_than' | 'in' | 'not_in' | 'exists';
|
|
115
154
|
export interface SegmentFilter {
|
|
116
155
|
field: string;
|
|
117
|
-
operator:
|
|
118
|
-
value: string | number | string[];
|
|
156
|
+
operator: SegmentFilterOperator;
|
|
157
|
+
value: string | number | boolean | string[];
|
|
119
158
|
}
|
|
120
159
|
export interface CreateSegmentOptions {
|
|
121
160
|
name: string;
|
|
@@ -135,6 +174,23 @@ export interface Segment {
|
|
|
135
174
|
createdAt: string;
|
|
136
175
|
updatedAt: string;
|
|
137
176
|
}
|
|
177
|
+
export interface SegmentPreviewOptions {
|
|
178
|
+
filters?: SegmentFilter[];
|
|
179
|
+
/** Number of sample devices to return (max 50, default 20). */
|
|
180
|
+
limit?: number;
|
|
181
|
+
}
|
|
182
|
+
export interface SegmentPreviewResult {
|
|
183
|
+
/** Total number of devices matching the filters. */
|
|
184
|
+
count: number;
|
|
185
|
+
/** Small sample of matching devices (up to `limit`). */
|
|
186
|
+
preview: Array<{
|
|
187
|
+
deviceId: string;
|
|
188
|
+
platform: string;
|
|
189
|
+
userId: string | null;
|
|
190
|
+
topics: string[] | null;
|
|
191
|
+
metadata: Record<string, any> | null;
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
138
194
|
export interface CreateScheduledOptions {
|
|
139
195
|
title: string;
|
|
140
196
|
body: string;
|