@epostak/sdk 1.0.0 → 1.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.
Files changed (46) hide show
  1. package/README.md +94 -396
  2. package/dist/client.d.ts +30 -8
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +28 -11
  5. package/dist/client.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/resources/account.d.ts +25 -0
  9. package/dist/resources/account.d.ts.map +1 -1
  10. package/dist/resources/account.js +25 -0
  11. package/dist/resources/account.js.map +1 -1
  12. package/dist/resources/documents.d.ts +265 -1
  13. package/dist/resources/documents.d.ts.map +1 -1
  14. package/dist/resources/documents.js +265 -1
  15. package/dist/resources/documents.js.map +1 -1
  16. package/dist/resources/extract.d.ts +58 -0
  17. package/dist/resources/extract.d.ts.map +1 -1
  18. package/dist/resources/extract.js +64 -2
  19. package/dist/resources/extract.js.map +1 -1
  20. package/dist/resources/firms.d.ts +104 -0
  21. package/dist/resources/firms.d.ts.map +1 -1
  22. package/dist/resources/firms.js +104 -0
  23. package/dist/resources/firms.js.map +1 -1
  24. package/dist/resources/peppol.d.ts +68 -1
  25. package/dist/resources/peppol.d.ts.map +1 -1
  26. package/dist/resources/peppol.js +68 -1
  27. package/dist/resources/peppol.js.map +1 -1
  28. package/dist/resources/reporting.d.ts +28 -0
  29. package/dist/resources/reporting.d.ts.map +1 -1
  30. package/dist/resources/reporting.js +28 -0
  31. package/dist/resources/reporting.js.map +1 -1
  32. package/dist/resources/webhooks.d.ts +207 -2
  33. package/dist/resources/webhooks.d.ts.map +1 -1
  34. package/dist/resources/webhooks.js +224 -3
  35. package/dist/resources/webhooks.js.map +1 -1
  36. package/dist/types.d.ts +499 -19
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/utils/errors.d.ts +26 -4
  39. package/dist/utils/errors.d.ts.map +1 -1
  40. package/dist/utils/errors.js +26 -4
  41. package/dist/utils/errors.js.map +1 -1
  42. package/dist/utils/request.d.ts +42 -2
  43. package/dist/utils/request.d.ts.map +1 -1
  44. package/dist/utils/request.js +105 -30
  45. package/dist/utils/request.js.map +1 -1
  46. package/package.json +1 -1
@@ -1,49 +1,270 @@
1
1
  import { BaseResource, buildQuery } from "../utils/request.js";
