@rivium/push-node 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.
@@ -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
  }
@@ -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
@@ -112,10 +112,11 @@ export interface Template {
112
112
  createdAt: string;
113
113
  updatedAt: string;
114
114
  }
115
+ export type SegmentFilterOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'greater_than' | 'less_than' | 'in' | 'not_in' | 'exists';
115
116
  export interface SegmentFilter {
116
117
  field: string;
117
- operator: 'equals' | 'contains' | 'starts_with' | 'in' | 'gt' | 'lt' | 'between';
118
- value: string | number | string[];
118
+ operator: SegmentFilterOperator;
119
+ value: string | number | boolean | string[];
119
120
  }
120
121
  export interface CreateSegmentOptions {
121
122
  name: string;
@@ -135,6 +136,23 @@ export interface Segment {
135
136
  createdAt: string;
136
137
  updatedAt: string;
137
138
  }
139
+ export interface SegmentPreviewOptions {
140
+ filters?: SegmentFilter[];
141
+ /** Number of sample devices to return (max 50, default 20). */
142
+ limit?: number;
143
+ }
144
+ export interface SegmentPreviewResult {
145
+ /** Total number of devices matching the filters. */
146
+ count: number;
147
+ /** Small sample of matching devices (up to `limit`). */
148
+ preview: Array<{
149
+ deviceId: string;
150
+ platform: string;
151
+ userId: string | null;
152
+ topics: string[] | null;
153
+ metadata: Record<string, any> | null;
154
+ }>;
155
+ }
138
156
  export interface CreateScheduledOptions {
139
157
  title: string;
140
158
  body: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivium/push-node",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Rivium-co/rivium-push-nodejs-sdk.git"