@poststack.dev/sdk 0.1.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.
@@ -0,0 +1,420 @@
1
+ declare class PostStackClient {
2
+ private readonly baseUrl;
3
+ private readonly headers;
4
+ constructor(apiKey: string, baseUrl: string);
5
+ get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
6
+ post<T>(path: string, body?: unknown): Promise<T>;
7
+ patch<T>(path: string, body: unknown): Promise<T>;
8
+ delete<T>(path: string): Promise<T>;
9
+ private handleResponse;
10
+ }
11
+
12
+ interface Attachment {
13
+ filename: string;
14
+ content: string;
15
+ content_type?: string;
16
+ }
17
+ interface SendEmailInput {
18
+ from: string;
19
+ to: string[];
20
+ cc?: string[];
21
+ bcc?: string[];
22
+ reply_to?: string;
23
+ subject?: string;
24
+ html?: string;
25
+ text?: string;
26
+ headers?: Record<string, string>;
27
+ tags?: string[];
28
+ attachments?: Attachment[];
29
+ idempotency_key?: string;
30
+ scheduled_at?: string;
31
+ template_id?: string;
32
+ variables?: Record<string, string>;
33
+ }
34
+ interface BatchSendInput {
35
+ emails: SendEmailInput[];
36
+ }
37
+ interface CreateDomainInput {
38
+ name: string;
39
+ region?: 'eu-west-1' | 'us-east-1' | 'sa-east-1' | 'ap-northeast-1';
40
+ custom_return_path?: string;
41
+ open_tracking?: boolean;
42
+ click_tracking?: boolean;
43
+ tls_mode?: 'opportunistic' | 'enforced';
44
+ }
45
+ interface UpdateDomainInput {
46
+ open_tracking?: boolean;
47
+ click_tracking?: boolean;
48
+ tls_mode?: 'opportunistic' | 'enforced';
49
+ }
50
+ interface CreateContactInput {
51
+ email: string;
52
+ first_name?: string;
53
+ last_name?: string;
54
+ unsubscribed?: boolean;
55
+ properties?: Record<string, unknown>;
56
+ }
57
+ interface UpdateContactInput {
58
+ first_name?: string;
59
+ last_name?: string;
60
+ unsubscribed?: boolean;
61
+ properties?: Record<string, unknown>;
62
+ }
63
+ interface CreateSegmentInput {
64
+ name: string;
65
+ }
66
+ interface UpdateSegmentInput {
67
+ name: string;
68
+ }
69
+ interface AddContactsInput {
70
+ contact_ids: string[];
71
+ }
72
+ interface CreateTemplateInput {
73
+ name: string;
74
+ subject: string;
75
+ html: string;
76
+ text?: string;
77
+ variables?: string[];
78
+ }
79
+ interface UpdateTemplateInput {
80
+ name?: string;
81
+ subject?: string;
82
+ html?: string;
83
+ text?: string;
84
+ variables?: string[];
85
+ }
86
+ interface CreateWebhookInput {
87
+ url: string;
88
+ events: string[];
89
+ }
90
+ interface UpdateWebhookInput {
91
+ url?: string;
92
+ events?: string[];
93
+ enabled?: boolean;
94
+ }
95
+ type ApiKeyPermission = 'full_access' | 'sending_access';
96
+ type ApiKeyMode = 'live' | 'test';
97
+ interface CreateApiKeyInput {
98
+ name: string;
99
+ permission: ApiKeyPermission;
100
+ mode?: ApiKeyMode;
101
+ domain_id?: string;
102
+ }
103
+ type EmailStatus = 'queued' | 'sending' | 'delivered' | 'bounced' | 'complained' | 'failed';
104
+ type EmailEventType = 'queued' | 'sent' | 'delivered' | 'bounced' | 'soft_bounced' | 'opened' | 'clicked' | 'complained' | 'unsubscribed' | 'failed';
105
+ type DomainStatus = 'pending' | 'verified' | 'failed';
106
+ type TlsMode = 'opportunistic' | 'enforced';
107
+ type Region = 'eu-west-1' | 'us-east-1' | 'sa-east-1' | 'ap-northeast-1';
108
+ type DnsRecordType = 'TXT' | 'CNAME' | 'MX';
109
+ type DnsPurpose = 'spf' | 'dkim' | 'dmarc' | 'return_path' | 'mx';
110
+ interface EmailEvent {
111
+ type: EmailEventType;
112
+ timestamp: string;
113
+ }
114
+ interface Email {
115
+ id: string;
116
+ publicId: string;
117
+ from: string;
118
+ to: string[];
119
+ subject: string;
120
+ status: EmailStatus;
121
+ createdAt: string;
122
+ sentAt?: string;
123
+ events?: EmailEvent[];
124
+ }
125
+ interface DnsRecord {
126
+ type: DnsRecordType;
127
+ name: string;
128
+ value: string;
129
+ purpose: DnsPurpose;
130
+ verified: boolean;
131
+ }
132
+ interface Domain {
133
+ id: number;
134
+ name: string;
135
+ status: DomainStatus;
136
+ region: Region;
137
+ dnsRecords: DnsRecord[];
138
+ openTracking: boolean;
139
+ clickTracking: boolean;
140
+ tlsMode: TlsMode;
141
+ verifiedAt?: string;
142
+ createdAt: string;
143
+ }
144
+ interface Contact {
145
+ id: string;
146
+ email: string;
147
+ firstName?: string;
148
+ lastName?: string;
149
+ unsubscribed: boolean;
150
+ properties?: Record<string, unknown>;
151
+ createdAt: string;
152
+ }
153
+ interface Segment {
154
+ id: string;
155
+ name: string;
156
+ contactCount: number;
157
+ createdAt: string;
158
+ }
159
+ interface Template {
160
+ id: number;
161
+ publicId: string;
162
+ name: string;
163
+ subject: string;
164
+ htmlBody?: string;
165
+ textBody?: string;
166
+ variables?: string[];
167
+ published: boolean;
168
+ version: number;
169
+ createdAt: string;
170
+ }
171
+ interface Webhook {
172
+ id: number;
173
+ url: string;
174
+ events: string[];
175
+ active: boolean;
176
+ createdAt: string;
177
+ }
178
+ interface ApiKey {
179
+ id: number;
180
+ name: string;
181
+ keyPrefix: string;
182
+ permission: ApiKeyPermission;
183
+ mode: ApiKeyMode;
184
+ domainId: number | null;
185
+ lastUsedAt?: string | null;
186
+ expiresAt?: string | null;
187
+ createdAt: string;
188
+ }
189
+ interface PaginationMeta {
190
+ page: number;
191
+ perPage: number;
192
+ total: number;
193
+ totalPages: number;
194
+ }
195
+ interface PaginatedResponse<T> {
196
+ data: T[];
197
+ meta: PaginationMeta;
198
+ }
199
+ interface ListParams {
200
+ page?: number;
201
+ per_page?: number;
202
+ }
203
+ interface ListContactsParams extends ListParams {
204
+ search?: string;
205
+ segment_id?: string;
206
+ }
207
+ type BroadcastStatus = 'draft' | 'queued' | 'sending' | 'sent' | 'cancelled';
208
+ interface CreateBroadcastInput {
209
+ segment_id: string;
210
+ from: string;
211
+ subject: string;
212
+ html?: string;
213
+ text?: string;
214
+ reply_to?: string;
215
+ name?: string;
216
+ scheduled_at?: string;
217
+ topic_id?: number;
218
+ }
219
+ interface UpdateBroadcastInput {
220
+ segment_id?: string;
221
+ from?: string;
222
+ subject?: string;
223
+ html?: string;
224
+ text?: string;
225
+ reply_to?: string;
226
+ name?: string;
227
+ scheduled_at?: string;
228
+ topic_id?: number;
229
+ }
230
+ interface TestBroadcastInput {
231
+ email: string;
232
+ }
233
+ interface Broadcast {
234
+ id: number;
235
+ publicId: string;
236
+ subject: string;
237
+ status: BroadcastStatus;
238
+ totalRecipients: number;
239
+ deliveredCount: number;
240
+ openedCount: number;
241
+ clickedCount: number;
242
+ bouncedCount: number;
243
+ createdAt: string;
244
+ sentAt?: string;
245
+ scheduledAt?: string;
246
+ }
247
+ type SuppressionReason = 'hard_bounce' | 'complaint' | 'manual' | 'unsubscribe';
248
+ interface AddSuppressionInput {
249
+ email: string;
250
+ reason?: SuppressionReason;
251
+ }
252
+ interface Suppression {
253
+ id: number;
254
+ email: string;
255
+ reason: SuppressionReason;
256
+ createdAt: string;
257
+ }
258
+
259
+ declare class ApiKeysResource {
260
+ private readonly client;
261
+ constructor(client: PostStackClient);
262
+ create(input: CreateApiKeyInput): Promise<ApiKey>;
263
+ list(params?: ListParams): Promise<{
264
+ keys: ApiKey[];
265
+ }>;
266
+ get(id: number): Promise<ApiKey>;
267
+ revoke(id: number): Promise<{
268
+ success: boolean;
269
+ }>;
270
+ }
271
+
272
+ declare class BroadcastsResource {
273
+ private readonly client;
274
+ constructor(client: PostStackClient);
275
+ create(input: CreateBroadcastInput): Promise<{
276
+ broadcast: Broadcast;
277
+ }>;
278
+ list(params?: ListParams): Promise<PaginatedResponse<Broadcast>>;
279
+ get(id: string): Promise<{
280
+ broadcast: Broadcast;
281
+ }>;
282
+ update(id: string, input: UpdateBroadcastInput): Promise<{
283
+ broadcast: Broadcast;
284
+ }>;
285
+ send(id: string): Promise<{
286
+ success: boolean;
287
+ }>;
288
+ cancel(id: string): Promise<{
289
+ success: boolean;
290
+ }>;
291
+ sendTest(id: string, input: TestBroadcastInput): Promise<{
292
+ success: boolean;
293
+ }>;
294
+ }
295
+
296
+ declare class ContactsResource {
297
+ private readonly client;
298
+ constructor(client: PostStackClient);
299
+ create(input: CreateContactInput): Promise<Contact>;
300
+ list(params?: ListContactsParams): Promise<PaginatedResponse<Contact>>;
301
+ get(id: string): Promise<Contact>;
302
+ update(id: string, input: UpdateContactInput): Promise<Contact>;
303
+ delete(id: string): Promise<{
304
+ success: boolean;
305
+ }>;
306
+ unsubscribe(id: string): Promise<Contact>;
307
+ }
308
+
309
+ declare class DomainsResource {
310
+ private readonly client;
311
+ constructor(client: PostStackClient);
312
+ create(input: CreateDomainInput): Promise<Domain>;
313
+ list(params?: ListParams): Promise<PaginatedResponse<Domain>>;
314
+ get(id: number): Promise<Domain>;
315
+ verify(id: number): Promise<Domain>;
316
+ update(id: number, input: UpdateDomainInput): Promise<Domain>;
317
+ delete(id: number): Promise<{
318
+ success: boolean;
319
+ }>;
320
+ }
321
+
322
+ declare class EmailsResource {
323
+ private readonly client;
324
+ constructor(client: PostStackClient);
325
+ send(input: SendEmailInput): Promise<{
326
+ id: string;
327
+ }>;
328
+ batch(input: BatchSendInput): Promise<{
329
+ data: {
330
+ id: string;
331
+ }[];
332
+ }>;
333
+ get(id: string): Promise<Email>;
334
+ list(params?: ListParams): Promise<PaginatedResponse<Email>>;
335
+ cancel(id: string): Promise<{
336
+ success: boolean;
337
+ }>;
338
+ }
339
+
340
+ declare class SegmentsResource {
341
+ private readonly client;
342
+ constructor(client: PostStackClient);
343
+ create(input: CreateSegmentInput): Promise<Segment>;
344
+ list(params?: ListParams): Promise<PaginatedResponse<Segment>>;
345
+ get(id: string): Promise<Segment>;
346
+ update(id: string, input: UpdateSegmentInput): Promise<Segment>;
347
+ delete(id: string): Promise<{
348
+ success: boolean;
349
+ }>;
350
+ addContacts(id: string, input: AddContactsInput): Promise<{
351
+ success: boolean;
352
+ }>;
353
+ removeContact(id: string, contactId: string): Promise<{
354
+ success: boolean;
355
+ }>;
356
+ }
357
+
358
+ declare class SuppressionsResource {
359
+ private readonly client;
360
+ constructor(client: PostStackClient);
361
+ list(params?: ListParams): Promise<PaginatedResponse<Suppression>>;
362
+ add(input: AddSuppressionInput): Promise<{
363
+ success: boolean;
364
+ }>;
365
+ remove(email: string): Promise<{
366
+ success: boolean;
367
+ }>;
368
+ }
369
+
370
+ declare class TemplatesResource {
371
+ private readonly client;
372
+ constructor(client: PostStackClient);
373
+ create(input: CreateTemplateInput): Promise<Template>;
374
+ list(params?: ListParams): Promise<PaginatedResponse<Template>>;
375
+ get(id: string): Promise<Template>;
376
+ update(id: string, input: UpdateTemplateInput): Promise<Template>;
377
+ delete(id: string): Promise<{
378
+ success: boolean;
379
+ }>;
380
+ publish(id: string): Promise<Template>;
381
+ unpublish(id: string): Promise<Template>;
382
+ }
383
+
384
+ declare class WebhooksResource {
385
+ private readonly client;
386
+ constructor(client: PostStackClient);
387
+ create(input: CreateWebhookInput): Promise<Webhook>;
388
+ get(id: number): Promise<Webhook>;
389
+ list(params?: ListParams): Promise<PaginatedResponse<Webhook>>;
390
+ update(id: number, input: UpdateWebhookInput): Promise<Webhook>;
391
+ delete(id: number): Promise<{
392
+ success: boolean;
393
+ }>;
394
+ test(id: number): Promise<{
395
+ success: boolean;
396
+ }>;
397
+ }
398
+
399
+ declare class PostStackError extends Error {
400
+ readonly statusCode: number;
401
+ readonly code?: string | undefined;
402
+ constructor(statusCode: number, message: string, code?: string | undefined);
403
+ }
404
+
405
+ declare class PostStack {
406
+ readonly emails: EmailsResource;
407
+ readonly domains: DomainsResource;
408
+ readonly contacts: ContactsResource;
409
+ readonly segments: SegmentsResource;
410
+ readonly templates: TemplatesResource;
411
+ readonly webhooks: WebhooksResource;
412
+ readonly broadcasts: BroadcastsResource;
413
+ readonly suppressions: SuppressionsResource;
414
+ readonly apiKeys: ApiKeysResource;
415
+ constructor(apiKey: string, options?: {
416
+ baseUrl?: string;
417
+ });
418
+ }
419
+
420
+ export { type AddContactsInput, type AddSuppressionInput, type ApiKey, type ApiKeyMode, type ApiKeyPermission, type Attachment, type BatchSendInput, type Broadcast, type BroadcastStatus, type Contact, type CreateApiKeyInput, type CreateBroadcastInput, type CreateContactInput, type CreateDomainInput, type CreateSegmentInput, type CreateTemplateInput, type CreateWebhookInput, type DnsPurpose, type DnsRecord, type DnsRecordType, type Domain, type DomainStatus, type Email, type EmailEvent, type EmailEventType, type EmailStatus, type ListContactsParams, type ListParams, type PaginatedResponse, type PaginationMeta, PostStack, PostStackError, type Region, type Segment, type SendEmailInput, type Suppression, type SuppressionReason, type Template, type TestBroadcastInput, type TlsMode, type UpdateBroadcastInput, type UpdateContactInput, type UpdateDomainInput, type UpdateSegmentInput, type UpdateTemplateInput, type UpdateWebhookInput, type Webhook };