2
+ /**
3
+ * Sub-resource for the webhook pull queue — an alternative to push webhooks.
4
+ * Use the pull queue when your server cannot receive inbound HTTPS requests.
5
+ * Events accumulate in the queue and must be acknowledged after processing.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Poll-based event consumption loop
10
+ * const { items, has_more } = await client.webhooks.queue.pull({ limit: 50 });
11
+ * for (const item of items) {
12
+ * await processEvent(item);
13
+ * await client.webhooks.queue.ack(item.id);
14
+ * }
15
+ * ```
16
+ */
2
17
  export class WebhookQueueResource extends BaseResource {
18
+ /**
19
+ * Pull unacknowledged events from the webhook queue.
20
+ * Events remain in the queue until explicitly acknowledged via `ack()` or `batchAck()`.
21
+ *
22
+ * @param params - Optional limit and event type filter
23
+ * @returns Array of queue items and whether more items are available
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const { items, has_more } = await client.webhooks.queue.pull({
28
+ * limit: 20,
29
+ * event_type: 'document.received',
30
+ * });
31
+ * ```
32
+ */
3
33
  pull(params) {
4
34
  return this.request("GET", `/webhook-queue${buildQuery({
5
35
  limit: params?.limit,
6
36
  event_type: params?.event_type,
7
37
  })}`);
8
38
  }
39
+ /**
40
+ * Acknowledge (remove) a single event from the queue after processing.
41
+ *
42
+ * @param eventId - The event ID to acknowledge
43
+ * @returns void
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * await client.webhooks.queue.ack('event-uuid');
48
+ * ```
49
+ */
9
50
  ack(eventId) {
10
51
  return this.request("DELETE", `/webhook-queue/${encodeURIComponent(eventId)}`);
11
52
  }
53
+ /**
54
+ * Acknowledge (remove) multiple events from the queue in a single request.
55
+ *
56
+ * @param eventIds - Array of event IDs to acknowledge
57
+ * @returns void
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const { items } = await client.webhooks.queue.pull({ limit: 50 });
62
+ * // Process all items...
63
+ * await client.webhooks.queue.batchAck(items.map(i => i.id));
64
+ * ```
65
+ */
12
66
  batchAck(eventIds) {
13
- return this.request("POST", "/webhook-queue/batch-ack", { event_ids: eventIds });
67
+ return this.request("POST", "/webhook-queue/batch-ack", {
68
+ event_ids: eventIds,
69
+ });
14
70
  }
71
+ /**
72
+ * Pull events across all managed firms (integrator endpoint).
73
+ * Only available with integrator API keys (`sk_int_*`).
74
+ * Use the `since` parameter for cursor-based polling.
75
+ *
76
+ * @param params - Optional limit and since timestamp for cursor-based polling
77
+ * @returns Array of events across all firms with count
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const { events, count } = await client.webhooks.queue.pullAll({
82
+ * since: '2026-04-11T00:00:00Z',
83
+ * limit: 200,
84
+ * });
85
+ * ```
86
+ */
15
87
  pullAll(params) {
16
88
  return this.request("GET", `/webhook-queue/all${buildQuery({
17
89
  limit: params?.limit,
18
90
  since: params?.since,
19
91
  })}`);
20
92
  }
93
+ /**
94
+ * Acknowledge (remove) multiple events from the cross-firm queue (integrator endpoint).
95
+ * Only available with integrator API keys (`sk_int_*`).
96
+ *
97
+ * @param eventIds - Array of event IDs to acknowledge
98
+ * @returns Object with the count of acknowledged events
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const { events } = await client.webhooks.queue.pullAll({ limit: 100 });
103
+ * // Process all events...
104
+ * const { acknowledged } = await client.webhooks.queue.batchAckAll(
105
+ * events.map(e => e.event_id),
106
+ * );
107
+ * ```
108
+ */
21
109
  batchAckAll(eventIds) {
22
- return this.request("POST", "/webhook-queue/all/batch-ack", { event_ids: eventIds });
110
+ return this.request("POST", "/webhook-queue/all/batch-ack", {
111
+ event_ids: eventIds,
112
+ });
23
113
  }
24
114
  }
