@nestuge/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.
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/index.cjs +583 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.js +534 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
2
|
+
interface RequestorConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
maxRetries: number;
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
fetch: FetchLike;
|
|
8
|
+
}
|
|
9
|
+
interface RequestOptions {
|
|
10
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
11
|
+
/** Contract path, e.g. `/v1/customers/{id}` with params already interpolated. */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Shallow object of query params; undefined values are omitted. */
|
|
14
|
+
query?: object;
|
|
15
|
+
body?: unknown;
|
|
16
|
+
}
|
|
17
|
+
declare class Requestor {
|
|
18
|
+
private readonly config;
|
|
19
|
+
constructor(config: RequestorConfig);
|
|
20
|
+
/** Performs a request against the Dev API and returns the unwrapped `data`. */
|
|
21
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
22
|
+
private buildUrl;
|
|
23
|
+
private dispatch;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Whether the API key (and therefore the request) is live or test mode. */
|
|
27
|
+
type Mode = 'live' | 'test';
|
|
28
|
+
/** One page of a cursor-paginated list. */
|
|
29
|
+
interface Page<T> {
|
|
30
|
+
items: T[];
|
|
31
|
+
hasMore: boolean;
|
|
32
|
+
nextCursor: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** Standard cursor-pagination query parameters. */
|
|
35
|
+
interface ListParams {
|
|
36
|
+
/** Page size, 1–100. Defaults to 20 on the server. */
|
|
37
|
+
limit?: number;
|
|
38
|
+
/** Opaque cursor from a prior page's `nextCursor`. Omit for the first page. */
|
|
39
|
+
cursor?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Response of `nestuge.ping()`. */
|
|
42
|
+
interface PingResponse {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
brandID: string;
|
|
45
|
+
mode: Mode;
|
|
46
|
+
scopes: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A hub member (membership) of the brand. */
|
|
50
|
+
interface Customer {
|
|
51
|
+
membershipId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
email: string;
|
|
54
|
+
phone: string | null;
|
|
55
|
+
hubID: string;
|
|
56
|
+
status: string;
|
|
57
|
+
plan: string;
|
|
58
|
+
joinedAt: string;
|
|
59
|
+
}
|
|
60
|
+
interface CustomerListParams extends ListParams {
|
|
61
|
+
/** Restrict results to a single hub. */
|
|
62
|
+
hubID?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class Customers {
|
|
66
|
+
private readonly requestor;
|
|
67
|
+
constructor(requestor: Requestor);
|
|
68
|
+
/** Lists the brand's hub members, newest first. Requires `customers:read`. */
|
|
69
|
+
list(params?: CustomerListParams): Promise<Page<Customer>>;
|
|
70
|
+
/** Returns a single hub membership by its membership id. */
|
|
71
|
+
retrieve(id: string): Promise<Customer>;
|
|
72
|
+
/** Iterates every customer, following pagination cursors automatically. */
|
|
73
|
+
iterate(params?: Omit<CustomerListParams, 'cursor'>): AsyncGenerator<Customer>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A hub community/calendar event. */
|
|
77
|
+
interface HubEvent {
|
|
78
|
+
id: string;
|
|
79
|
+
hubID: string;
|
|
80
|
+
hubName: string;
|
|
81
|
+
title: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
date: string;
|
|
84
|
+
endDate?: string;
|
|
85
|
+
time?: {
|
|
86
|
+
start?: string;
|
|
87
|
+
end?: string;
|
|
88
|
+
};
|
|
89
|
+
timezone?: string;
|
|
90
|
+
type?: string;
|
|
91
|
+
venue?: string | null;
|
|
92
|
+
meetLink?: string;
|
|
93
|
+
attendeeStatus?: string;
|
|
94
|
+
}
|
|
95
|
+
interface CreateEventParams {
|
|
96
|
+
/** The hub to create the event in. Must belong to the authenticated brand. */
|
|
97
|
+
hubID: string;
|
|
98
|
+
title: string;
|
|
99
|
+
description: string;
|
|
100
|
+
/** ISO 8601 date. */
|
|
101
|
+
date: string;
|
|
102
|
+
endDate?: string;
|
|
103
|
+
time: {
|
|
104
|
+
start: string;
|
|
105
|
+
end: string;
|
|
106
|
+
};
|
|
107
|
+
timezone?: string;
|
|
108
|
+
type: string;
|
|
109
|
+
venue?: string | null;
|
|
110
|
+
meetLink?: string;
|
|
111
|
+
audience?: string;
|
|
112
|
+
tier?: string | null;
|
|
113
|
+
targetedGroupIDs?: string[];
|
|
114
|
+
isAllDay?: boolean;
|
|
115
|
+
repeat?: string;
|
|
116
|
+
reminder: string;
|
|
117
|
+
color: string;
|
|
118
|
+
sendNotification: boolean;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare class Events {
|
|
122
|
+
private readonly requestor;
|
|
123
|
+
constructor(requestor: Requestor);
|
|
124
|
+
/** Lists the brand's hub community events, newest first. Requires `events:read`. */
|
|
125
|
+
list(params?: ListParams): Promise<Page<HubEvent>>;
|
|
126
|
+
/** Returns a single hub event owned by the brand. */
|
|
127
|
+
retrieve(id: string): Promise<HubEvent>;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a hub event in one of the brand's hubs. Requires `events:write`
|
|
130
|
+
* and the brand to have Google Calendar connected.
|
|
131
|
+
*/
|
|
132
|
+
create(params: CreateEventParams): Promise<HubEvent>;
|
|
133
|
+
/** Iterates every event, following pagination cursors automatically. */
|
|
134
|
+
iterate(): AsyncGenerator<HubEvent>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface ProductEventDetails {
|
|
138
|
+
eventType: string | null;
|
|
139
|
+
venue: string | null;
|
|
140
|
+
dateTime: string | null;
|
|
141
|
+
endDate: string | null;
|
|
142
|
+
}
|
|
143
|
+
interface Product {
|
|
144
|
+
id: string;
|
|
145
|
+
type: string;
|
|
146
|
+
status: string;
|
|
147
|
+
title: string;
|
|
148
|
+
description: string;
|
|
149
|
+
imageUrl: string | null;
|
|
150
|
+
url: string;
|
|
151
|
+
visibility: string | null;
|
|
152
|
+
isFree: boolean;
|
|
153
|
+
keywords: string[];
|
|
154
|
+
createdAt: string;
|
|
155
|
+
updatedAt: string;
|
|
156
|
+
event: ProductEventDetails | null;
|
|
157
|
+
}
|
|
158
|
+
interface Money {
|
|
159
|
+
amount: number;
|
|
160
|
+
/** ISO 4217 code, e.g. "NGN". */
|
|
161
|
+
currency: string;
|
|
162
|
+
}
|
|
163
|
+
/** A pricing tier (payment plan) of a product. */
|
|
164
|
+
interface ProductTier {
|
|
165
|
+
id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
/** Plan type, e.g. "onetime", "recurring", "installment". */
|
|
168
|
+
type: string | null;
|
|
169
|
+
price: Money;
|
|
170
|
+
discount: Money | null;
|
|
171
|
+
recurrence: {
|
|
172
|
+
/** Billing period, e.g. "monthly", "yearly". */
|
|
173
|
+
periodic: string;
|
|
174
|
+
count: number | null;
|
|
175
|
+
interval: number | null;
|
|
176
|
+
} | null;
|
|
177
|
+
perks: string[];
|
|
178
|
+
buttonText: string | null;
|
|
179
|
+
/** ISO 8601 date-time the tier stops being purchasable, if set. */
|
|
180
|
+
timeBound: string | null;
|
|
181
|
+
/** Total purchasable slots, if capped. */
|
|
182
|
+
slots: number | null;
|
|
183
|
+
noOfTickets: number | null;
|
|
184
|
+
/** IDs of the product items this tier grants access to. */
|
|
185
|
+
itemIDs: string[];
|
|
186
|
+
isDefault: boolean;
|
|
187
|
+
status: string | null;
|
|
188
|
+
archived: boolean;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A content item attached to a product. Descriptive fields only — the
|
|
192
|
+
* deliverable itself (links, files) is never exposed through the API.
|
|
193
|
+
*/
|
|
194
|
+
interface ProductItem {
|
|
195
|
+
id: string;
|
|
196
|
+
type: string | null;
|
|
197
|
+
title: string;
|
|
198
|
+
description: string | null;
|
|
199
|
+
image: string | null;
|
|
200
|
+
duration: number | null;
|
|
201
|
+
isAddon: boolean;
|
|
202
|
+
parentId: string | null;
|
|
203
|
+
price: Money | null;
|
|
204
|
+
}
|
|
205
|
+
/** Returned by `products.retrieve`: the product plus its tiers and items. */
|
|
206
|
+
interface ProductDetail extends Product {
|
|
207
|
+
tiers: ProductTier[];
|
|
208
|
+
items: ProductItem[];
|
|
209
|
+
}
|
|
210
|
+
type ProductType = 'custom' | 'event' | 'booking';
|
|
211
|
+
type ProductVisibility = 'public' | 'private' | 'invite-only';
|
|
212
|
+
type ProductEventType = 'Zoom' | 'Online' | 'In-Person' | 'Google Meet';
|
|
213
|
+
interface CreateProductParams {
|
|
214
|
+
type: ProductType;
|
|
215
|
+
/** 6–80 characters. */
|
|
216
|
+
title: string;
|
|
217
|
+
description: string;
|
|
218
|
+
/** HTTPS URL. */
|
|
219
|
+
imageUrl: string;
|
|
220
|
+
visibility?: ProductVisibility;
|
|
221
|
+
/** Set `isFree: true` or provide `price` — exactly one of the two. */
|
|
222
|
+
isFree?: boolean;
|
|
223
|
+
price?: {
|
|
224
|
+
amount: number;
|
|
225
|
+
/** ISO 4217 code, e.g. "NGN". */
|
|
226
|
+
currency: string;
|
|
227
|
+
};
|
|
228
|
+
/** Max 300 characters. */
|
|
229
|
+
refundPolicy?: string;
|
|
230
|
+
/** Required when `type` is `event`. `venue` is required for In-Person events. */
|
|
231
|
+
event?: {
|
|
232
|
+
eventType: ProductEventType;
|
|
233
|
+
/** ISO 8601 date-time. */
|
|
234
|
+
dateTime: string;
|
|
235
|
+
venue?: string | null;
|
|
236
|
+
endDate?: string | null;
|
|
237
|
+
};
|
|
238
|
+
/** Required when `type` is `booking`. */
|
|
239
|
+
booking?: {
|
|
240
|
+
/** Minutes, minimum 15. */
|
|
241
|
+
bookingDuration: number;
|
|
242
|
+
/** IANA timezone, e.g. "Africa/Lagos". */
|
|
243
|
+
timezone: string;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
declare class Products {
|
|
248
|
+
private readonly requestor;
|
|
249
|
+
constructor(requestor: Requestor);
|
|
250
|
+
/** Lists the brand's products (all types), newest first. Requires `products:read`. */
|
|
251
|
+
list(params?: ListParams): Promise<Page<Product>>;
|
|
252
|
+
/**
|
|
253
|
+
* Returns a single product owned by the brand, including its pricing
|
|
254
|
+
* tiers and content items.
|
|
255
|
+
*/
|
|
256
|
+
retrieve(id: string): Promise<ProductDetail>;
|
|
257
|
+
/**
|
|
258
|
+
* Creates a draft product. Requires `products:write`. Test-mode keys
|
|
259
|
+
* validate and return a preview without persisting.
|
|
260
|
+
*/
|
|
261
|
+
create(params: CreateProductParams): Promise<Product>;
|
|
262
|
+
/** Iterates every product, following pagination cursors automatically. */
|
|
263
|
+
iterate(): AsyncGenerator<Product>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface Purchase {
|
|
267
|
+
id: string;
|
|
268
|
+
productId: string;
|
|
269
|
+
title: string;
|
|
270
|
+
status: string;
|
|
271
|
+
productType: string | null;
|
|
272
|
+
planName: string | null;
|
|
273
|
+
customer: {
|
|
274
|
+
name: string;
|
|
275
|
+
email: string;
|
|
276
|
+
};
|
|
277
|
+
country: string | null;
|
|
278
|
+
paid: boolean;
|
|
279
|
+
purchasedOn: string;
|
|
280
|
+
ticketID: string | null;
|
|
281
|
+
certificateID: string | null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
declare class Purchases {
|
|
285
|
+
private readonly requestor;
|
|
286
|
+
constructor(requestor: Requestor);
|
|
287
|
+
/** Lists the brand's purchases/orders, newest first. Requires `purchases:read`. */
|
|
288
|
+
list(params?: ListParams): Promise<Page<Purchase>>;
|
|
289
|
+
/** Returns a single purchase/order by id. */
|
|
290
|
+
retrieve(id: string): Promise<Purchase>;
|
|
291
|
+
/** Iterates every purchase, following pagination cursors automatically. */
|
|
292
|
+
iterate(): AsyncGenerator<Purchase>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface Ticket {
|
|
296
|
+
ticketID: string;
|
|
297
|
+
eventName: string;
|
|
298
|
+
ticketName: string | null;
|
|
299
|
+
date: string | null;
|
|
300
|
+
venue: string | null;
|
|
301
|
+
purchaseID: string;
|
|
302
|
+
attendee: {
|
|
303
|
+
name: string;
|
|
304
|
+
email: string;
|
|
305
|
+
};
|
|
306
|
+
isCheckedIn: boolean;
|
|
307
|
+
checkinTime: string | null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare class Tickets {
|
|
311
|
+
private readonly requestor;
|
|
312
|
+
constructor(requestor: Requestor);
|
|
313
|
+
/** Returns a single event ticket by ticket id. Requires `purchases:read`. */
|
|
314
|
+
retrieve(id: string): Promise<Ticket>;
|
|
315
|
+
/**
|
|
316
|
+
* Checks in an event attendee by ticket id. Requires `purchases:write`.
|
|
317
|
+
* Test-mode keys validate and return the checked-in ticket without persisting.
|
|
318
|
+
*/
|
|
319
|
+
checkIn(id: string): Promise<Ticket>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
interface Transaction {
|
|
323
|
+
/** Transaction reference — also the id used with `transactions.retrieve()`. */
|
|
324
|
+
txref: string;
|
|
325
|
+
type: string;
|
|
326
|
+
status: string;
|
|
327
|
+
amount: number;
|
|
328
|
+
currency: string;
|
|
329
|
+
customer: {
|
|
330
|
+
name: string;
|
|
331
|
+
email: string;
|
|
332
|
+
};
|
|
333
|
+
createdAt: string;
|
|
334
|
+
resourceID: string | null;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
declare class Transactions {
|
|
338
|
+
private readonly requestor;
|
|
339
|
+
constructor(requestor: Requestor);
|
|
340
|
+
/** Lists the brand's transactions, newest first. Requires `transactions:read`. */
|
|
341
|
+
list(params?: ListParams): Promise<Page<Transaction>>;
|
|
342
|
+
/** Returns a single transaction by its reference (`txref`). */
|
|
343
|
+
retrieve(id: string): Promise<Transaction>;
|
|
344
|
+
/** Iterates every transaction, following pagination cursors automatically. */
|
|
345
|
+
iterate(): AsyncGenerator<Transaction>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
type WebhookEventType = 'transaction.succeeded' | 'transaction.failed' | 'payout.settled' | 'subscription.renewed' | 'subscription.expired' | 'subscription.completed' | 'member.joined' | 'member.removed';
|
|
349
|
+
type WebhookEndpointStatus = 'active' | 'disabled';
|
|
350
|
+
interface WebhookEndpoint {
|
|
351
|
+
id: string;
|
|
352
|
+
url: string;
|
|
353
|
+
events: WebhookEventType[];
|
|
354
|
+
status: WebhookEndpointStatus;
|
|
355
|
+
description: string | null;
|
|
356
|
+
createdAt: string;
|
|
357
|
+
updatedAt: string;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Returned only by `webhooks.create()`. The `signingSecret` is shown once and
|
|
361
|
+
* can never be retrieved again — store it securely.
|
|
362
|
+
*/
|
|
363
|
+
interface WebhookEndpointWithSecret extends WebhookEndpoint {
|
|
364
|
+
signingSecret: string;
|
|
365
|
+
}
|
|
366
|
+
interface CreateWebhookParams {
|
|
367
|
+
/** HTTPS URL to deliver events to. */
|
|
368
|
+
url: string;
|
|
369
|
+
/** At least one event type. */
|
|
370
|
+
events: WebhookEventType[];
|
|
371
|
+
/** Max 200 characters. */
|
|
372
|
+
description?: string;
|
|
373
|
+
}
|
|
374
|
+
interface UpdateWebhookParams {
|
|
375
|
+
url?: string;
|
|
376
|
+
events?: WebhookEventType[];
|
|
377
|
+
status?: WebhookEndpointStatus;
|
|
378
|
+
description?: string | null;
|
|
379
|
+
}
|
|
380
|
+
interface TestWebhookParams {
|
|
381
|
+
eventType: WebhookEventType;
|
|
382
|
+
/** Limit the test delivery to a single endpoint. */
|
|
383
|
+
endpointID?: string;
|
|
384
|
+
}
|
|
385
|
+
type WebhookResourceType = 'transaction' | 'purchase' | 'member';
|
|
386
|
+
type WebhookDeliveryStatus = 'pending' | 'success' | 'failed';
|
|
387
|
+
interface WebhookDelivery {
|
|
388
|
+
id: string;
|
|
389
|
+
endpointID: string;
|
|
390
|
+
eventType: WebhookEventType;
|
|
391
|
+
resourceType: WebhookResourceType;
|
|
392
|
+
resourceID: string;
|
|
393
|
+
status: WebhookDeliveryStatus;
|
|
394
|
+
attempts: number;
|
|
395
|
+
responseCode: number | null;
|
|
396
|
+
mode: Mode;
|
|
397
|
+
createdAt: string;
|
|
398
|
+
deliveredAt: string | null;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* The JSON body Nestuge POSTs to your webhook endpoint, discriminated on
|
|
402
|
+
* `type` so `data` narrows to the right resource shape.
|
|
403
|
+
*/
|
|
404
|
+
type WebhookEvent = WebhookEventOf<'transaction.succeeded', Transaction> | WebhookEventOf<'transaction.failed', Transaction> | WebhookEventOf<'payout.settled', Transaction> | WebhookEventOf<'subscription.renewed', Purchase> | WebhookEventOf<'subscription.expired', Purchase> | WebhookEventOf<'subscription.completed', Purchase> | WebhookEventOf<'member.joined', Customer> | WebhookEventOf<'member.removed', Customer>;
|
|
405
|
+
interface WebhookEventOf<T extends WebhookEventType, D> {
|
|
406
|
+
/** Delivery id (`X-Nestuge-Delivery` carries the same value). */
|
|
407
|
+
id: string;
|
|
408
|
+
type: T;
|
|
409
|
+
/** ISO 8601 creation time of the event. */
|
|
410
|
+
created: string;
|
|
411
|
+
data: D;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
declare const SIGNATURE_HEADER = "X-Nestuge-Signature";
|
|
415
|
+
interface VerifySignatureParams {
|
|
416
|
+
/** The raw, unmodified request body string (not re-serialized JSON). */
|
|
417
|
+
payload: string;
|
|
418
|
+
/** Value of the `X-Nestuge-Signature` header (`sha256=<hex>`). */
|
|
419
|
+
signature: string;
|
|
420
|
+
/** The endpoint's signing secret, returned once by `webhooks.create()`. */
|
|
421
|
+
secret: string;
|
|
422
|
+
}
|
|
423
|
+
/** Verifies a webhook signature with a timing-safe HMAC-SHA256 comparison. */
|
|
424
|
+
declare const verifySignature: ({ payload, signature, secret, }: VerifySignatureParams) => Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* Verifies the signature and parses the payload into a typed `WebhookEvent`.
|
|
427
|
+
* Throws `WebhookVerificationError` on a bad signature or unparseable body.
|
|
428
|
+
*/
|
|
429
|
+
declare const constructEvent: (params: VerifySignatureParams) => Promise<WebhookEvent>;
|
|
430
|
+
|
|
431
|
+
/** All webhook endpoints require the `webhooks:write` scope. */
|
|
432
|
+
declare class Webhooks {
|
|
433
|
+
private readonly requestor;
|
|
434
|
+
readonly deliveries: WebhookDeliveries;
|
|
435
|
+
constructor(requestor: Requestor);
|
|
436
|
+
/**
|
|
437
|
+
* Registers an HTTPS endpoint URL. The returned `signingSecret` is shown
|
|
438
|
+
* once in this response and can never be retrieved again.
|
|
439
|
+
*/
|
|
440
|
+
create(params: CreateWebhookParams): Promise<WebhookEndpointWithSecret>;
|
|
441
|
+
/** Lists the brand's webhook endpoints. */
|
|
442
|
+
list(params?: ListParams): Promise<Page<WebhookEndpoint>>;
|
|
443
|
+
/** Returns a single webhook endpoint. */
|
|
444
|
+
retrieve(id: string): Promise<WebhookEndpoint>;
|
|
445
|
+
/** Updates a webhook endpoint's URL, events, status, or description. */
|
|
446
|
+
update(id: string, params: UpdateWebhookParams): Promise<WebhookEndpoint>;
|
|
447
|
+
/** Deletes a webhook endpoint. */
|
|
448
|
+
del(id: string): Promise<{
|
|
449
|
+
id: string;
|
|
450
|
+
deleted: boolean;
|
|
451
|
+
}>;
|
|
452
|
+
/**
|
|
453
|
+
* Synthesizes a sample event and delivers it through the real
|
|
454
|
+
* signed/retried/logged pipeline as a test-mode delivery.
|
|
455
|
+
*/
|
|
456
|
+
test(params: TestWebhookParams): Promise<{
|
|
457
|
+
created: number;
|
|
458
|
+
}>;
|
|
459
|
+
/** Iterates every webhook endpoint, following pagination cursors automatically. */
|
|
460
|
+
iterate(): AsyncGenerator<WebhookEndpoint>;
|
|
461
|
+
/**
|
|
462
|
+
* Verifies an incoming webhook's `X-Nestuge-Signature` header with a
|
|
463
|
+
* timing-safe HMAC-SHA256 comparison over the raw request body.
|
|
464
|
+
*/
|
|
465
|
+
verifySignature(params: VerifySignatureParams): Promise<boolean>;
|
|
466
|
+
/**
|
|
467
|
+
* Verifies the signature and returns the parsed, typed event. Throws
|
|
468
|
+
* `WebhookVerificationError` if verification fails.
|
|
469
|
+
*/
|
|
470
|
+
constructEvent(params: VerifySignatureParams): Promise<WebhookEvent>;
|
|
471
|
+
}
|
|
472
|
+
declare class WebhookDeliveries {
|
|
473
|
+
private readonly requestor;
|
|
474
|
+
constructor(requestor: Requestor);
|
|
475
|
+
/** Lists webhook delivery attempts, newest first. */
|
|
476
|
+
list(params?: ListParams): Promise<Page<WebhookDelivery>>;
|
|
477
|
+
/** Returns a single delivery record. */
|
|
478
|
+
retrieve(id: string): Promise<WebhookDelivery>;
|
|
479
|
+
/** Re-queues a delivery as a fresh attempt; the original record is preserved. */
|
|
480
|
+
resend(id: string): Promise<WebhookDelivery>;
|
|
481
|
+
/** Iterates every delivery record, following pagination cursors automatically. */
|
|
482
|
+
iterate(): AsyncGenerator<WebhookDelivery>;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
interface NestugeConfig {
|
|
486
|
+
/** Brand API key (`nk_live_…` or `nk_test_…`) from Settings → Developer. */
|
|
487
|
+
apiKey: string;
|
|
488
|
+
/** API origin. Defaults to `https://nestuge.com`. */
|
|
489
|
+
baseUrl?: string;
|
|
490
|
+
/** Extra retry attempts on 429/5xx/network errors. Defaults to 2. */
|
|
491
|
+
maxRetries?: number;
|
|
492
|
+
/** Per-attempt timeout in milliseconds. Defaults to 30000. */
|
|
493
|
+
timeoutMs?: number;
|
|
494
|
+
/** Custom fetch implementation (testing, proxies). Defaults to global fetch. */
|
|
495
|
+
fetch?: FetchLike;
|
|
496
|
+
}
|
|
497
|
+
declare class Nestuge {
|
|
498
|
+
readonly customers: Customers;
|
|
499
|
+
readonly products: Products;
|
|
500
|
+
readonly purchases: Purchases;
|
|
501
|
+
readonly transactions: Transactions;
|
|
502
|
+
readonly events: Events;
|
|
503
|
+
readonly tickets: Tickets;
|
|
504
|
+
readonly webhooks: Webhooks;
|
|
505
|
+
private readonly requestor;
|
|
506
|
+
constructor(config: NestugeConfig);
|
|
507
|
+
/**
|
|
508
|
+
* Authenticated health check: confirms the key works and returns the
|
|
509
|
+
* resolved brand, key mode, and granted scopes. No scope required.
|
|
510
|
+
*/
|
|
511
|
+
ping(): Promise<PingResponse>;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
interface ErrorContext {
|
|
515
|
+
message: string;
|
|
516
|
+
/** HTTP status code, when the server responded. */
|
|
517
|
+
status?: number;
|
|
518
|
+
/** The `code` field from the API error envelope. */
|
|
519
|
+
code?: number;
|
|
520
|
+
/** The `error` field from the API error envelope (detail text). */
|
|
521
|
+
detail?: string;
|
|
522
|
+
}
|
|
523
|
+
/** Base class for every error thrown by the SDK. */
|
|
524
|
+
declare class NestugeError extends Error {
|
|
525
|
+
readonly status?: number;
|
|
526
|
+
readonly code?: number;
|
|
527
|
+
readonly detail?: string;
|
|
528
|
+
constructor(context: ErrorContext);
|
|
529
|
+
}
|
|
530
|
+
/** 400 — the request body or parameters failed validation. */
|
|
531
|
+
declare class ValidationError extends NestugeError {
|
|
532
|
+
}
|
|
533
|
+
/** 401 — missing, malformed, or revoked API key. */
|
|
534
|
+
declare class AuthenticationError extends NestugeError {
|
|
535
|
+
}
|
|
536
|
+
/** 403 — the API key lacks a required scope for this endpoint. */
|
|
537
|
+
declare class PermissionError extends NestugeError {
|
|
538
|
+
}
|
|
539
|
+
/** 404 — the resource does not exist or belongs to another brand. */
|
|
540
|
+
declare class NotFoundError extends NestugeError {
|
|
541
|
+
}
|
|
542
|
+
/** 429 — rate limit exceeded (120 requests/minute per key). */
|
|
543
|
+
declare class RateLimitError extends NestugeError {
|
|
544
|
+
/** Seconds to wait before retrying, from the `Retry-After` header. */
|
|
545
|
+
readonly retryAfter?: number;
|
|
546
|
+
constructor(context: ErrorContext & {
|
|
547
|
+
retryAfter?: number;
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
/** 5xx — the API failed to process the request. */
|
|
551
|
+
declare class ServerError extends NestugeError {
|
|
552
|
+
}
|
|
553
|
+
/** The request never reached the API (network failure or timeout). */
|
|
554
|
+
declare class ConnectionError extends NestugeError {
|
|
555
|
+
}
|
|
556
|
+
/** Webhook signature verification failed in `constructEvent`. */
|
|
557
|
+
declare class WebhookVerificationError extends NestugeError {
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export { AuthenticationError, ConnectionError, type CreateEventParams, type CreateProductParams, type CreateWebhookParams, type Customer, type CustomerListParams, type HubEvent, type ListParams, type Mode, type Money, Nestuge, type NestugeConfig, NestugeError, NotFoundError, type Page, PermissionError, type PingResponse, type Product, type ProductDetail, type ProductEventDetails, type ProductEventType, type ProductItem, type ProductTier, type ProductType, type ProductVisibility, type Purchase, RateLimitError, SIGNATURE_HEADER, ServerError, type TestWebhookParams, type Ticket, type Transaction, type UpdateWebhookParams, ValidationError, type VerifySignatureParams, type WebhookDelivery, type WebhookDeliveryStatus, type WebhookEndpoint, type WebhookEndpointStatus, type WebhookEndpointWithSecret, type WebhookEvent, type WebhookEventType, type WebhookResourceType, WebhookVerificationError, constructEvent, Nestuge as default, verifySignature };
|