@pushary/server 1.3.3 → 1.5.0
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 +121 -0
- package/dist/adapters.cjs +733 -0
- package/dist/adapters.cjs.map +1 -0
- package/dist/adapters.d.cts +310 -0
- package/dist/adapters.d.ts +310 -0
- package/dist/adapters.js +316 -0
- package/dist/adapters.js.map +1 -0
- package/dist/chunk-E6DWMKLZ.js +388 -0
- package/dist/chunk-E6DWMKLZ.js.map +1 -0
- package/dist/index.cjs +116 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -412
- package/dist/index.d.ts +2 -412
- package/dist/index.js +9 -265
- package/dist/index.js.map +1 -1
- package/dist/util-DeGBh5at.d.cts +652 -0
- package/dist/util-DeGBh5at.d.ts +652 -0
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,403 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
readonly apiKey: string;
|
|
3
|
-
readonly baseUrl?: string;
|
|
4
|
-
}
|
|
5
|
-
interface ListParams {
|
|
6
|
-
readonly limit?: number;
|
|
7
|
-
readonly cursor?: string;
|
|
8
|
-
}
|
|
9
|
-
interface PaginatedResponse<T> {
|
|
10
|
-
readonly data: readonly T[];
|
|
11
|
-
readonly nextCursor?: string;
|
|
12
|
-
readonly hasMore: boolean;
|
|
13
|
-
}
|
|
14
|
-
interface Subscriber {
|
|
15
|
-
readonly id: string;
|
|
16
|
-
readonly siteId: string;
|
|
17
|
-
readonly endpoint: string;
|
|
18
|
-
readonly status: 'active' | 'unsubscribed' | 'expired' | 'bounced';
|
|
19
|
-
readonly browser?: string;
|
|
20
|
-
readonly os?: string;
|
|
21
|
-
readonly deviceType?: string;
|
|
22
|
-
readonly country?: string;
|
|
23
|
-
readonly city?: string;
|
|
24
|
-
readonly timezone?: string;
|
|
25
|
-
readonly language?: string;
|
|
26
|
-
readonly tags?: readonly string[];
|
|
27
|
-
readonly externalId?: string;
|
|
28
|
-
readonly createdAt: string;
|
|
29
|
-
readonly lastActiveAt?: string;
|
|
30
|
-
}
|
|
31
|
-
interface SubscriberListParams extends ListParams {
|
|
32
|
-
readonly status?: 'active' | 'unsubscribed' | 'expired' | 'bounced';
|
|
33
|
-
readonly tags?: readonly string[];
|
|
34
|
-
readonly externalId?: string;
|
|
35
|
-
}
|
|
36
|
-
interface UpdateSubscriber {
|
|
37
|
-
readonly tags?: readonly string[];
|
|
38
|
-
readonly externalId?: string;
|
|
39
|
-
readonly customData?: Readonly<Record<string, unknown>>;
|
|
40
|
-
}
|
|
41
|
-
interface Campaign {
|
|
42
|
-
readonly id: string;
|
|
43
|
-
readonly siteId: string;
|
|
44
|
-
readonly name: string;
|
|
45
|
-
readonly title: string;
|
|
46
|
-
readonly body: string;
|
|
47
|
-
readonly iconUrl?: string;
|
|
48
|
-
readonly imageUrl?: string;
|
|
49
|
-
readonly actionUrl?: string;
|
|
50
|
-
readonly status: 'draft' | 'scheduled' | 'sending' | 'active' | 'paused' | 'completed' | 'cancelled';
|
|
51
|
-
readonly scheduledAt?: string;
|
|
52
|
-
readonly totalTargeted: number;
|
|
53
|
-
readonly totalSent: number;
|
|
54
|
-
readonly totalDelivered: number;
|
|
55
|
-
readonly totalClicked: number;
|
|
56
|
-
readonly createdAt: string;
|
|
57
|
-
}
|
|
58
|
-
interface CreateCampaign {
|
|
59
|
-
readonly name: string;
|
|
60
|
-
readonly title: string;
|
|
61
|
-
readonly body: string;
|
|
62
|
-
readonly iconUrl?: string;
|
|
63
|
-
readonly imageUrl?: string;
|
|
64
|
-
readonly actionUrl?: string;
|
|
65
|
-
readonly scheduledAt?: string;
|
|
66
|
-
readonly segmentId?: string;
|
|
67
|
-
readonly tags?: readonly string[];
|
|
68
|
-
}
|
|
69
|
-
interface UpdateCampaign {
|
|
70
|
-
readonly name?: string;
|
|
71
|
-
readonly title?: string;
|
|
72
|
-
readonly body?: string;
|
|
73
|
-
readonly iconUrl?: string;
|
|
74
|
-
readonly imageUrl?: string;
|
|
75
|
-
readonly actionUrl?: string;
|
|
76
|
-
readonly scheduledAt?: string;
|
|
77
|
-
readonly status?: 'draft' | 'paused' | 'cancelled';
|
|
78
|
-
}
|
|
79
|
-
interface Template {
|
|
80
|
-
readonly id: string;
|
|
81
|
-
readonly siteId: string;
|
|
82
|
-
readonly name: string;
|
|
83
|
-
readonly title: string;
|
|
84
|
-
readonly body: string;
|
|
85
|
-
readonly iconUrl?: string;
|
|
86
|
-
readonly imageUrl?: string;
|
|
87
|
-
readonly actionUrl?: string;
|
|
88
|
-
readonly createdAt: string;
|
|
89
|
-
}
|
|
90
|
-
interface CreateTemplate {
|
|
91
|
-
readonly name: string;
|
|
92
|
-
readonly title: string;
|
|
93
|
-
readonly body: string;
|
|
94
|
-
readonly iconUrl?: string;
|
|
95
|
-
readonly imageUrl?: string;
|
|
96
|
-
readonly actionUrl?: string;
|
|
97
|
-
}
|
|
98
|
-
interface UpdateTemplate {
|
|
99
|
-
readonly name?: string;
|
|
100
|
-
readonly title?: string;
|
|
101
|
-
readonly body?: string;
|
|
102
|
-
readonly iconUrl?: string;
|
|
103
|
-
readonly imageUrl?: string;
|
|
104
|
-
readonly actionUrl?: string;
|
|
105
|
-
}
|
|
106
|
-
interface SendNotification {
|
|
107
|
-
readonly title: string;
|
|
108
|
-
readonly body: string;
|
|
109
|
-
readonly iconUrl?: string;
|
|
110
|
-
readonly imageUrl?: string;
|
|
111
|
-
readonly url?: string;
|
|
112
|
-
readonly subscriberIds?: readonly string[];
|
|
113
|
-
readonly externalIds?: readonly string[];
|
|
114
|
-
readonly tags?: readonly string[];
|
|
115
|
-
readonly data?: Readonly<Record<string, unknown>>;
|
|
116
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
117
|
-
}
|
|
118
|
-
interface SendResult {
|
|
119
|
-
readonly success: boolean;
|
|
120
|
-
readonly campaignId?: string;
|
|
121
|
-
readonly sent: number;
|
|
122
|
-
readonly limits: {
|
|
123
|
-
readonly remaining: number;
|
|
124
|
-
readonly limit: number;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
interface SubscriberCount {
|
|
128
|
-
readonly total: number;
|
|
129
|
-
readonly active: number;
|
|
130
|
-
readonly unsubscribed: number;
|
|
131
|
-
}
|
|
132
|
-
interface CampaignStats {
|
|
133
|
-
readonly totalSent: number;
|
|
134
|
-
readonly totalDelivered: number;
|
|
135
|
-
readonly totalClicked: number;
|
|
136
|
-
readonly totalFailed: number;
|
|
137
|
-
readonly deliveryRate: number;
|
|
138
|
-
readonly clickRate: number;
|
|
139
|
-
}
|
|
140
|
-
type FlowTriggerType = 'notification_click' | 'notification_impression' | 'notification_dismiss' | 'subscription' | 'unsubscription';
|
|
141
|
-
type FlowStepType = 'send_notification' | 'delay' | 'exit';
|
|
142
|
-
type FlowStatus = 'draft' | 'active' | 'paused' | 'archived';
|
|
143
|
-
interface FlowStepConfig {
|
|
144
|
-
readonly notification?: {
|
|
145
|
-
readonly title: string;
|
|
146
|
-
readonly body: string;
|
|
147
|
-
readonly iconUrl?: string;
|
|
148
|
-
readonly imageUrl?: string;
|
|
149
|
-
readonly actionUrl?: string;
|
|
150
|
-
};
|
|
151
|
-
readonly delay?: {
|
|
152
|
-
readonly value: number;
|
|
153
|
-
readonly unit: 'seconds' | 'minutes' | 'hours' | 'days';
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
interface FlowStep {
|
|
157
|
-
readonly id: string;
|
|
158
|
-
readonly flowId: string;
|
|
159
|
-
readonly stepOrder: number;
|
|
160
|
-
readonly stepType: FlowStepType;
|
|
161
|
-
readonly config: FlowStepConfig;
|
|
162
|
-
readonly createdAt: string;
|
|
163
|
-
readonly updatedAt: string;
|
|
164
|
-
}
|
|
165
|
-
interface Flow {
|
|
166
|
-
readonly id: string;
|
|
167
|
-
readonly siteId: string;
|
|
168
|
-
readonly name: string;
|
|
169
|
-
readonly description?: string;
|
|
170
|
-
readonly triggerType: FlowTriggerType;
|
|
171
|
-
readonly triggerCampaignId?: string;
|
|
172
|
-
readonly status: FlowStatus;
|
|
173
|
-
readonly executionCount: number;
|
|
174
|
-
readonly createdBy?: string;
|
|
175
|
-
readonly createdAt: string;
|
|
176
|
-
readonly updatedAt: string;
|
|
177
|
-
readonly steps?: readonly FlowStep[];
|
|
178
|
-
}
|
|
179
|
-
interface FlowStepInput {
|
|
180
|
-
readonly stepType: FlowStepType;
|
|
181
|
-
readonly config: FlowStepConfig;
|
|
182
|
-
}
|
|
183
|
-
interface CreateFlow {
|
|
184
|
-
readonly name: string;
|
|
185
|
-
readonly description?: string;
|
|
186
|
-
readonly triggerType: FlowTriggerType;
|
|
187
|
-
readonly triggerCampaignId?: string;
|
|
188
|
-
readonly steps?: readonly FlowStepInput[];
|
|
189
|
-
}
|
|
190
|
-
interface UpdateFlow {
|
|
191
|
-
readonly name?: string;
|
|
192
|
-
readonly description?: string;
|
|
193
|
-
readonly triggerType?: FlowTriggerType;
|
|
194
|
-
readonly triggerCampaignId?: string;
|
|
195
|
-
readonly status?: FlowStatus;
|
|
196
|
-
readonly steps?: readonly FlowStepInput[];
|
|
197
|
-
}
|
|
198
|
-
interface FlowListParams extends ListParams {
|
|
199
|
-
readonly status?: FlowStatus;
|
|
200
|
-
}
|
|
201
|
-
type DecisionType = 'confirm' | 'select' | 'input';
|
|
202
|
-
type DecisionStatus = 'pending' | 'answered' | 'expired' | 'cancelled';
|
|
203
|
-
interface CreateDecision {
|
|
204
|
-
readonly question: string;
|
|
205
|
-
readonly type?: DecisionType;
|
|
206
|
-
readonly options?: readonly string[];
|
|
207
|
-
readonly externalId?: string;
|
|
208
|
-
readonly email?: string;
|
|
209
|
-
readonly callbackUrl?: string;
|
|
210
|
-
readonly agentName?: string;
|
|
211
|
-
readonly context?: string;
|
|
212
|
-
readonly placeholder?: string;
|
|
213
|
-
readonly expiresInSeconds?: number;
|
|
214
|
-
readonly wait?: boolean;
|
|
215
|
-
readonly timeoutSeconds?: number;
|
|
216
|
-
readonly idempotencyKey?: string;
|
|
217
|
-
readonly poweredBy?: boolean;
|
|
218
|
-
readonly requireReachable?: boolean;
|
|
219
|
-
}
|
|
220
|
-
interface DecisionReachability {
|
|
221
|
-
readonly reachable?: boolean;
|
|
222
|
-
readonly reachableChannels?: number;
|
|
223
|
-
readonly deviceCount?: number;
|
|
224
|
-
}
|
|
225
|
-
interface DecisionResult extends DecisionReachability {
|
|
226
|
-
readonly decisionId: string;
|
|
227
|
-
readonly status: DecisionStatus;
|
|
228
|
-
readonly answered: boolean;
|
|
229
|
-
readonly value?: string | null;
|
|
230
|
-
readonly type?: DecisionType;
|
|
231
|
-
readonly question?: string;
|
|
232
|
-
readonly pollUrl?: string;
|
|
233
|
-
readonly decisionPageUrl?: string;
|
|
234
|
-
readonly expiresInSeconds?: number;
|
|
235
|
-
readonly idempotent?: boolean;
|
|
236
|
-
readonly hint?: string;
|
|
237
|
-
}
|
|
238
|
-
interface Decision {
|
|
239
|
-
readonly decisionId: string;
|
|
240
|
-
readonly status: DecisionStatus;
|
|
241
|
-
readonly answered: boolean;
|
|
242
|
-
readonly value: string | null;
|
|
243
|
-
readonly type: DecisionType;
|
|
244
|
-
readonly question: string;
|
|
245
|
-
readonly options: readonly string[] | null;
|
|
246
|
-
readonly externalId: string | null;
|
|
247
|
-
readonly context: string | null;
|
|
248
|
-
readonly createdAt: string;
|
|
249
|
-
readonly answeredAt: string | null;
|
|
250
|
-
readonly expiresAt: string | null;
|
|
251
|
-
}
|
|
252
|
-
interface DecisionAnswerResult {
|
|
253
|
-
readonly decisionId: string;
|
|
254
|
-
readonly status: DecisionStatus;
|
|
255
|
-
readonly answered: boolean;
|
|
256
|
-
readonly value?: string | null;
|
|
257
|
-
}
|
|
258
|
-
interface CancelDecisionResult {
|
|
259
|
-
readonly decisionId: string;
|
|
260
|
-
readonly cancelled: boolean;
|
|
261
|
-
readonly status: string;
|
|
262
|
-
}
|
|
263
|
-
interface WebhookSecret {
|
|
264
|
-
readonly webhookSecret: string;
|
|
265
|
-
}
|
|
266
|
-
interface DecisionCallback {
|
|
267
|
-
readonly correlationId: string;
|
|
268
|
-
readonly answer: string;
|
|
269
|
-
readonly value: string;
|
|
270
|
-
readonly answeredAt: string;
|
|
271
|
-
readonly context?: string;
|
|
272
|
-
}
|
|
273
|
-
interface EnrollResult {
|
|
274
|
-
readonly externalId: string;
|
|
275
|
-
readonly token: string;
|
|
276
|
-
readonly deepLink: string;
|
|
277
|
-
readonly universalLink: string;
|
|
278
|
-
readonly expiresInSeconds: number;
|
|
279
|
-
}
|
|
280
|
-
interface AskDecision {
|
|
281
|
-
readonly question: string;
|
|
282
|
-
readonly type?: DecisionType;
|
|
283
|
-
readonly options?: readonly string[];
|
|
284
|
-
readonly externalId?: string;
|
|
285
|
-
readonly email?: string;
|
|
286
|
-
readonly agentName?: string;
|
|
287
|
-
readonly context?: string;
|
|
288
|
-
readonly placeholder?: string;
|
|
289
|
-
readonly expiresInSeconds?: number;
|
|
290
|
-
readonly idempotencyKey?: string;
|
|
291
|
-
readonly poweredBy?: boolean;
|
|
292
|
-
readonly callbackUrl?: string;
|
|
293
|
-
readonly requireReachable?: boolean;
|
|
294
|
-
readonly timeoutMs?: number;
|
|
295
|
-
}
|
|
296
|
-
interface AskResult extends DecisionReachability {
|
|
297
|
-
readonly decisionId: string;
|
|
298
|
-
readonly status: DecisionStatus;
|
|
299
|
-
readonly answered: boolean;
|
|
300
|
-
readonly value: string | null;
|
|
301
|
-
readonly type: DecisionType;
|
|
302
|
-
readonly approved: boolean;
|
|
303
|
-
}
|
|
304
|
-
interface IssueBoundKey {
|
|
305
|
-
readonly externalId: string;
|
|
306
|
-
readonly name?: string;
|
|
307
|
-
readonly expiresInSeconds?: number;
|
|
308
|
-
}
|
|
309
|
-
interface BoundKeyResult {
|
|
310
|
-
readonly apiKey: string;
|
|
311
|
-
readonly keyPrefix: string;
|
|
312
|
-
readonly scope: 'bound';
|
|
313
|
-
readonly boundExternalId: string;
|
|
314
|
-
readonly expiresAt: string | null;
|
|
315
|
-
}
|
|
316
|
-
interface BoundKeySummary {
|
|
317
|
-
readonly keyPrefix: string;
|
|
318
|
-
readonly name: string;
|
|
319
|
-
readonly boundExternalId: string | null;
|
|
320
|
-
readonly isActive: boolean;
|
|
321
|
-
readonly lastUsedAt: string | null;
|
|
322
|
-
readonly expiresAt: string | null;
|
|
323
|
-
readonly createdAt: string;
|
|
324
|
-
}
|
|
325
|
-
interface RevokeKeyResult {
|
|
326
|
-
readonly keyPrefix: string;
|
|
327
|
-
readonly revoked: boolean;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
interface SubscribersResource {
|
|
331
|
-
readonly list: (params?: SubscriberListParams) => Promise<PaginatedResponse<Subscriber>>;
|
|
332
|
-
readonly get: (id: string) => Promise<Subscriber>;
|
|
333
|
-
readonly update: (id: string, data: UpdateSubscriber) => Promise<Subscriber>;
|
|
334
|
-
readonly delete: (id: string) => Promise<void>;
|
|
335
|
-
readonly count: () => Promise<SubscriberCount>;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
interface CampaignsResource {
|
|
339
|
-
readonly list: (params?: ListParams) => Promise<PaginatedResponse<Campaign>>;
|
|
340
|
-
readonly create: (data: CreateCampaign) => Promise<Campaign>;
|
|
341
|
-
readonly get: (id: string) => Promise<Campaign>;
|
|
342
|
-
readonly update: (id: string, data: UpdateCampaign) => Promise<Campaign>;
|
|
343
|
-
readonly delete: (id: string) => Promise<void>;
|
|
344
|
-
readonly send: (id: string) => Promise<Campaign>;
|
|
345
|
-
readonly pause: (id: string) => Promise<Campaign>;
|
|
346
|
-
readonly resume: (id: string) => Promise<Campaign>;
|
|
347
|
-
readonly stats: (id: string) => Promise<CampaignStats>;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
interface TemplatesResource {
|
|
351
|
-
readonly list: (params?: ListParams) => Promise<PaginatedResponse<Template>>;
|
|
352
|
-
readonly create: (data: CreateTemplate) => Promise<Template>;
|
|
353
|
-
readonly get: (id: string) => Promise<Template>;
|
|
354
|
-
readonly update: (id: string, data: UpdateTemplate) => Promise<Template>;
|
|
355
|
-
readonly delete: (id: string) => Promise<void>;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
interface NotificationsResource {
|
|
359
|
-
readonly send: (data: SendNotification) => Promise<SendResult>;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
interface FlowsResource {
|
|
363
|
-
readonly list: (params?: FlowListParams) => Promise<PaginatedResponse<Flow>>;
|
|
364
|
-
readonly create: (data: CreateFlow) => Promise<Flow>;
|
|
365
|
-
readonly get: (id: string) => Promise<Flow>;
|
|
366
|
-
readonly update: (id: string, data: UpdateFlow) => Promise<Flow>;
|
|
367
|
-
readonly delete: (id: string) => Promise<void>;
|
|
368
|
-
readonly activate: (id: string) => Promise<Flow>;
|
|
369
|
-
readonly pause: (id: string) => Promise<Flow>;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
interface DecisionsResource {
|
|
373
|
-
readonly create: (data: CreateDecision) => Promise<DecisionResult>;
|
|
374
|
-
readonly get: (id: string, opts?: {
|
|
375
|
-
readonly wait?: number;
|
|
376
|
-
}) => Promise<Decision>;
|
|
377
|
-
readonly ask: (data: AskDecision) => Promise<AskResult>;
|
|
378
|
-
readonly answer: (id: string, answer: string) => Promise<DecisionAnswerResult>;
|
|
379
|
-
readonly cancel: (id: string) => Promise<CancelDecisionResult>;
|
|
380
|
-
readonly getWebhookSecret: () => Promise<WebhookSecret>;
|
|
381
|
-
readonly rotateWebhookSecret: () => Promise<WebhookSecret>;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
interface KeysResource {
|
|
385
|
-
readonly issue: (data: IssueBoundKey) => Promise<BoundKeyResult>;
|
|
386
|
-
readonly list: () => Promise<readonly BoundKeySummary[]>;
|
|
387
|
-
readonly revoke: (keyPrefix: string) => Promise<RevokeKeyResult>;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
interface PusharyServer {
|
|
391
|
-
readonly subscribers: SubscribersResource;
|
|
392
|
-
readonly campaigns: CampaignsResource;
|
|
393
|
-
readonly templates: TemplatesResource;
|
|
394
|
-
readonly notifications: NotificationsResource;
|
|
395
|
-
readonly flows: FlowsResource;
|
|
396
|
-
readonly decisions: DecisionsResource;
|
|
397
|
-
readonly keys: KeysResource;
|
|
398
|
-
readonly enroll: (externalId: string) => Promise<EnrollResult>;
|
|
399
|
-
}
|
|
400
|
-
declare const createPusharyServer: (config: PusharyConfig) => PusharyServer;
|
|
1
|
+
export { A as ActionPresentation, a6 as AskDecision, a7 as AskResult, O as AuthorizationAuthority, N as AuthorizationBinding, M as AuthorizationEvaluation, I as AuthorizationQuery, H as AuthorizationVerdict, J as AuthorizeRequest, K as AuthorizeResult, a9 as BoundKeyResult, aa as BoundKeySummary, C as Campaign, g as CampaignStats, ad as CampaignsResource, a2 as CancelDecisionResult, R as ConsumeAuthorizationResult, Q as ConsumedAuthorization, e as CreateCampaign, Z as CreateDecision, l as CreateFlow, h as CreateTemplate, a0 as Decision, a1 as DecisionAnswerResult, a3 as DecisionCallback, x as DecisionDeliverability, z as DecisionParameters, y as DecisionReach, _ as DecisionReachability, $ as DecisionResult, v as DecisionStatus, w as DecisionSubject, D as DecisionType, ah as DecisionsResource, a5 as EnrollResult, V as ExecutionOutcome, W as ExecutionReceipt, F as Flow, n as FlowListParams, q as FlowStatus, r as FlowStep, s as FlowStepConfig, t as FlowStepInput, p as FlowStepType, o as FlowTriggerType, ag as FlowsResource, a8 as IssueBoundKey, ai as KeysResource, L as ListParams, af as NotificationsResource, u as PaginatedResponse, Y as PermitExecutionState, X as PermitRefusal, B as PresentedChange, E as PresentedFormat, a as PusharyConfig, P as PusharyServer, ab as RevokeKeyResult, al as SIGNATURE_HEADER, G as SandboxOutcome, j as SendNotification, k as SendResult, S as Subscriber, d as SubscriberCount, b as SubscriberListParams, ac as SubscribersResource, T as Template, ae as TemplatesResource, f as UpdateCampaign, m as UpdateFlow, U as UpdateSubscriber, i as UpdateTemplate, a4 as WebhookSecret, c as createPusharyServer, am as deterministicKey, an as isApproved, ak as parseDecisionCallback, aj as verifyWebhookSignature } from './util-DeGBh5at.js';
|
|
401
2
|
|
|
402
3
|
/**
|
|
403
4
|
* Thrown for any non-2xx response from the API.
|
|
@@ -432,15 +33,4 @@ declare class PusharyApiError extends Error {
|
|
|
432
33
|
get isServerError(): boolean;
|
|
433
34
|
}
|
|
434
35
|
|
|
435
|
-
|
|
436
|
-
declare const verifyWebhookSignature: (rawBody: string, signature: string | null | undefined, secret: string) => boolean;
|
|
437
|
-
declare const parseDecisionCallback: (rawBody: string) => DecisionCallback | null;
|
|
438
|
-
|
|
439
|
-
declare const deterministicKey: (parts: readonly string[]) => string;
|
|
440
|
-
declare const isApproved: (decision: {
|
|
441
|
-
readonly status: DecisionStatus;
|
|
442
|
-
readonly type?: DecisionType;
|
|
443
|
-
readonly value: string | null;
|
|
444
|
-
}) => boolean;
|
|
445
|
-
|
|
446
|
-
export { type AskDecision, type AskResult, type BoundKeyResult, type BoundKeySummary, type Campaign, type CampaignStats, type CampaignsResource, type CancelDecisionResult, type CreateCampaign, type CreateDecision, type CreateFlow, type CreateTemplate, type Decision, type DecisionAnswerResult, type DecisionCallback, type DecisionReachability, type DecisionResult, type DecisionStatus, type DecisionType, type DecisionsResource, type EnrollResult, type Flow, type FlowListParams, type FlowStatus, type FlowStep, type FlowStepConfig, type FlowStepInput, type FlowStepType, type FlowTriggerType, type FlowsResource, type IssueBoundKey, type KeysResource, type ListParams, type NotificationsResource, type PaginatedResponse, PusharyApiError, type PusharyConfig, type PusharyServer, type RevokeKeyResult, SIGNATURE_HEADER, type SendNotification, type SendResult, type Subscriber, type SubscriberCount, type SubscriberListParams, type SubscribersResource, type Template, type TemplatesResource, type UpdateCampaign, type UpdateFlow, type UpdateSubscriber, type UpdateTemplate, type WebhookSecret, createPusharyServer, deterministicKey, isApproved, parseDecisionCallback, verifyWebhookSignature };
|
|
36
|
+
export { PusharyApiError };
|
package/dist/index.js
CHANGED
|
@@ -1,268 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.setPrototypeOf(this, _PusharyApiError.prototype);
|
|
11
|
-
}
|
|
12
|
-
/** The key is missing, malformed, or revoked. Re-authenticate; do not retry. */
|
|
13
|
-
get isAuthError() {
|
|
14
|
-
return this.status === 401 || this.status === 403;
|
|
15
|
-
}
|
|
16
|
-
/** Rate limited. Back off and retry. */
|
|
17
|
-
get isRateLimited() {
|
|
18
|
-
return this.status === 429;
|
|
19
|
-
}
|
|
20
|
-
/** Server-side fault. Safe to retry an idempotent call. */
|
|
21
|
-
get isServerError() {
|
|
22
|
-
return this.status >= 500;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/request.ts
|
|
27
|
-
var buildUrl = (baseUrl, path, params) => {
|
|
28
|
-
const url = new URL(`${baseUrl}${path}`);
|
|
29
|
-
if (params) {
|
|
30
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
31
|
-
if (value !== void 0 && value !== null) {
|
|
32
|
-
url.searchParams.set(key, String(value));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return url.toString();
|
|
37
|
-
};
|
|
38
|
-
var handleResponse = async (response) => {
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
const body = await response.json().catch(() => ({}));
|
|
41
|
-
throw new PusharyApiError(body.message || body.error || `HTTP ${response.status}`, {
|
|
42
|
-
status: response.status,
|
|
43
|
-
statusText: response.statusText,
|
|
44
|
-
code: body.code,
|
|
45
|
-
body
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return response.json();
|
|
49
|
-
};
|
|
50
|
-
var createRequest = (ctx) => async (method, path, body) => {
|
|
51
|
-
const isGet = method === "GET";
|
|
52
|
-
const url = isGet && body ? buildUrl(ctx.baseUrl, path, body) : `${ctx.baseUrl}${path}`;
|
|
53
|
-
const response = await fetch(url, {
|
|
54
|
-
method,
|
|
55
|
-
headers: ctx.headers,
|
|
56
|
-
body: !isGet && body ? JSON.stringify(body) : void 0
|
|
57
|
-
});
|
|
58
|
-
return handleResponse(response);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// src/resources/subscribers.ts
|
|
62
|
-
var createSubscribersResource = (request) => Object.freeze({
|
|
63
|
-
list: (params) => request("GET", "/subscribers", params),
|
|
64
|
-
get: (id) => request("GET", `/subscribers/${id}`),
|
|
65
|
-
update: (id, data) => request("PATCH", `/subscribers/${id}`, data),
|
|
66
|
-
delete: (id) => request("DELETE", `/subscribers/${id}`),
|
|
67
|
-
count: () => request("GET", "/subscribers/count")
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// src/resources/campaigns.ts
|
|
71
|
-
var createCampaignsResource = (request) => Object.freeze({
|
|
72
|
-
list: (params) => request("GET", "/campaigns", params),
|
|
73
|
-
create: (data) => request("POST", "/campaigns", data),
|
|
74
|
-
get: (id) => request("GET", `/campaigns/${id}`),
|
|
75
|
-
update: (id, data) => request("PATCH", `/campaigns/${id}`, data),
|
|
76
|
-
delete: (id) => request("DELETE", `/campaigns/${id}`),
|
|
77
|
-
send: (id) => request("POST", `/campaigns/${id}/send`),
|
|
78
|
-
pause: (id) => request("POST", `/campaigns/${id}/pause`),
|
|
79
|
-
resume: (id) => request("POST", `/campaigns/${id}/resume`),
|
|
80
|
-
stats: (id) => request("GET", `/campaigns/${id}/stats`)
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// src/resources/templates.ts
|
|
84
|
-
var createTemplatesResource = (request) => Object.freeze({
|
|
85
|
-
list: (params) => request("GET", "/templates", params),
|
|
86
|
-
create: (data) => request("POST", "/templates", data),
|
|
87
|
-
get: (id) => request("GET", `/templates/${id}`),
|
|
88
|
-
update: (id, data) => request("PATCH", `/templates/${id}`, data),
|
|
89
|
-
delete: (id) => request("DELETE", `/templates/${id}`)
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// src/resources/notifications.ts
|
|
93
|
-
var createNotificationsResource = (request) => Object.freeze({
|
|
94
|
-
send: (data) => request("POST", "/send", data)
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// src/resources/flows.ts
|
|
98
|
-
var createFlowsResource = (request) => Object.freeze({
|
|
99
|
-
list: (params) => request("GET", "/flows", params),
|
|
100
|
-
create: (data) => request("POST", "/flows", data),
|
|
101
|
-
get: (id) => request("GET", `/flows/${id}`),
|
|
102
|
-
update: (id, data) => request("PATCH", `/flows/${id}`, data),
|
|
103
|
-
delete: (id) => request("DELETE", `/flows/${id}`),
|
|
104
|
-
activate: (id) => request("POST", `/flows/${id}/activate`),
|
|
105
|
-
pause: (id) => request("POST", `/flows/${id}/pause`)
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// src/resources/decisions.ts
|
|
109
|
-
import { randomUUID } from "crypto";
|
|
110
|
-
|
|
111
|
-
// src/util.ts
|
|
112
|
-
import { createHash } from "crypto";
|
|
113
|
-
var deterministicKey = (parts) => createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 40);
|
|
114
|
-
var AFFIRMATIVE = /* @__PURE__ */ new Set([
|
|
115
|
-
"yes",
|
|
116
|
-
"y",
|
|
117
|
-
"approve",
|
|
118
|
-
"approved",
|
|
119
|
-
"ok",
|
|
120
|
-
"okay",
|
|
121
|
-
"confirm",
|
|
122
|
-
"accept",
|
|
123
|
-
"true"
|
|
124
|
-
]);
|
|
125
|
-
var isApproved = (decision) => {
|
|
126
|
-
if (decision.status !== "answered") return false;
|
|
127
|
-
if (decision.type && decision.type !== "confirm") return true;
|
|
128
|
-
return decision.value != null && AFFIRMATIVE.has(decision.value.trim().toLowerCase());
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// src/resources/decisions.ts
|
|
132
|
-
var POLL_WINDOW_SECONDS = 50;
|
|
133
|
-
var DEFAULT_ASK_TIMEOUT_MS = 55e3;
|
|
134
|
-
var createDecisionsResource = (request) => {
|
|
135
|
-
const ask = async (data) => {
|
|
136
|
-
const idempotencyKey = data.idempotencyKey ?? randomUUID();
|
|
137
|
-
const created = await request("POST", "/decisions", {
|
|
138
|
-
question: data.question,
|
|
139
|
-
type: data.type,
|
|
140
|
-
options: data.options,
|
|
141
|
-
externalId: data.externalId,
|
|
142
|
-
email: data.email,
|
|
143
|
-
agentName: data.agentName,
|
|
144
|
-
context: data.context,
|
|
145
|
-
placeholder: data.placeholder,
|
|
146
|
-
expiresInSeconds: data.expiresInSeconds,
|
|
147
|
-
poweredBy: data.poweredBy,
|
|
148
|
-
callbackUrl: data.callbackUrl,
|
|
149
|
-
requireReachable: data.requireReachable,
|
|
150
|
-
idempotencyKey,
|
|
151
|
-
wait: false
|
|
152
|
-
});
|
|
153
|
-
const type = created.type ?? data.type ?? "confirm";
|
|
154
|
-
let status = created.status;
|
|
155
|
-
let answered = created.answered;
|
|
156
|
-
let value = created.value ?? null;
|
|
157
|
-
const deadline = Date.now() + Math.max(0, data.timeoutMs ?? DEFAULT_ASK_TIMEOUT_MS);
|
|
158
|
-
while (status === "pending" && Date.now() < deadline) {
|
|
159
|
-
const waitSeconds = Math.max(
|
|
160
|
-
1,
|
|
161
|
-
Math.min(POLL_WINDOW_SECONDS, Math.ceil((deadline - Date.now()) / 1e3))
|
|
162
|
-
);
|
|
163
|
-
const polled = await request("GET", `/decisions/${created.decisionId}`, {
|
|
164
|
-
wait: waitSeconds
|
|
165
|
-
});
|
|
166
|
-
status = polled.status;
|
|
167
|
-
answered = polled.answered;
|
|
168
|
-
value = polled.value;
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
decisionId: created.decisionId,
|
|
172
|
-
status,
|
|
173
|
-
answered,
|
|
174
|
-
value,
|
|
175
|
-
type,
|
|
176
|
-
approved: isApproved({ status, type, value }),
|
|
177
|
-
// Surfaced from the create response so a caller can tell an unanswered
|
|
178
|
-
// decision that reached nobody (reachable:false) apart from a real decline.
|
|
179
|
-
reachable: created.reachable,
|
|
180
|
-
reachableChannels: created.reachableChannels,
|
|
181
|
-
deviceCount: created.deviceCount
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
return Object.freeze({
|
|
185
|
-
create: (data) => request("POST", "/decisions", data),
|
|
186
|
-
get: (id, opts) => request("GET", `/decisions/${id}`, opts?.wait ? { wait: opts.wait } : void 0),
|
|
187
|
-
ask,
|
|
188
|
-
answer: (id, answer) => request("POST", `/decisions/${id}`, { answer }),
|
|
189
|
-
cancel: (id) => request("DELETE", `/decisions/${id}`),
|
|
190
|
-
getWebhookSecret: () => request("GET", "/webhook-secret"),
|
|
191
|
-
rotateWebhookSecret: () => request("POST", "/webhook-secret")
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// src/resources/keys.ts
|
|
196
|
-
var createKeysResource = (request) => Object.freeze({
|
|
197
|
-
issue: (data) => request("POST", "/keys", data),
|
|
198
|
-
list: () => request("GET", "/keys").then((r) => r.keys),
|
|
199
|
-
revoke: (keyPrefix) => request("DELETE", `/keys/${encodeURIComponent(keyPrefix)}`)
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// src/client.ts
|
|
203
|
-
var DEFAULT_BASE_URL = "https://pushary.com/api/v1/server";
|
|
204
|
-
var validateApiKey = (apiKey) => {
|
|
205
|
-
if (!apiKey) {
|
|
206
|
-
throw new Error("API key is required. Get your API key from https://pushary.com/dashboard/settings");
|
|
207
|
-
}
|
|
208
|
-
if (!apiKey.includes(".")) {
|
|
209
|
-
throw new Error("Invalid API key format. Use the full API key (pk_xxx.sk_xxx)");
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
var createContext = (config) => {
|
|
213
|
-
validateApiKey(config.apiKey);
|
|
214
|
-
return Object.freeze({
|
|
215
|
-
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
216
|
-
headers: Object.freeze({
|
|
217
|
-
"Content-Type": "application/json",
|
|
218
|
-
"Authorization": `Bearer ${config.apiKey}`
|
|
219
|
-
})
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
var createPusharyServer = (config) => {
|
|
223
|
-
const ctx = createContext(config);
|
|
224
|
-
const request = createRequest(ctx);
|
|
225
|
-
return Object.freeze({
|
|
226
|
-
subscribers: createSubscribersResource(request),
|
|
227
|
-
campaigns: createCampaignsResource(request),
|
|
228
|
-
templates: createTemplatesResource(request),
|
|
229
|
-
notifications: createNotificationsResource(request),
|
|
230
|
-
flows: createFlowsResource(request),
|
|
231
|
-
decisions: createDecisionsResource(request),
|
|
232
|
-
keys: createKeysResource(request),
|
|
233
|
-
enroll: (externalId) => request("POST", "/enroll", { externalId })
|
|
234
|
-
});
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// src/webhook.ts
|
|
238
|
-
import { createHmac, timingSafeEqual } from "crypto";
|
|
239
|
-
var SIGNATURE_HEADER = "x-pushary-signature";
|
|
240
|
-
var verifyWebhookSignature = (rawBody, signature, secret) => {
|
|
241
|
-
if (!signature || !secret) return false;
|
|
242
|
-
const expected = createHmac("sha256", secret).update(rawBody).digest("hex");
|
|
243
|
-
const a = Buffer.from(expected);
|
|
244
|
-
const b = Buffer.from(signature);
|
|
245
|
-
if (a.length !== b.length) return false;
|
|
246
|
-
return timingSafeEqual(a, b);
|
|
247
|
-
};
|
|
248
|
-
var parseDecisionCallback = (rawBody) => {
|
|
249
|
-
let parsed;
|
|
250
|
-
try {
|
|
251
|
-
parsed = JSON.parse(rawBody);
|
|
252
|
-
} catch {
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
256
|
-
const p = parsed;
|
|
257
|
-
if (typeof p.correlationId !== "string" || typeof p.answer !== "string") return null;
|
|
258
|
-
return {
|
|
259
|
-
correlationId: p.correlationId,
|
|
260
|
-
answer: p.answer,
|
|
261
|
-
value: typeof p.value === "string" ? p.value : p.answer,
|
|
262
|
-
answeredAt: typeof p.answeredAt === "string" ? p.answeredAt : "",
|
|
263
|
-
...typeof p.context === "string" ? { context: p.context } : {}
|
|
264
|
-
};
|
|
265
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
PusharyApiError,
|
|
3
|
+
SIGNATURE_HEADER,
|
|
4
|
+
createPusharyServer,
|
|
5
|
+
deterministicKey,
|
|
6
|
+
isApproved,
|
|
7
|
+
parseDecisionCallback,
|
|
8
|
+
verifyWebhookSignature
|
|
9
|
+
} from "./chunk-E6DWMKLZ.js";
|
|
266
10
|
export {
|
|
267
11
|
PusharyApiError,
|
|
268
12
|
SIGNATURE_HEADER,
|