115
+ /**
116
+ * Resource for managing webhook subscriptions and the pull queue.
117
+ * Webhooks notify your server about document events (sent, received, validated).
118
+ * Choose between push webhooks (server receives HTTPS POST) or the pull queue
119
+ * (your code polls for events).
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // Create a push webhook
124
+ * const webhook = await client.webhooks.create({
125
+ * url: 'https://example.com/webhooks/epostak',
126
+ * events: ['document.received', 'document.sent'],
127
+ * });
128
+ * // Store webhook.secret for HMAC verification
129
+ * ```
130
+ */
25
131
  export class WebhooksResource extends BaseResource {
26
- /** Access the webhook pull queue for polling-based consumption */
132
+ /** Sub-resource for the pull queue (polling-based event consumption) */
27
133
  queue;
28
134
  constructor(config) {
29
135
  super(config);
30
136
  this.queue = new WebhookQueueResource(config);
31
137
  }
138
+ /**
139
+ * Create a new webhook subscription. Returns the HMAC-SHA256 signing secret
140
+ * which is only available at creation time — store it securely.
141
+ *
142
+ * @param body - Webhook URL and optional event filter
143
+ * @returns Webhook details including the one-time signing secret
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const webhook = await client.webhooks.create({
148
+ * url: 'https://example.com/webhooks',
149
+ * events: ['document.received'],
150
+ * });
151
+ * console.log(webhook.secret); // Store this securely!
152
+ * ```
153
+ */
32
154
  create(body) {
33
155
  return this.request("POST", "/webhooks", body);
34
156
  }
157
+ /**
158
+ * List all webhook subscriptions for the current account.
159
+ *
160
+ * @returns Array of webhook subscriptions
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const webhooks = await client.webhooks.list();
165
+ * webhooks.forEach(w => console.log(w.url, w.isActive));
166
+ * ```
167
+ */
35
168
  async list() {
36
169
  const res = await this.request("GET", "/webhooks");
37
170
  return res.data;
38
171
  }
172
+ /**
173
+ * Get a webhook subscription by ID, including recent delivery history.
174
+ * Use the delivery history to debug failed webhook deliveries.
175
+ *
176
+ * @param id - Webhook UUID
177
+ * @returns Webhook details with delivery history
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const webhook = await client.webhooks.get('webhook-uuid');
182
+ * const failedDeliveries = webhook.deliveries.filter(d => d.status === 'failed');
183
+ * ```
184
+ */
39
185
  get(id) {
40
186
  return this.request("GET", `/webhooks/${encodeURIComponent(id)}`);
41
187
  }
188
+ /**
189
+ * Update a webhook subscription. Use this to change the URL, event filter,
190
+ * or pause/resume the webhook.
191
+ *
192
+ * @param id - Webhook UUID
193
+ * @param body - Fields to update (omit to leave unchanged)
194
+ * @returns The updated webhook
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * // Pause a webhook
199
+ * await client.webhooks.update('webhook-uuid', { isActive: false });
200
+ *
201
+ * // Change URL and events
202
+ * await client.webhooks.update('webhook-uuid', {
203
+ * url: 'https://new-url.com/webhooks',
204
+ * events: ['document.received', 'document.validated'],
205
+ * });
206
+ * ```
207
+ */
42
208
  update(id, body) {
43
209
  return this.request("PATCH", `/webhooks/${encodeURIComponent(id)}`, body);
44
210
  }
211
+ /**
212
+ * Delete a webhook subscription. Stops all future deliveries for this webhook.
213
+ *
214
+ * @param id - Webhook UUID to delete
215
+ * @returns Confirmation with `deleted: true`
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * await client.webhooks.delete('webhook-uuid');
220
+ * ```
221
+ */
45
222
  delete(id) {
46
223
  return this.request("DELETE", `/webhooks/${encodeURIComponent(id)}`);
47
224
  }
225
+ /**
226
+ * Send a test event to a webhook endpoint. Useful for verifying your
227
+ * webhook URL is reachable and responding correctly.
228
+ *
229
+ * @param id - Webhook UUID to test
230
+ * @param event - Event type to simulate (defaults to server-chosen event)
231
+ * @returns Test result with success status, HTTP status code, and response time
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const result = await client.webhooks.test('webhook-uuid');
236
+ * console.log(result.success, result.responseTime + 'ms');
237
+ * ```
238
+ */
239
+ test(id, event) {
240
+ const body = {};
241
+ if (event)
242
+ body.event = event;
243
+ return this.request("POST", `/webhooks/${encodeURIComponent(id)}/test`, body);
244
+ }
245
+ /**
246
+ * Get paginated delivery history for a webhook. Use this to inspect
247
+ * individual delivery attempts, filter by status, and debug failures.
248
+ *
249
+ * @param id - Webhook UUID
250
+ * @param params - Optional pagination and filter parameters
251
+ * @returns Paginated list of delivery records with total count
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * const { deliveries, total } = await client.webhooks.deliveries('webhook-uuid', {
256
+ * status: 'FAILED',
257
+ * limit: 50,
258
+ * });
259
+ * ```
260
+ */
261
+ deliveries(id, params) {
262
+ return this.request("GET", `/webhooks/${encodeURIComponent(id)}/deliveries${buildQuery({
263
+ limit: params?.limit,
264
+ offset: params?.offset,
265
+ status: params?.status,
266
+ event: params?.event,
267
+ })}`);
268
+ }
48
269
  }
49
270
  //# sourceMappingURL=webhooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAe/D,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IACpD,IAAI,CAAC,MAA2B;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,iBAAiB,UAAU,CAAC;YACrD,KAAK,EAAE,MAAM,EAAE,KAAK;YACpB,UAAU,EAAE,MAAM,EAAE,UAAU;SAC/B,CAAC,EAAE,CAAC,CAAC;IACR,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,kBAAkB,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,QAAQ,CAAC,QAAkB;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,0BAA0B,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,CAAC,MAA8B;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,qBAAqB,UAAU,CAAC;YACzD,KAAK,EAAE,MAAM,EAAE,KAAK;YACpB,KAAK,EAAE,MAAM,EAAE,KAAK;SACrB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