@pgns/core 0.1.1
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/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.js +278 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +10 -0
- package/dist/events.d.ts +31 -0
- package/dist/events.js +63 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/types.d.ts +355 -0
- package/dist/types.js +246 -0
- package/package.json +53 -0
package/dist/events.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const DEFAULT_RETRY_DELAY = 3000;
|
|
2
|
+
/**
|
|
3
|
+
* Connect to the Pgns SSE event stream using `fetch` + `ReadableStream`.
|
|
4
|
+
*
|
|
5
|
+
* Automatically reconnects on failure with a 3-second delay. Cancel the
|
|
6
|
+
* connection by aborting the signal passed in `opts`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const controller = new AbortController();
|
|
11
|
+
* createEventSource("https://api.pgns.io", {
|
|
12
|
+
* token: "eyJhbG...",
|
|
13
|
+
* signal: controller.signal,
|
|
14
|
+
* onEvent(data) { console.log(data); },
|
|
15
|
+
* });
|
|
16
|
+
* // later: controller.abort();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export async function createEventSource(baseUrl, opts) {
|
|
20
|
+
const url = opts.roostId
|
|
21
|
+
? `${baseUrl}/v1/events?roost_id=${encodeURIComponent(opts.roostId)}`
|
|
22
|
+
: `${baseUrl}/v1/events`;
|
|
23
|
+
while (!opts.signal?.aborted) {
|
|
24
|
+
try {
|
|
25
|
+
const res = await fetch(url, {
|
|
26
|
+
headers: {
|
|
27
|
+
...(opts.token ? { Authorization: `Bearer ${opts.token}` } : {}),
|
|
28
|
+
Accept: 'text/event-stream',
|
|
29
|
+
},
|
|
30
|
+
signal: opts.signal,
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok || !res.body) {
|
|
33
|
+
throw new Error(`SSE connect failed: ${res.status}`);
|
|
34
|
+
}
|
|
35
|
+
const reader = res.body.getReader();
|
|
36
|
+
const decoder = new TextDecoder();
|
|
37
|
+
let buffer = '';
|
|
38
|
+
while (!opts.signal?.aborted) {
|
|
39
|
+
const { done, value } = await reader.read();
|
|
40
|
+
if (done)
|
|
41
|
+
break;
|
|
42
|
+
buffer += decoder.decode(value, { stream: true });
|
|
43
|
+
const lines = buffer.split('\n');
|
|
44
|
+
buffer = lines.pop() ?? '';
|
|
45
|
+
for (const line of lines) {
|
|
46
|
+
if (line.startsWith('data:')) {
|
|
47
|
+
opts.onEvent(line.slice(5).trim());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (opts.signal?.aborted)
|
|
54
|
+
break;
|
|
55
|
+
if (err instanceof DOMException && err.name === 'AbortError')
|
|
56
|
+
break;
|
|
57
|
+
opts.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
58
|
+
}
|
|
59
|
+
if (opts.signal?.aborted)
|
|
60
|
+
break;
|
|
61
|
+
await new Promise((r) => setTimeout(r, DEFAULT_RETRY_DELAY));
|
|
62
|
+
}
|
|
63
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PigeonsClient } from './client.js';
|
|
2
|
+
export type { PigeonsClientConfig } from './client.js';
|
|
3
|
+
export { PigeonsError } from './errors.js';
|
|
4
|
+
export { createEventSource } from './events.js';
|
|
5
|
+
export type { EventSourceOptions } from './events.js';
|
|
6
|
+
export { ApiErrorSchema, ApiKeyCreatedResponseSchema, ApiKeyResponseSchema, AuthTokensSchema, CreateApiKeyRequestSchema, CreateDestinationSchema, CreateRoostSchema, DeliveryAttemptSchema, DeliveryStatusSchema, DestinationSchema, DestinationTypeSchema, LoginRequestSchema, MagicLinkRequestSchema, MagicLinkVerifyRequestSchema, PaginatedDeliveryAttemptsSchema, PaginatedPigeonsSchema, PaginatedResponseSchema, PigeonSchema, ReplayResponseSchema, RoostSchema, SignupRequestSchema, UpdateApiKeyRequestSchema, UpdateRoostSchema, } from './types.js';
|
|
7
|
+
export type { ApiError, ApiKeyCreatedResponse, ApiKeyResponse, AuthTokens, CreateApiKeyRequest, CreateDestination, CreateRoost, DeliveryAttempt, DeliveryStatus, Destination, DestinationType, LoginRequest, MagicLinkRequest, MagicLinkVerifyRequest, PaginatedDeliveryAttempts, PaginatedPigeons, Pigeon, ReplayResponse, Roost, SignupRequest, UpdateApiKeyRequest, UpdateRoost, } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PigeonsClient } from './client.js';
|
|
2
|
+
export { PigeonsError } from './errors.js';
|
|
3
|
+
export { createEventSource } from './events.js';
|
|
4
|
+
// -- Schemas (Zod) --
|
|
5
|
+
export { ApiErrorSchema, ApiKeyCreatedResponseSchema, ApiKeyResponseSchema, AuthTokensSchema, CreateApiKeyRequestSchema, CreateDestinationSchema, CreateRoostSchema, DeliveryAttemptSchema, DeliveryStatusSchema, DestinationSchema, DestinationTypeSchema, LoginRequestSchema, MagicLinkRequestSchema, MagicLinkVerifyRequestSchema, PaginatedDeliveryAttemptsSchema, PaginatedPigeonsSchema, PaginatedResponseSchema, PigeonSchema, ReplayResponseSchema, RoostSchema, SignupRequestSchema, UpdateApiKeyRequestSchema, UpdateRoostSchema, } from './types.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Supported destination types for webhook forwarding. */
|
|
3
|
+
export declare const DestinationTypeSchema: z.ZodEnum<{
|
|
4
|
+
url: "url";
|
|
5
|
+
slack: "slack";
|
|
6
|
+
discord: "discord";
|
|
7
|
+
email: "email";
|
|
8
|
+
}>;
|
|
9
|
+
export type DestinationType = z.infer<typeof DestinationTypeSchema>;
|
|
10
|
+
/** Lifecycle status of a delivery attempt. */
|
|
11
|
+
export declare const DeliveryStatusSchema: z.ZodEnum<{
|
|
12
|
+
pending: "pending";
|
|
13
|
+
delivering: "delivering";
|
|
14
|
+
delivered: "delivered";
|
|
15
|
+
failed: "failed";
|
|
16
|
+
retrying: "retrying";
|
|
17
|
+
}>;
|
|
18
|
+
export type DeliveryStatus = z.infer<typeof DeliveryStatusSchema>;
|
|
19
|
+
/** Token pair returned by authentication endpoints. */
|
|
20
|
+
export declare const AuthTokensSchema: z.ZodObject<{
|
|
21
|
+
access_token: z.ZodString;
|
|
22
|
+
token_type: z.ZodString;
|
|
23
|
+
expires_in: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type AuthTokens = z.infer<typeof AuthTokensSchema>;
|
|
26
|
+
/** Body for `POST /v1/auth/signup`. */
|
|
27
|
+
export declare const SignupRequestSchema: z.ZodObject<{
|
|
28
|
+
email: z.ZodString;
|
|
29
|
+
password: z.ZodString;
|
|
30
|
+
name: z.ZodOptional<z.ZodString>;
|
|
31
|
+
tos_accepted: z.ZodBoolean;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export type SignupRequest = z.infer<typeof SignupRequestSchema>;
|
|
34
|
+
/** Body for `POST /v1/auth/login`. */
|
|
35
|
+
export declare const LoginRequestSchema: z.ZodObject<{
|
|
36
|
+
email: z.ZodString;
|
|
37
|
+
password: z.ZodString;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type LoginRequest = z.infer<typeof LoginRequestSchema>;
|
|
40
|
+
/** Body for `POST /v1/auth/magic-link`. */
|
|
41
|
+
export declare const MagicLinkRequestSchema: z.ZodObject<{
|
|
42
|
+
email: z.ZodString;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type MagicLinkRequest = z.infer<typeof MagicLinkRequestSchema>;
|
|
45
|
+
/** Body for `POST /v1/auth/magic-link/verify`. */
|
|
46
|
+
export declare const MagicLinkVerifyRequestSchema: z.ZodObject<{
|
|
47
|
+
token: z.ZodString;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type MagicLinkVerifyRequest = z.infer<typeof MagicLinkVerifyRequestSchema>;
|
|
50
|
+
/** An authenticated user account. */
|
|
51
|
+
export declare const UserSchema: z.ZodObject<{
|
|
52
|
+
id: z.ZodString;
|
|
53
|
+
email: z.ZodString;
|
|
54
|
+
name: z.ZodString;
|
|
55
|
+
plan: z.ZodString;
|
|
56
|
+
tos_accepted_at: z.ZodNullable<z.ZodString>;
|
|
57
|
+
created_at: z.ZodString;
|
|
58
|
+
updated_at: z.ZodString;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
export type User = z.infer<typeof UserSchema>;
|
|
61
|
+
/** A roost — a webhook endpoint that captures incoming requests. */
|
|
62
|
+
export declare const RoostSchema: z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
description: z.ZodString;
|
|
66
|
+
secret: z.ZodNullable<z.ZodString>;
|
|
67
|
+
is_active: z.ZodBoolean;
|
|
68
|
+
created_at: z.ZodString;
|
|
69
|
+
updated_at: z.ZodString;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export type Roost = z.infer<typeof RoostSchema>;
|
|
72
|
+
/** A captured webhook request. */
|
|
73
|
+
export declare const PigeonSchema: z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
roost_id: z.ZodString;
|
|
76
|
+
source_ip: z.ZodString;
|
|
77
|
+
request_method: z.ZodString;
|
|
78
|
+
content_type: z.ZodString;
|
|
79
|
+
headers: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
80
|
+
body_json: z.ZodNullable<z.ZodUnknown>;
|
|
81
|
+
body_raw: z.ZodNullable<z.ZodArray<z.ZodNumber>>;
|
|
82
|
+
request_query: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
83
|
+
filtered: z.ZodBoolean;
|
|
84
|
+
replayed_from: z.ZodNullable<z.ZodString>;
|
|
85
|
+
delivery_status: z.ZodEnum<{
|
|
86
|
+
pending: "pending";
|
|
87
|
+
delivering: "delivering";
|
|
88
|
+
delivered: "delivered";
|
|
89
|
+
failed: "failed";
|
|
90
|
+
retrying: "retrying";
|
|
91
|
+
}>;
|
|
92
|
+
received_at: z.ZodString;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
export type Pigeon = z.infer<typeof PigeonSchema>;
|
|
95
|
+
/** A forwarding target attached to a roost. */
|
|
96
|
+
export declare const DestinationSchema: z.ZodObject<{
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
roost_id: z.ZodString;
|
|
99
|
+
destination_type: z.ZodEnum<{
|
|
100
|
+
url: "url";
|
|
101
|
+
slack: "slack";
|
|
102
|
+
discord: "discord";
|
|
103
|
+
email: "email";
|
|
104
|
+
}>;
|
|
105
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
106
|
+
filter_expression: z.ZodString;
|
|
107
|
+
template: z.ZodString;
|
|
108
|
+
retry_max: z.ZodNumber;
|
|
109
|
+
retry_delay_ms: z.ZodNumber;
|
|
110
|
+
retry_multiplier: z.ZodNumber;
|
|
111
|
+
is_paused: z.ZodBoolean;
|
|
112
|
+
created_at: z.ZodString;
|
|
113
|
+
updated_at: z.ZodString;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
export type Destination = z.infer<typeof DestinationSchema>;
|
|
116
|
+
/** A single attempt to deliver a pigeon to a destination. */
|
|
117
|
+
export declare const DeliveryAttemptSchema: z.ZodObject<{
|
|
118
|
+
id: z.ZodString;
|
|
119
|
+
pigeon_id: z.ZodString;
|
|
120
|
+
destination_id: z.ZodString;
|
|
121
|
+
status: z.ZodEnum<{
|
|
122
|
+
pending: "pending";
|
|
123
|
+
delivering: "delivering";
|
|
124
|
+
delivered: "delivered";
|
|
125
|
+
failed: "failed";
|
|
126
|
+
retrying: "retrying";
|
|
127
|
+
}>;
|
|
128
|
+
attempt_number: z.ZodNumber;
|
|
129
|
+
response_status: z.ZodNullable<z.ZodNumber>;
|
|
130
|
+
response_body: z.ZodNullable<z.ZodString>;
|
|
131
|
+
error_message: z.ZodNullable<z.ZodString>;
|
|
132
|
+
attempted_at: z.ZodString;
|
|
133
|
+
next_retry_at: z.ZodNullable<z.ZodString>;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
export type DeliveryAttempt = z.infer<typeof DeliveryAttemptSchema>;
|
|
136
|
+
/** An API key (without the full key value). */
|
|
137
|
+
export declare const ApiKeyResponseSchema: z.ZodObject<{
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
key_prefix: z.ZodString;
|
|
140
|
+
name: z.ZodString;
|
|
141
|
+
last_used: z.ZodNullable<z.ZodString>;
|
|
142
|
+
revoked_at: z.ZodNullable<z.ZodString>;
|
|
143
|
+
created_at: z.ZodString;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
export type ApiKeyResponse = z.infer<typeof ApiKeyResponseSchema>;
|
|
146
|
+
/** Response from creating an API key — includes the full key (shown only once). */
|
|
147
|
+
export declare const ApiKeyCreatedResponseSchema: z.ZodObject<{
|
|
148
|
+
id: z.ZodString;
|
|
149
|
+
key: z.ZodString;
|
|
150
|
+
key_prefix: z.ZodString;
|
|
151
|
+
name: z.ZodString;
|
|
152
|
+
created_at: z.ZodString;
|
|
153
|
+
}, z.core.$strip>;
|
|
154
|
+
export type ApiKeyCreatedResponse = z.infer<typeof ApiKeyCreatedResponseSchema>;
|
|
155
|
+
/** Body for `POST /v1/roosts`. */
|
|
156
|
+
export declare const CreateRoostSchema: z.ZodObject<{
|
|
157
|
+
name: z.ZodString;
|
|
158
|
+
description: z.ZodOptional<z.ZodString>;
|
|
159
|
+
secret: z.ZodOptional<z.ZodString>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
export type CreateRoost = z.infer<typeof CreateRoostSchema>;
|
|
162
|
+
/** Body for `PATCH /v1/roosts/:id`. */
|
|
163
|
+
export declare const UpdateRoostSchema: z.ZodObject<{
|
|
164
|
+
name: z.ZodOptional<z.ZodString>;
|
|
165
|
+
description: z.ZodOptional<z.ZodString>;
|
|
166
|
+
secret: z.ZodOptional<z.ZodString>;
|
|
167
|
+
is_active: z.ZodOptional<z.ZodBoolean>;
|
|
168
|
+
}, z.core.$strip>;
|
|
169
|
+
export type UpdateRoost = z.infer<typeof UpdateRoostSchema>;
|
|
170
|
+
/** Body for `POST /v1/roosts/:id/destinations`. */
|
|
171
|
+
export declare const CreateDestinationSchema: z.ZodObject<{
|
|
172
|
+
destination_type: z.ZodEnum<{
|
|
173
|
+
url: "url";
|
|
174
|
+
slack: "slack";
|
|
175
|
+
discord: "discord";
|
|
176
|
+
email: "email";
|
|
177
|
+
}>;
|
|
178
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
179
|
+
filter_expression: z.ZodOptional<z.ZodString>;
|
|
180
|
+
template: z.ZodOptional<z.ZodString>;
|
|
181
|
+
retry_max: z.ZodOptional<z.ZodNumber>;
|
|
182
|
+
retry_delay_ms: z.ZodOptional<z.ZodNumber>;
|
|
183
|
+
retry_multiplier: z.ZodOptional<z.ZodNumber>;
|
|
184
|
+
}, z.core.$strip>;
|
|
185
|
+
export type CreateDestination = z.infer<typeof CreateDestinationSchema>;
|
|
186
|
+
/** Body for `PATCH /v1/me`. */
|
|
187
|
+
export declare const UpdateProfileRequestSchema: z.ZodObject<{
|
|
188
|
+
name: z.ZodOptional<z.ZodString>;
|
|
189
|
+
email: z.ZodOptional<z.ZodString>;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
export type UpdateProfileRequest = z.infer<typeof UpdateProfileRequestSchema>;
|
|
192
|
+
/** Body for `POST /v1/api-keys`. */
|
|
193
|
+
export declare const CreateApiKeyRequestSchema: z.ZodObject<{
|
|
194
|
+
name: z.ZodOptional<z.ZodString>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
export type CreateApiKeyRequest = z.infer<typeof CreateApiKeyRequestSchema>;
|
|
197
|
+
/** Body for `PATCH /v1/api-keys/:id`. */
|
|
198
|
+
export declare const UpdateApiKeyRequestSchema: z.ZodObject<{
|
|
199
|
+
name: z.ZodString;
|
|
200
|
+
}, z.core.$strip>;
|
|
201
|
+
export type UpdateApiKeyRequest = z.infer<typeof UpdateApiKeyRequestSchema>;
|
|
202
|
+
/** Response from `POST /v1/pigeons/:id/replay`. */
|
|
203
|
+
export declare const ReplayResponseSchema: z.ZodObject<{
|
|
204
|
+
replayed: z.ZodBoolean;
|
|
205
|
+
pigeon_id: z.ZodString;
|
|
206
|
+
delivery_attempts: z.ZodNumber;
|
|
207
|
+
}, z.core.$strip>;
|
|
208
|
+
export type ReplayResponse = z.infer<typeof ReplayResponseSchema>;
|
|
209
|
+
/** Aggregated stats for the dashboard overview. */
|
|
210
|
+
export declare const DashboardStatsSchema: z.ZodObject<{
|
|
211
|
+
total_roosts: z.ZodNumber;
|
|
212
|
+
active_roosts: z.ZodNumber;
|
|
213
|
+
total_pigeons: z.ZodNumber;
|
|
214
|
+
pigeons_today: z.ZodNumber;
|
|
215
|
+
delivered: z.ZodNumber;
|
|
216
|
+
failed: z.ZodNumber;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
export type DashboardStats = z.infer<typeof DashboardStatsSchema>;
|
|
219
|
+
/** A reusable template for formatting webhook payloads. */
|
|
220
|
+
export declare const TemplateSchema: z.ZodObject<{
|
|
221
|
+
id: z.ZodString;
|
|
222
|
+
name: z.ZodString;
|
|
223
|
+
description: z.ZodString;
|
|
224
|
+
body: z.ZodString;
|
|
225
|
+
created_at: z.ZodString;
|
|
226
|
+
updated_at: z.ZodString;
|
|
227
|
+
}, z.core.$strip>;
|
|
228
|
+
export type Template = z.infer<typeof TemplateSchema>;
|
|
229
|
+
/** Body for `POST /v1/templates`. */
|
|
230
|
+
export declare const CreateTemplateSchema: z.ZodObject<{
|
|
231
|
+
name: z.ZodString;
|
|
232
|
+
description: z.ZodOptional<z.ZodString>;
|
|
233
|
+
body: z.ZodOptional<z.ZodString>;
|
|
234
|
+
}, z.core.$strip>;
|
|
235
|
+
export type CreateTemplate = z.infer<typeof CreateTemplateSchema>;
|
|
236
|
+
/** Body for `PATCH /v1/templates/:id`. */
|
|
237
|
+
export declare const UpdateTemplateSchema: z.ZodObject<{
|
|
238
|
+
name: z.ZodOptional<z.ZodString>;
|
|
239
|
+
description: z.ZodOptional<z.ZodString>;
|
|
240
|
+
body: z.ZodOptional<z.ZodString>;
|
|
241
|
+
}, z.core.$strip>;
|
|
242
|
+
export type UpdateTemplate = z.infer<typeof UpdateTemplateSchema>;
|
|
243
|
+
/** Body for `POST /v1/templates/preview`. */
|
|
244
|
+
export declare const PreviewTemplateRequestSchema: z.ZodObject<{
|
|
245
|
+
body: z.ZodString;
|
|
246
|
+
pigeon_id: z.ZodString;
|
|
247
|
+
}, z.core.$strip>;
|
|
248
|
+
export type PreviewTemplateRequest = z.infer<typeof PreviewTemplateRequestSchema>;
|
|
249
|
+
/** Response from `POST /v1/templates/preview`. */
|
|
250
|
+
export declare const PreviewTemplateResponseSchema: z.ZodObject<{
|
|
251
|
+
rendered: z.ZodString;
|
|
252
|
+
}, z.core.$strip>;
|
|
253
|
+
export type PreviewTemplateResponse = z.infer<typeof PreviewTemplateResponseSchema>;
|
|
254
|
+
/** Generic paginated response envelope. */
|
|
255
|
+
export declare function PaginatedResponseSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
|
|
256
|
+
data: z.ZodArray<T>;
|
|
257
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
258
|
+
has_more: z.ZodBoolean;
|
|
259
|
+
}, z.core.$strip>;
|
|
260
|
+
export declare const PaginatedPigeonsSchema: z.ZodObject<{
|
|
261
|
+
data: z.ZodArray<z.ZodObject<{
|
|
262
|
+
id: z.ZodString;
|
|
263
|
+
roost_id: z.ZodString;
|
|
264
|
+
source_ip: z.ZodString;
|
|
265
|
+
request_method: z.ZodString;
|
|
266
|
+
content_type: z.ZodString;
|
|
267
|
+
headers: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
268
|
+
body_json: z.ZodNullable<z.ZodUnknown>;
|
|
269
|
+
body_raw: z.ZodNullable<z.ZodArray<z.ZodNumber>>;
|
|
270
|
+
request_query: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
271
|
+
filtered: z.ZodBoolean;
|
|
272
|
+
replayed_from: z.ZodNullable<z.ZodString>;
|
|
273
|
+
delivery_status: z.ZodEnum<{
|
|
274
|
+
pending: "pending";
|
|
275
|
+
delivering: "delivering";
|
|
276
|
+
delivered: "delivered";
|
|
277
|
+
failed: "failed";
|
|
278
|
+
retrying: "retrying";
|
|
279
|
+
}>;
|
|
280
|
+
received_at: z.ZodString;
|
|
281
|
+
}, z.core.$strip>>;
|
|
282
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
283
|
+
has_more: z.ZodBoolean;
|
|
284
|
+
}, z.core.$strip>;
|
|
285
|
+
export type PaginatedPigeons = z.infer<typeof PaginatedPigeonsSchema>;
|
|
286
|
+
export declare const PaginatedDeliveryAttemptsSchema: z.ZodObject<{
|
|
287
|
+
data: z.ZodArray<z.ZodObject<{
|
|
288
|
+
id: z.ZodString;
|
|
289
|
+
pigeon_id: z.ZodString;
|
|
290
|
+
destination_id: z.ZodString;
|
|
291
|
+
status: z.ZodEnum<{
|
|
292
|
+
pending: "pending";
|
|
293
|
+
delivering: "delivering";
|
|
294
|
+
delivered: "delivered";
|
|
295
|
+
failed: "failed";
|
|
296
|
+
retrying: "retrying";
|
|
297
|
+
}>;
|
|
298
|
+
attempt_number: z.ZodNumber;
|
|
299
|
+
response_status: z.ZodNullable<z.ZodNumber>;
|
|
300
|
+
response_body: z.ZodNullable<z.ZodString>;
|
|
301
|
+
error_message: z.ZodNullable<z.ZodString>;
|
|
302
|
+
attempted_at: z.ZodString;
|
|
303
|
+
next_retry_at: z.ZodNullable<z.ZodString>;
|
|
304
|
+
}, z.core.$strip>>;
|
|
305
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
306
|
+
has_more: z.ZodBoolean;
|
|
307
|
+
}, z.core.$strip>;
|
|
308
|
+
export type PaginatedDeliveryAttempts = z.infer<typeof PaginatedDeliveryAttemptsSchema>;
|
|
309
|
+
export declare const BillingLimitsSchema: z.ZodObject<{
|
|
310
|
+
pigeons_per_month: z.ZodNumber;
|
|
311
|
+
max_roosts: z.ZodNumber;
|
|
312
|
+
api_per_minute: z.ZodNumber;
|
|
313
|
+
inbound_per_second: z.ZodNumber;
|
|
314
|
+
email_per_month: z.ZodNumber;
|
|
315
|
+
}, z.core.$strip>;
|
|
316
|
+
export type BillingLimits = z.infer<typeof BillingLimitsSchema>;
|
|
317
|
+
export declare const BillingStatusSchema: z.ZodObject<{
|
|
318
|
+
plan: z.ZodString;
|
|
319
|
+
subscription_status: z.ZodString;
|
|
320
|
+
billing_period_start: z.ZodNullable<z.ZodString>;
|
|
321
|
+
billing_period_end: z.ZodNullable<z.ZodString>;
|
|
322
|
+
usage_count: z.ZodNumber;
|
|
323
|
+
limits: z.ZodObject<{
|
|
324
|
+
pigeons_per_month: z.ZodNumber;
|
|
325
|
+
max_roosts: z.ZodNumber;
|
|
326
|
+
api_per_minute: z.ZodNumber;
|
|
327
|
+
inbound_per_second: z.ZodNumber;
|
|
328
|
+
email_per_month: z.ZodNumber;
|
|
329
|
+
}, z.core.$strip>;
|
|
330
|
+
}, z.core.$strip>;
|
|
331
|
+
export type BillingStatus = z.infer<typeof BillingStatusSchema>;
|
|
332
|
+
export declare const CheckoutRequestSchema: z.ZodObject<{
|
|
333
|
+
price_id: z.ZodString;
|
|
334
|
+
success_url: z.ZodString;
|
|
335
|
+
cancel_url: z.ZodString;
|
|
336
|
+
}, z.core.$strip>;
|
|
337
|
+
export type CheckoutRequest = z.infer<typeof CheckoutRequestSchema>;
|
|
338
|
+
export declare const CheckoutResponseSchema: z.ZodObject<{
|
|
339
|
+
checkout_url: z.ZodString;
|
|
340
|
+
}, z.core.$strip>;
|
|
341
|
+
export type CheckoutResponse = z.infer<typeof CheckoutResponseSchema>;
|
|
342
|
+
export declare const PortalRequestSchema: z.ZodObject<{
|
|
343
|
+
return_url: z.ZodString;
|
|
344
|
+
}, z.core.$strip>;
|
|
345
|
+
export type PortalRequest = z.infer<typeof PortalRequestSchema>;
|
|
346
|
+
export declare const PortalResponseSchema: z.ZodObject<{
|
|
347
|
+
portal_url: z.ZodString;
|
|
348
|
+
}, z.core.$strip>;
|
|
349
|
+
export type PortalResponse = z.infer<typeof PortalResponseSchema>;
|
|
350
|
+
/** Error body returned by the API on non-2xx responses. */
|
|
351
|
+
export declare const ApiErrorSchema: z.ZodObject<{
|
|
352
|
+
error: z.ZodString;
|
|
353
|
+
status: z.ZodNumber;
|
|
354
|
+
}, z.core.$strip>;
|
|
355
|
+
export type ApiError = z.infer<typeof ApiErrorSchema>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Supported destination types for webhook forwarding. */
|
|
3
|
+
export const DestinationTypeSchema = z.enum(['url', 'slack', 'discord', 'email']);
|
|
4
|
+
/** Lifecycle status of a delivery attempt. */
|
|
5
|
+
export const DeliveryStatusSchema = z.enum([
|
|
6
|
+
'pending',
|
|
7
|
+
'delivering',
|
|
8
|
+
'delivered',
|
|
9
|
+
'failed',
|
|
10
|
+
'retrying',
|
|
11
|
+
]);
|
|
12
|
+
/** Token pair returned by authentication endpoints. */
|
|
13
|
+
export const AuthTokensSchema = z.object({
|
|
14
|
+
access_token: z.string(),
|
|
15
|
+
token_type: z.string(),
|
|
16
|
+
expires_in: z.number(),
|
|
17
|
+
});
|
|
18
|
+
/** Body for `POST /v1/auth/signup`. */
|
|
19
|
+
export const SignupRequestSchema = z.object({
|
|
20
|
+
email: z.string(),
|
|
21
|
+
password: z.string(),
|
|
22
|
+
name: z.string().optional(),
|
|
23
|
+
tos_accepted: z.boolean(),
|
|
24
|
+
});
|
|
25
|
+
/** Body for `POST /v1/auth/login`. */
|
|
26
|
+
export const LoginRequestSchema = z.object({
|
|
27
|
+
email: z.string(),
|
|
28
|
+
password: z.string(),
|
|
29
|
+
});
|
|
30
|
+
/** Body for `POST /v1/auth/magic-link`. */
|
|
31
|
+
export const MagicLinkRequestSchema = z.object({
|
|
32
|
+
email: z.string(),
|
|
33
|
+
});
|
|
34
|
+
/** Body for `POST /v1/auth/magic-link/verify`. */
|
|
35
|
+
export const MagicLinkVerifyRequestSchema = z.object({
|
|
36
|
+
token: z.string(),
|
|
37
|
+
});
|
|
38
|
+
/** An authenticated user account. */
|
|
39
|
+
export const UserSchema = z.object({
|
|
40
|
+
id: z.string(),
|
|
41
|
+
email: z.string(),
|
|
42
|
+
name: z.string(),
|
|
43
|
+
plan: z.string(),
|
|
44
|
+
tos_accepted_at: z.string().nullable(),
|
|
45
|
+
created_at: z.string(),
|
|
46
|
+
updated_at: z.string(),
|
|
47
|
+
});
|
|
48
|
+
/** A roost — a webhook endpoint that captures incoming requests. */
|
|
49
|
+
export const RoostSchema = z.object({
|
|
50
|
+
id: z.string(),
|
|
51
|
+
name: z.string(),
|
|
52
|
+
description: z.string(),
|
|
53
|
+
secret: z.string().nullable(),
|
|
54
|
+
is_active: z.boolean(),
|
|
55
|
+
created_at: z.string(),
|
|
56
|
+
updated_at: z.string(),
|
|
57
|
+
});
|
|
58
|
+
/** A captured webhook request. */
|
|
59
|
+
export const PigeonSchema = z.object({
|
|
60
|
+
id: z.string(),
|
|
61
|
+
roost_id: z.string(),
|
|
62
|
+
source_ip: z.string(),
|
|
63
|
+
request_method: z.string(),
|
|
64
|
+
content_type: z.string(),
|
|
65
|
+
headers: z.record(z.string(), z.unknown()),
|
|
66
|
+
body_json: z.unknown().nullable(),
|
|
67
|
+
body_raw: z.array(z.number()).nullable(),
|
|
68
|
+
request_query: z.record(z.string(), z.unknown()).nullable(),
|
|
69
|
+
filtered: z.boolean(),
|
|
70
|
+
replayed_from: z.string().nullable(),
|
|
71
|
+
delivery_status: DeliveryStatusSchema,
|
|
72
|
+
received_at: z.string(),
|
|
73
|
+
});
|
|
74
|
+
/** A forwarding target attached to a roost. */
|
|
75
|
+
export const DestinationSchema = z.object({
|
|
76
|
+
id: z.string(),
|
|
77
|
+
roost_id: z.string(),
|
|
78
|
+
destination_type: DestinationTypeSchema,
|
|
79
|
+
config: z.record(z.string(), z.unknown()),
|
|
80
|
+
filter_expression: z.string(),
|
|
81
|
+
template: z.string(),
|
|
82
|
+
retry_max: z.number(),
|
|
83
|
+
retry_delay_ms: z.number(),
|
|
84
|
+
retry_multiplier: z.number(),
|
|
85
|
+
is_paused: z.boolean(),
|
|
86
|
+
created_at: z.string(),
|
|
87
|
+
updated_at: z.string(),
|
|
88
|
+
});
|
|
89
|
+
/** A single attempt to deliver a pigeon to a destination. */
|
|
90
|
+
export const DeliveryAttemptSchema = z.object({
|
|
91
|
+
id: z.string(),
|
|
92
|
+
pigeon_id: z.string(),
|
|
93
|
+
destination_id: z.string(),
|
|
94
|
+
status: DeliveryStatusSchema,
|
|
95
|
+
attempt_number: z.number(),
|
|
96
|
+
response_status: z.number().nullable(),
|
|
97
|
+
response_body: z.string().nullable(),
|
|
98
|
+
error_message: z.string().nullable(),
|
|
99
|
+
attempted_at: z.string(),
|
|
100
|
+
next_retry_at: z.string().nullable(),
|
|
101
|
+
});
|
|
102
|
+
/** An API key (without the full key value). */
|
|
103
|
+
export const ApiKeyResponseSchema = z.object({
|
|
104
|
+
id: z.string(),
|
|
105
|
+
key_prefix: z.string(),
|
|
106
|
+
name: z.string(),
|
|
107
|
+
last_used: z.string().nullable(),
|
|
108
|
+
revoked_at: z.string().nullable(),
|
|
109
|
+
created_at: z.string(),
|
|
110
|
+
});
|
|
111
|
+
/** Response from creating an API key — includes the full key (shown only once). */
|
|
112
|
+
export const ApiKeyCreatedResponseSchema = z.object({
|
|
113
|
+
id: z.string(),
|
|
114
|
+
key: z.string(),
|
|
115
|
+
key_prefix: z.string(),
|
|
116
|
+
name: z.string(),
|
|
117
|
+
created_at: z.string(),
|
|
118
|
+
});
|
|
119
|
+
/** Body for `POST /v1/roosts`. */
|
|
120
|
+
export const CreateRoostSchema = z.object({
|
|
121
|
+
name: z.string(),
|
|
122
|
+
description: z.string().optional(),
|
|
123
|
+
secret: z.string().optional(),
|
|
124
|
+
});
|
|
125
|
+
/** Body for `PATCH /v1/roosts/:id`. */
|
|
126
|
+
export const UpdateRoostSchema = z.object({
|
|
127
|
+
name: z.string().optional(),
|
|
128
|
+
description: z.string().optional(),
|
|
129
|
+
secret: z.string().optional(),
|
|
130
|
+
is_active: z.boolean().optional(),
|
|
131
|
+
});
|
|
132
|
+
/** Body for `POST /v1/roosts/:id/destinations`. */
|
|
133
|
+
export const CreateDestinationSchema = z.object({
|
|
134
|
+
destination_type: DestinationTypeSchema,
|
|
135
|
+
config: z.record(z.string(), z.unknown()).optional(),
|
|
136
|
+
filter_expression: z.string().optional(),
|
|
137
|
+
template: z.string().optional(),
|
|
138
|
+
retry_max: z.number().optional(),
|
|
139
|
+
retry_delay_ms: z.number().optional(),
|
|
140
|
+
retry_multiplier: z.number().optional(),
|
|
141
|
+
});
|
|
142
|
+
/** Body for `PATCH /v1/me`. */
|
|
143
|
+
export const UpdateProfileRequestSchema = z.object({
|
|
144
|
+
name: z.string().optional(),
|
|
145
|
+
email: z.string().optional(),
|
|
146
|
+
});
|
|
147
|
+
/** Body for `POST /v1/api-keys`. */
|
|
148
|
+
export const CreateApiKeyRequestSchema = z.object({
|
|
149
|
+
name: z.string().optional(),
|
|
150
|
+
});
|
|
151
|
+
/** Body for `PATCH /v1/api-keys/:id`. */
|
|
152
|
+
export const UpdateApiKeyRequestSchema = z.object({
|
|
153
|
+
name: z.string(),
|
|
154
|
+
});
|
|
155
|
+
/** Response from `POST /v1/pigeons/:id/replay`. */
|
|
156
|
+
export const ReplayResponseSchema = z.object({
|
|
157
|
+
replayed: z.boolean(),
|
|
158
|
+
pigeon_id: z.string(),
|
|
159
|
+
delivery_attempts: z.number(),
|
|
160
|
+
});
|
|
161
|
+
/** Aggregated stats for the dashboard overview. */
|
|
162
|
+
export const DashboardStatsSchema = z.object({
|
|
163
|
+
total_roosts: z.number(),
|
|
164
|
+
active_roosts: z.number(),
|
|
165
|
+
total_pigeons: z.number(),
|
|
166
|
+
pigeons_today: z.number(),
|
|
167
|
+
delivered: z.number(),
|
|
168
|
+
failed: z.number(),
|
|
169
|
+
});
|
|
170
|
+
/** A reusable template for formatting webhook payloads. */
|
|
171
|
+
export const TemplateSchema = z.object({
|
|
172
|
+
id: z.string(),
|
|
173
|
+
name: z.string(),
|
|
174
|
+
description: z.string(),
|
|
175
|
+
body: z.string(),
|
|
176
|
+
created_at: z.string(),
|
|
177
|
+
updated_at: z.string(),
|
|
178
|
+
});
|
|
179
|
+
/** Body for `POST /v1/templates`. */
|
|
180
|
+
export const CreateTemplateSchema = z.object({
|
|
181
|
+
name: z.string(),
|
|
182
|
+
description: z.string().optional(),
|
|
183
|
+
body: z.string().optional(),
|
|
184
|
+
});
|
|
185
|
+
/** Body for `PATCH /v1/templates/:id`. */
|
|
186
|
+
export const UpdateTemplateSchema = z.object({
|
|
187
|
+
name: z.string().optional(),
|
|
188
|
+
description: z.string().optional(),
|
|
189
|
+
body: z.string().optional(),
|
|
190
|
+
});
|
|
191
|
+
/** Body for `POST /v1/templates/preview`. */
|
|
192
|
+
export const PreviewTemplateRequestSchema = z.object({
|
|
193
|
+
body: z.string(),
|
|
194
|
+
pigeon_id: z.string(),
|
|
195
|
+
});
|
|
196
|
+
/** Response from `POST /v1/templates/preview`. */
|
|
197
|
+
export const PreviewTemplateResponseSchema = z.object({
|
|
198
|
+
rendered: z.string(),
|
|
199
|
+
});
|
|
200
|
+
/** Generic paginated response envelope. */
|
|
201
|
+
export function PaginatedResponseSchema(itemSchema) {
|
|
202
|
+
return z.object({
|
|
203
|
+
data: z.array(itemSchema),
|
|
204
|
+
next_cursor: z.string().nullable(),
|
|
205
|
+
has_more: z.boolean(),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
export const PaginatedPigeonsSchema = PaginatedResponseSchema(PigeonSchema);
|
|
209
|
+
export const PaginatedDeliveryAttemptsSchema = PaginatedResponseSchema(DeliveryAttemptSchema);
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Billing
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
export const BillingLimitsSchema = z.object({
|
|
214
|
+
pigeons_per_month: z.number(),
|
|
215
|
+
max_roosts: z.number(),
|
|
216
|
+
api_per_minute: z.number(),
|
|
217
|
+
inbound_per_second: z.number(),
|
|
218
|
+
email_per_month: z.number(),
|
|
219
|
+
});
|
|
220
|
+
export const BillingStatusSchema = z.object({
|
|
221
|
+
plan: z.string(),
|
|
222
|
+
subscription_status: z.string(),
|
|
223
|
+
billing_period_start: z.string().nullable(),
|
|
224
|
+
billing_period_end: z.string().nullable(),
|
|
225
|
+
usage_count: z.number(),
|
|
226
|
+
limits: BillingLimitsSchema,
|
|
227
|
+
});
|
|
228
|
+
export const CheckoutRequestSchema = z.object({
|
|
229
|
+
price_id: z.string(),
|
|
230
|
+
success_url: z.string(),
|
|
231
|
+
cancel_url: z.string(),
|
|
232
|
+
});
|
|
233
|
+
export const CheckoutResponseSchema = z.object({
|
|
234
|
+
checkout_url: z.string(),
|
|
235
|
+
});
|
|
236
|
+
export const PortalRequestSchema = z.object({
|
|
237
|
+
return_url: z.string(),
|
|
238
|
+
});
|
|
239
|
+
export const PortalResponseSchema = z.object({
|
|
240
|
+
portal_url: z.string(),
|
|
241
|
+
});
|
|
242
|
+
/** Error body returned by the API on non-2xx responses. */
|
|
243
|
+
export const ApiErrorSchema = z.object({
|
|
244
|
+
error: z.string(),
|
|
245
|
+
status: z.number(),
|
|
246
|
+
});
|