@nymbalhq/types 0.0.0-canary-20261019164512
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/dist/index.d.ts +1030 -0
- package/dist/index.js +310 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1030 @@
|
|
|
1
|
+
type ErrorContext = Record<string, unknown>;
|
|
2
|
+
declare class NymbalError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly context: ErrorContext;
|
|
5
|
+
constructor(code: string, message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
context?: ErrorContext;
|
|
8
|
+
});
|
|
9
|
+
toJSON(): {
|
|
10
|
+
name: string;
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
context: ErrorContext;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare class ConfigError extends NymbalError {
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
context?: ErrorContext;
|
|
20
|
+
code?: `config.${string}`;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
declare class ValidationError extends NymbalError {
|
|
24
|
+
constructor(message: string, options?: {
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
context?: ErrorContext;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
declare class NotFoundError extends NymbalError {
|
|
30
|
+
constructor(resource: string, identifier: unknown, options?: {
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
context?: ErrorContext;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
declare class AdapterError extends NymbalError {
|
|
36
|
+
constructor(code: string, message: string, options?: {
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
context?: ErrorContext;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
declare class HttpError extends NymbalError {
|
|
42
|
+
readonly status: number;
|
|
43
|
+
constructor(status: number, message: string, options?: {
|
|
44
|
+
cause?: unknown;
|
|
45
|
+
context?: ErrorContext;
|
|
46
|
+
code?: string;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
declare class AuthError extends HttpError {
|
|
50
|
+
constructor(code: 'unauthorized' | 'forbidden' | 'invalid_credentials' | 'token_expired' | 'token_invalid', message: string, options?: {
|
|
51
|
+
cause?: unknown;
|
|
52
|
+
context?: ErrorContext;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
declare class PaymentError extends NymbalError {
|
|
56
|
+
constructor(code: 'intent_failed' | 'capture_failed' | 'refund_rejected' | 'refund_unknown' | 'cancel_refused' | 'webhook_invalid' | 'not_configured', message: string, options?: {
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
context?: ErrorContext;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** A command the order's money does not allow (confirm unpaid, cancel paid, refund beyond the capture). */
|
|
62
|
+
declare class OrderConflictError extends NymbalError {
|
|
63
|
+
constructor(code: 'order.unpaid' | 'order.paid' | 'order.stock_unavailable' | 'order.payment_in_progress' | 'refund.not_captured' | 'refund.exceeds_captured' | 'refund.request_reused', message: string, options?: {
|
|
64
|
+
cause?: unknown;
|
|
65
|
+
context?: ErrorContext;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
declare class CheckoutError extends NymbalError {
|
|
69
|
+
constructor(code: 'cart_empty' | 'in_progress' | 'payment_in_progress' | 'variant_missing' | 'out_of_stock' | 'reservation_failed' | 'finalize_failed', message: string, options?: {
|
|
70
|
+
cause?: unknown;
|
|
71
|
+
context?: ErrorContext;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
declare class StatusTransitionError extends NymbalError {
|
|
75
|
+
constructor(entity: string, fromStatus: string, toStatus: string, options?: {
|
|
76
|
+
cause?: unknown;
|
|
77
|
+
context?: ErrorContext;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface Money {
|
|
82
|
+
amount: number;
|
|
83
|
+
currency: string;
|
|
84
|
+
}
|
|
85
|
+
declare function money(amount: number, currency: string): Money;
|
|
86
|
+
declare function assertMinorUnits(amount: number): void;
|
|
87
|
+
declare function add(a: Money, b: Money): Money;
|
|
88
|
+
declare function sub(a: Money, b: Money): Money;
|
|
89
|
+
declare function mulBy(m: Money, scalar: number): Money;
|
|
90
|
+
declare function sumMoney(values: Money[], currency: string): Money;
|
|
91
|
+
declare function allocate(m: Money, weights: number[]): Money[];
|
|
92
|
+
|
|
93
|
+
type ProductStatus = 'draft' | 'active' | 'archived';
|
|
94
|
+
type ProductType = 'simple' | 'variable';
|
|
95
|
+
type VariantStatus = 'active' | 'inactive';
|
|
96
|
+
interface ProductMedia {
|
|
97
|
+
url: string;
|
|
98
|
+
altText: string;
|
|
99
|
+
position: number;
|
|
100
|
+
}
|
|
101
|
+
interface VariantOption {
|
|
102
|
+
name: string;
|
|
103
|
+
value: string;
|
|
104
|
+
}
|
|
105
|
+
interface VariantDimensions {
|
|
106
|
+
lengthMm?: number;
|
|
107
|
+
widthMm?: number;
|
|
108
|
+
heightMm?: number;
|
|
109
|
+
}
|
|
110
|
+
interface Variant {
|
|
111
|
+
id: string;
|
|
112
|
+
productId: string;
|
|
113
|
+
sku: string;
|
|
114
|
+
name: string;
|
|
115
|
+
priceMinor: number;
|
|
116
|
+
compareAtPriceMinor: number | null;
|
|
117
|
+
weightGrams: number | null;
|
|
118
|
+
dimensions: VariantDimensions | null;
|
|
119
|
+
stock: number;
|
|
120
|
+
lowStockThreshold: number;
|
|
121
|
+
options: VariantOption[];
|
|
122
|
+
status: VariantStatus;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
updatedAt: string;
|
|
125
|
+
}
|
|
126
|
+
interface Product {
|
|
127
|
+
id: string;
|
|
128
|
+
slug: string;
|
|
129
|
+
name: string;
|
|
130
|
+
description: string;
|
|
131
|
+
shortDescription: string;
|
|
132
|
+
status: ProductStatus;
|
|
133
|
+
type: ProductType;
|
|
134
|
+
seoTitle: string;
|
|
135
|
+
seoDescription: string;
|
|
136
|
+
media: ProductMedia[];
|
|
137
|
+
metadata: Record<string, unknown>;
|
|
138
|
+
createdAt: string;
|
|
139
|
+
updatedAt: string;
|
|
140
|
+
}
|
|
141
|
+
/** The orders a product listing can be requested in; ties break by slug, ascending. */
|
|
142
|
+
declare const PRODUCT_SORT_KEYS: readonly ["newest", "price-asc", "price-desc", "name-asc", "name-desc"];
|
|
143
|
+
type ProductSortKey = (typeof PRODUCT_SORT_KEYS)[number];
|
|
144
|
+
declare const DEFAULT_PRODUCT_SORT: ProductSortKey;
|
|
145
|
+
|
|
146
|
+
interface Category {
|
|
147
|
+
id: string;
|
|
148
|
+
parentId: string | null;
|
|
149
|
+
name: string;
|
|
150
|
+
slug: string;
|
|
151
|
+
description: string;
|
|
152
|
+
position: number;
|
|
153
|
+
createdAt: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface CartItem {
|
|
157
|
+
variantId: string;
|
|
158
|
+
productId: string;
|
|
159
|
+
productName: string;
|
|
160
|
+
variantName: string;
|
|
161
|
+
priceMinor: number;
|
|
162
|
+
qty: number;
|
|
163
|
+
imageUrl: string;
|
|
164
|
+
}
|
|
165
|
+
interface Cart {
|
|
166
|
+
token: string;
|
|
167
|
+
customerId: string | null;
|
|
168
|
+
items: CartItem[];
|
|
169
|
+
subtotalMinor: number;
|
|
170
|
+
currency: string;
|
|
171
|
+
expiresAt: string;
|
|
172
|
+
createdAt: string;
|
|
173
|
+
updatedAt: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
type OrderStatus = 'pending' | 'confirmed' | 'processing' | 'shipped' | 'delivered' | 'cancelled' | 'refunded' | 'partially_refunded';
|
|
177
|
+
declare const ORDER_STATUS_TRANSITIONS: Record<OrderStatus, readonly OrderStatus[]>;
|
|
178
|
+
declare function canTransitionOrder(from: OrderStatus, to: OrderStatus): boolean;
|
|
179
|
+
declare function assertOrderTransition(from: OrderStatus, to: OrderStatus): void;
|
|
180
|
+
interface Address {
|
|
181
|
+
firstName: string;
|
|
182
|
+
lastName: string;
|
|
183
|
+
company?: string;
|
|
184
|
+
addressLine1: string;
|
|
185
|
+
addressLine2?: string;
|
|
186
|
+
city: string;
|
|
187
|
+
region: string;
|
|
188
|
+
postalCode: string;
|
|
189
|
+
country: string;
|
|
190
|
+
phone?: string;
|
|
191
|
+
}
|
|
192
|
+
interface OrderLineItem {
|
|
193
|
+
variantId: string;
|
|
194
|
+
productId: string;
|
|
195
|
+
productName: string;
|
|
196
|
+
variantName: string;
|
|
197
|
+
sku: string;
|
|
198
|
+
qty: number;
|
|
199
|
+
unitPriceMinor: number;
|
|
200
|
+
lineSubtotalMinor: number;
|
|
201
|
+
lineTaxMinor: number;
|
|
202
|
+
lineTotalMinor: number;
|
|
203
|
+
imageUrl: string;
|
|
204
|
+
}
|
|
205
|
+
interface Order {
|
|
206
|
+
id: string;
|
|
207
|
+
orderNumber: string;
|
|
208
|
+
sequence: number;
|
|
209
|
+
customerId: string | null;
|
|
210
|
+
status: OrderStatus;
|
|
211
|
+
email: string;
|
|
212
|
+
billingAddress: Address;
|
|
213
|
+
shippingAddress: Address;
|
|
214
|
+
lineItems: OrderLineItem[];
|
|
215
|
+
subtotalMinor: number;
|
|
216
|
+
taxTotalMinor: number;
|
|
217
|
+
shippingTotalMinor: number;
|
|
218
|
+
discountTotalMinor: number;
|
|
219
|
+
totalMinor: number;
|
|
220
|
+
currency: string;
|
|
221
|
+
notes: string;
|
|
222
|
+
metadata: Record<string, unknown>;
|
|
223
|
+
paymentIntentId: string | null;
|
|
224
|
+
/** Money taken for the order, in minor units of its currency; 0 while nothing is captured. */
|
|
225
|
+
capturedMinor: number;
|
|
226
|
+
capturedAt: string | null;
|
|
227
|
+
/** Σ of the order's succeeded refunds (or, for an import or a pre-refund-table order, what was refunded then). */
|
|
228
|
+
refundedMinor: number;
|
|
229
|
+
captureMethod: CaptureMethod | null;
|
|
230
|
+
createdAt: string;
|
|
231
|
+
updatedAt: string;
|
|
232
|
+
}
|
|
233
|
+
/** Who took the money: the payments provider, the merchant recording an offline payment, or an imported history. */
|
|
234
|
+
type CaptureMethod = 'provider' | 'manual' | 'import';
|
|
235
|
+
type OrderRefundStatus = 'pending' | 'succeeded' | 'failed';
|
|
236
|
+
/** One refund of an order. `pending` until the provider's answer settles it, and counted against what is refundable. */
|
|
237
|
+
interface OrderRefund {
|
|
238
|
+
id: string;
|
|
239
|
+
orderId: string;
|
|
240
|
+
amountMinor: number;
|
|
241
|
+
currency: string;
|
|
242
|
+
providerRefundId: string | null;
|
|
243
|
+
status: OrderRefundStatus;
|
|
244
|
+
reason: string | null;
|
|
245
|
+
actor: string;
|
|
246
|
+
createdAt: string;
|
|
247
|
+
}
|
|
248
|
+
type PaymentState = 'unpaid' | 'paid' | 'partially_refunded' | 'refunded';
|
|
249
|
+
/** What the admin shows about an order's money: derived from the stored amounts and refunds alone. */
|
|
250
|
+
interface OrderPayment {
|
|
251
|
+
state: PaymentState;
|
|
252
|
+
capturedMinor: number;
|
|
253
|
+
refundedMinor: number;
|
|
254
|
+
refundableMinor: number;
|
|
255
|
+
currency: string;
|
|
256
|
+
refunds: OrderRefund[];
|
|
257
|
+
}
|
|
258
|
+
declare function paymentState(order: Pick<Order, 'capturedMinor' | 'refundedMinor'>): PaymentState;
|
|
259
|
+
/** What can still be refunded: the capture less what was refunded and what is still pending with the provider. */
|
|
260
|
+
declare function refundableMinor(order: Pick<Order, 'capturedMinor' | 'refundedMinor'>, refunds: ReadonlyArray<Pick<OrderRefund, 'amountMinor' | 'status'>>): number;
|
|
261
|
+
interface OrderHistoryEntry {
|
|
262
|
+
id: string;
|
|
263
|
+
orderId: string;
|
|
264
|
+
fromStatus: OrderStatus | null;
|
|
265
|
+
toStatus: OrderStatus;
|
|
266
|
+
actor: string;
|
|
267
|
+
note: string;
|
|
268
|
+
timestamp: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface CustomerAddress extends Address {
|
|
272
|
+
id: string;
|
|
273
|
+
isDefaultBilling: boolean;
|
|
274
|
+
isDefaultShipping: boolean;
|
|
275
|
+
}
|
|
276
|
+
interface Customer {
|
|
277
|
+
id: string;
|
|
278
|
+
email: string;
|
|
279
|
+
firstName: string;
|
|
280
|
+
lastName: string;
|
|
281
|
+
phone: string;
|
|
282
|
+
addresses: CustomerAddress[];
|
|
283
|
+
orderCount: number;
|
|
284
|
+
totalSpentMinor: number;
|
|
285
|
+
metadata: Record<string, unknown>;
|
|
286
|
+
/** What an access token grants. Written by seed and admin code only, never taken from `metadata`. */
|
|
287
|
+
roles: Role[];
|
|
288
|
+
requiresPasswordReset: boolean;
|
|
289
|
+
createdAt: string;
|
|
290
|
+
updatedAt: string;
|
|
291
|
+
}
|
|
292
|
+
interface CustomerProfile {
|
|
293
|
+
customerId: string;
|
|
294
|
+
orderCount: number;
|
|
295
|
+
totalSpentMinor: number;
|
|
296
|
+
segment: string;
|
|
297
|
+
createdAt: string;
|
|
298
|
+
}
|
|
299
|
+
type Role = 'admin' | 'customer' | 'guest';
|
|
300
|
+
|
|
301
|
+
type StockAdjustmentReason = 'sale' | 'return' | 'manual' | 'import' | 'reservation-commit' | 'reservation-release';
|
|
302
|
+
interface InventoryReservation {
|
|
303
|
+
reservationId: string;
|
|
304
|
+
variantId: string;
|
|
305
|
+
qty: number;
|
|
306
|
+
orderRef: string | null;
|
|
307
|
+
expiresAt: string;
|
|
308
|
+
createdAt: string;
|
|
309
|
+
}
|
|
310
|
+
interface StockAdjustment {
|
|
311
|
+
id: string;
|
|
312
|
+
variantId: string;
|
|
313
|
+
adjustment: number;
|
|
314
|
+
reason: StockAdjustmentReason;
|
|
315
|
+
actor: string;
|
|
316
|
+
previousQty: number;
|
|
317
|
+
newQty: number;
|
|
318
|
+
timestamp: string;
|
|
319
|
+
}
|
|
320
|
+
type StockStatus = 'in_stock' | 'low_stock' | 'out_of_stock';
|
|
321
|
+
|
|
322
|
+
type ReviewModerationStatus = 'pending' | 'approved' | 'rejected';
|
|
323
|
+
interface Review {
|
|
324
|
+
id: string;
|
|
325
|
+
productId: string;
|
|
326
|
+
customerId: string | null;
|
|
327
|
+
orderId: string | null;
|
|
328
|
+
rating: number;
|
|
329
|
+
title: string;
|
|
330
|
+
body: string;
|
|
331
|
+
moderationStatus: ReviewModerationStatus;
|
|
332
|
+
submittedAt: string;
|
|
333
|
+
moderatedAt: string | null;
|
|
334
|
+
moderatedBy: string | null;
|
|
335
|
+
}
|
|
336
|
+
interface AggregateRating {
|
|
337
|
+
productId: string;
|
|
338
|
+
average: number;
|
|
339
|
+
count: number;
|
|
340
|
+
histogram: Record<'1' | '2' | '3' | '4' | '5', number>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
type PaymentStatus = 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'requires_capture' | 'succeeded' | 'cancelled' | 'failed';
|
|
344
|
+
interface PaymentIntentParams {
|
|
345
|
+
amountMinor: number;
|
|
346
|
+
currency: string;
|
|
347
|
+
orderRef?: string;
|
|
348
|
+
customerId?: string;
|
|
349
|
+
/** Where the provider sends its receipt (Stripe's `receipt_email`). */
|
|
350
|
+
receiptEmail?: string;
|
|
351
|
+
metadata?: Record<string, string>;
|
|
352
|
+
}
|
|
353
|
+
interface PaymentIntent {
|
|
354
|
+
id: string;
|
|
355
|
+
clientSecret: string;
|
|
356
|
+
amountMinor: number;
|
|
357
|
+
currency: string;
|
|
358
|
+
status: PaymentStatus;
|
|
359
|
+
providerPayload?: Record<string, unknown>;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* What a checkout tells the shopper about their payment: `succeeded` once the order is confirmed, `requires_action`
|
|
363
|
+
* while the provider waits on the shopper (a Stripe confirmation), `failed` with the reason when it will not complete.
|
|
364
|
+
*/
|
|
365
|
+
interface CheckoutPayment {
|
|
366
|
+
status: 'succeeded' | 'requires_action' | 'failed';
|
|
367
|
+
reason?: string;
|
|
368
|
+
}
|
|
369
|
+
interface PaymentCapture {
|
|
370
|
+
paymentId: string;
|
|
371
|
+
capturedAmountMinor: number;
|
|
372
|
+
currency: string;
|
|
373
|
+
status: PaymentStatus;
|
|
374
|
+
}
|
|
375
|
+
interface Refund {
|
|
376
|
+
refundId: string;
|
|
377
|
+
paymentId: string;
|
|
378
|
+
amountMinor: number;
|
|
379
|
+
currency: string;
|
|
380
|
+
reason: string | null;
|
|
381
|
+
status: 'pending' | 'succeeded' | 'failed';
|
|
382
|
+
}
|
|
383
|
+
interface WebhookResult {
|
|
384
|
+
verified: boolean;
|
|
385
|
+
eventId: string;
|
|
386
|
+
kind: 'payment.captured' | 'payment.failed' | 'payment.refunded' | 'ignored';
|
|
387
|
+
paymentIntentId?: string;
|
|
388
|
+
amountMinor?: number;
|
|
389
|
+
currency?: string;
|
|
390
|
+
reason?: string;
|
|
391
|
+
raw?: Record<string, unknown>;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
declare const EVT_PRODUCT_CREATED = "product.created.v1";
|
|
395
|
+
declare const EVT_PRODUCT_UPDATED = "product.updated.v1";
|
|
396
|
+
declare const EVT_PRODUCT_DELETED = "product.deleted.v1";
|
|
397
|
+
declare const EVT_PRODUCT_PUBLISHED = "product.published.v1";
|
|
398
|
+
declare const EVT_PRODUCT_UNPUBLISHED = "product.unpublished.v1";
|
|
399
|
+
declare const EVT_CATEGORY_CREATED = "category.created.v1";
|
|
400
|
+
declare const EVT_CATEGORY_UPDATED = "category.updated.v1";
|
|
401
|
+
declare const EVT_CATEGORY_DELETED = "category.deleted.v1";
|
|
402
|
+
declare const EVT_ORDER_PLACED = "order.placed.v1";
|
|
403
|
+
declare const EVT_ORDER_PAID = "order.paid.v1";
|
|
404
|
+
declare const EVT_ORDER_FULFILLED = "order.fulfilled.v1";
|
|
405
|
+
declare const EVT_ORDER_SHIPPED = "order.shipped.v1";
|
|
406
|
+
declare const EVT_ORDER_DELIVERED = "order.delivered.v1";
|
|
407
|
+
declare const EVT_ORDER_CANCELLED = "order.cancelled.v1";
|
|
408
|
+
declare const EVT_ORDER_REFUNDED = "order.refunded.v1";
|
|
409
|
+
declare const EVT_ORDER_PARTIALLY_REFUNDED = "order.partially_refunded.v1";
|
|
410
|
+
declare const EVT_INVENTORY_CHANGED = "inventory.changed.v1";
|
|
411
|
+
declare const EVT_INVENTORY_RESERVED = "inventory.reserved.v1";
|
|
412
|
+
declare const EVT_INVENTORY_RELEASED = "inventory.released.v1";
|
|
413
|
+
declare const EVT_INVENTORY_LOW_STOCK = "inventory.low_stock.v1";
|
|
414
|
+
declare const EVT_INVENTORY_OUT_OF_STOCK = "inventory.out_of_stock.v1";
|
|
415
|
+
declare const EVT_CUSTOMER_CREATED = "customer.created.v1";
|
|
416
|
+
declare const EVT_CUSTOMER_UPDATED = "customer.updated.v1";
|
|
417
|
+
declare const EVT_CUSTOMER_DELETED = "customer.deleted.v1";
|
|
418
|
+
declare const EVT_CUSTOMER_REGISTERED = "customer.created.v1";
|
|
419
|
+
declare const EVT_CART_CREATED = "cart.created.v1";
|
|
420
|
+
declare const EVT_CART_ITEM_ADDED = "cart.item_added.v1";
|
|
421
|
+
declare const EVT_CART_ITEM_REMOVED = "cart.item_removed.v1";
|
|
422
|
+
declare const EVT_CART_UPDATED = "cart.updated.v1";
|
|
423
|
+
declare const EVT_CART_ABANDONED = "cart.abandoned.v1";
|
|
424
|
+
declare const EVT_CART_CONVERTED = "cart.converted.v1";
|
|
425
|
+
declare const EVT_PAYMENT_CAPTURED = "payment.captured.v1";
|
|
426
|
+
declare const EVT_PAYMENT_FAILED = "payment.failed.v1";
|
|
427
|
+
declare const EVT_PAYMENT_REFUNDED = "payment.refunded.v1";
|
|
428
|
+
declare const EVT_ADAPTER_ERROR = "adapter.error.v1";
|
|
429
|
+
declare const STANDARD_EVENT_TYPES: readonly ["product.created.v1", "product.updated.v1", "product.deleted.v1", "product.published.v1", "product.unpublished.v1", "category.created.v1", "category.updated.v1", "category.deleted.v1", "order.placed.v1", "order.paid.v1", "order.fulfilled.v1", "order.shipped.v1", "order.delivered.v1", "order.cancelled.v1", "order.refunded.v1", "order.partially_refunded.v1", "inventory.changed.v1", "inventory.reserved.v1", "inventory.released.v1", "inventory.low_stock.v1", "inventory.out_of_stock.v1", "customer.created.v1", "customer.updated.v1", "customer.deleted.v1", "cart.created.v1", "cart.item_added.v1", "cart.item_removed.v1", "cart.updated.v1", "cart.abandoned.v1", "cart.converted.v1", "payment.captured.v1", "payment.failed.v1", "payment.refunded.v1", "adapter.error.v1"];
|
|
430
|
+
|
|
431
|
+
interface ProductSnapshot extends Product {
|
|
432
|
+
variants: Variant[];
|
|
433
|
+
categoryIds: string[];
|
|
434
|
+
}
|
|
435
|
+
interface ProductCreatedV1Payload {
|
|
436
|
+
product: ProductSnapshot;
|
|
437
|
+
}
|
|
438
|
+
interface ProductUpdatedV1Payload {
|
|
439
|
+
product: ProductSnapshot;
|
|
440
|
+
}
|
|
441
|
+
interface ProductDeletedV1Payload {
|
|
442
|
+
productId: string;
|
|
443
|
+
slug: string;
|
|
444
|
+
}
|
|
445
|
+
interface ProductPublishedV1Payload {
|
|
446
|
+
productId: string;
|
|
447
|
+
slug: string;
|
|
448
|
+
}
|
|
449
|
+
interface ProductUnpublishedV1Payload {
|
|
450
|
+
productId: string;
|
|
451
|
+
slug: string;
|
|
452
|
+
}
|
|
453
|
+
interface CategoryCreatedV1Payload {
|
|
454
|
+
category: Category;
|
|
455
|
+
}
|
|
456
|
+
interface CategoryUpdatedV1Payload {
|
|
457
|
+
category: Category;
|
|
458
|
+
}
|
|
459
|
+
interface CategoryDeletedV1Payload {
|
|
460
|
+
categoryId: string;
|
|
461
|
+
slug: string;
|
|
462
|
+
}
|
|
463
|
+
interface OrderPlacedV1Payload {
|
|
464
|
+
order: Order;
|
|
465
|
+
}
|
|
466
|
+
interface OrderPaidV1Payload {
|
|
467
|
+
orderId: string;
|
|
468
|
+
paymentIntentId: string;
|
|
469
|
+
amountMinor: number;
|
|
470
|
+
currency: string;
|
|
471
|
+
}
|
|
472
|
+
interface OrderFulfilledV1Payload {
|
|
473
|
+
orderId: string;
|
|
474
|
+
}
|
|
475
|
+
interface OrderShippedV1Payload {
|
|
476
|
+
orderId: string;
|
|
477
|
+
trackingNumber: string;
|
|
478
|
+
carrier: string;
|
|
479
|
+
}
|
|
480
|
+
interface OrderDeliveredV1Payload {
|
|
481
|
+
orderId: string;
|
|
482
|
+
}
|
|
483
|
+
interface OrderCancelledV1Payload {
|
|
484
|
+
orderId: string;
|
|
485
|
+
reason: string;
|
|
486
|
+
}
|
|
487
|
+
interface OrderRefundedV1Payload {
|
|
488
|
+
orderId: string;
|
|
489
|
+
refundId: string;
|
|
490
|
+
amountMinor: number;
|
|
491
|
+
currency: string;
|
|
492
|
+
reason: string;
|
|
493
|
+
}
|
|
494
|
+
interface OrderPartiallyRefundedV1Payload {
|
|
495
|
+
orderId: string;
|
|
496
|
+
refundId: string;
|
|
497
|
+
amountMinor: number;
|
|
498
|
+
currency: string;
|
|
499
|
+
reason: string;
|
|
500
|
+
}
|
|
501
|
+
interface InventoryChangedV1Payload {
|
|
502
|
+
variantId: string;
|
|
503
|
+
previousQty: number;
|
|
504
|
+
newQty: number;
|
|
505
|
+
reason: StockAdjustmentReason;
|
|
506
|
+
}
|
|
507
|
+
interface InventoryReservedV1Payload {
|
|
508
|
+
variantId: string;
|
|
509
|
+
qty: number;
|
|
510
|
+
reservationId: string;
|
|
511
|
+
expiresAt: string;
|
|
512
|
+
}
|
|
513
|
+
interface InventoryReleasedV1Payload {
|
|
514
|
+
variantId: string;
|
|
515
|
+
qty: number;
|
|
516
|
+
reservationId: string;
|
|
517
|
+
reason: 'expired' | 'cancelled' | 'abandoned' | 'committed';
|
|
518
|
+
}
|
|
519
|
+
interface InventoryLowStockV1Payload {
|
|
520
|
+
variantId: string;
|
|
521
|
+
currentQty: number;
|
|
522
|
+
threshold: number;
|
|
523
|
+
}
|
|
524
|
+
interface InventoryOutOfStockV1Payload {
|
|
525
|
+
variantId: string;
|
|
526
|
+
}
|
|
527
|
+
interface CustomerCreatedV1Payload {
|
|
528
|
+
customerId: string;
|
|
529
|
+
email: string;
|
|
530
|
+
}
|
|
531
|
+
interface CustomerUpdatedV1Payload {
|
|
532
|
+
customerId: string;
|
|
533
|
+
}
|
|
534
|
+
interface CustomerDeletedV1Payload {
|
|
535
|
+
customerId: string;
|
|
536
|
+
}
|
|
537
|
+
interface CartCreatedV1Payload {
|
|
538
|
+
cartId: string;
|
|
539
|
+
token: string;
|
|
540
|
+
}
|
|
541
|
+
interface CartItemAddedV1Payload {
|
|
542
|
+
cartId: string;
|
|
543
|
+
variantId: string;
|
|
544
|
+
qty: number;
|
|
545
|
+
}
|
|
546
|
+
interface CartItemRemovedV1Payload {
|
|
547
|
+
cartId: string;
|
|
548
|
+
variantId: string;
|
|
549
|
+
}
|
|
550
|
+
interface CartUpdatedV1Payload {
|
|
551
|
+
cartId: string;
|
|
552
|
+
itemCount: number;
|
|
553
|
+
totalMinor: number;
|
|
554
|
+
}
|
|
555
|
+
interface CartAbandonedV1Payload {
|
|
556
|
+
cartId: string;
|
|
557
|
+
lastActivityAt: string;
|
|
558
|
+
}
|
|
559
|
+
interface CartConvertedV1Payload {
|
|
560
|
+
cartId: string;
|
|
561
|
+
orderId: string;
|
|
562
|
+
}
|
|
563
|
+
interface PaymentCapturedV1Payload {
|
|
564
|
+
paymentId: string;
|
|
565
|
+
orderId: string;
|
|
566
|
+
amountMinor: number;
|
|
567
|
+
currency: string;
|
|
568
|
+
}
|
|
569
|
+
interface PaymentFailedV1Payload {
|
|
570
|
+
paymentId: string;
|
|
571
|
+
orderId: string;
|
|
572
|
+
reason: string;
|
|
573
|
+
}
|
|
574
|
+
interface PaymentRefundedV1Payload {
|
|
575
|
+
paymentId: string;
|
|
576
|
+
orderId: string;
|
|
577
|
+
refundId: string;
|
|
578
|
+
amountMinor: number;
|
|
579
|
+
currency: string;
|
|
580
|
+
}
|
|
581
|
+
interface AdapterErrorV1Payload {
|
|
582
|
+
adapterType: string;
|
|
583
|
+
adapterName: string;
|
|
584
|
+
error: {
|
|
585
|
+
code: string;
|
|
586
|
+
message: string;
|
|
587
|
+
};
|
|
588
|
+
context: Record<string, unknown>;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
interface NymbalEventMap {
|
|
592
|
+
[EVT_PRODUCT_CREATED]: ProductCreatedV1Payload;
|
|
593
|
+
[EVT_PRODUCT_UPDATED]: ProductUpdatedV1Payload;
|
|
594
|
+
[EVT_PRODUCT_DELETED]: ProductDeletedV1Payload;
|
|
595
|
+
[EVT_PRODUCT_PUBLISHED]: ProductPublishedV1Payload;
|
|
596
|
+
[EVT_PRODUCT_UNPUBLISHED]: ProductUnpublishedV1Payload;
|
|
597
|
+
[EVT_CATEGORY_CREATED]: CategoryCreatedV1Payload;
|
|
598
|
+
[EVT_CATEGORY_UPDATED]: CategoryUpdatedV1Payload;
|
|
599
|
+
[EVT_CATEGORY_DELETED]: CategoryDeletedV1Payload;
|
|
600
|
+
[EVT_ORDER_PLACED]: OrderPlacedV1Payload;
|
|
601
|
+
[EVT_ORDER_PAID]: OrderPaidV1Payload;
|
|
602
|
+
[EVT_ORDER_FULFILLED]: OrderFulfilledV1Payload;
|
|
603
|
+
[EVT_ORDER_SHIPPED]: OrderShippedV1Payload;
|
|
604
|
+
[EVT_ORDER_DELIVERED]: OrderDeliveredV1Payload;
|
|
605
|
+
[EVT_ORDER_CANCELLED]: OrderCancelledV1Payload;
|
|
606
|
+
[EVT_ORDER_REFUNDED]: OrderRefundedV1Payload;
|
|
607
|
+
[EVT_ORDER_PARTIALLY_REFUNDED]: OrderPartiallyRefundedV1Payload;
|
|
608
|
+
[EVT_INVENTORY_CHANGED]: InventoryChangedV1Payload;
|
|
609
|
+
[EVT_INVENTORY_RESERVED]: InventoryReservedV1Payload;
|
|
610
|
+
[EVT_INVENTORY_RELEASED]: InventoryReleasedV1Payload;
|
|
611
|
+
[EVT_INVENTORY_LOW_STOCK]: InventoryLowStockV1Payload;
|
|
612
|
+
[EVT_INVENTORY_OUT_OF_STOCK]: InventoryOutOfStockV1Payload;
|
|
613
|
+
[EVT_CUSTOMER_CREATED]: CustomerCreatedV1Payload;
|
|
614
|
+
[EVT_CUSTOMER_UPDATED]: CustomerUpdatedV1Payload;
|
|
615
|
+
[EVT_CUSTOMER_DELETED]: CustomerDeletedV1Payload;
|
|
616
|
+
[EVT_CART_CREATED]: CartCreatedV1Payload;
|
|
617
|
+
[EVT_CART_ITEM_ADDED]: CartItemAddedV1Payload;
|
|
618
|
+
[EVT_CART_ITEM_REMOVED]: CartItemRemovedV1Payload;
|
|
619
|
+
[EVT_CART_UPDATED]: CartUpdatedV1Payload;
|
|
620
|
+
[EVT_CART_ABANDONED]: CartAbandonedV1Payload;
|
|
621
|
+
[EVT_CART_CONVERTED]: CartConvertedV1Payload;
|
|
622
|
+
[EVT_PAYMENT_CAPTURED]: PaymentCapturedV1Payload;
|
|
623
|
+
[EVT_PAYMENT_FAILED]: PaymentFailedV1Payload;
|
|
624
|
+
[EVT_PAYMENT_REFUNDED]: PaymentRefundedV1Payload;
|
|
625
|
+
[EVT_ADAPTER_ERROR]: AdapterErrorV1Payload;
|
|
626
|
+
}
|
|
627
|
+
type NymbalEventType = keyof NymbalEventMap;
|
|
628
|
+
type PayloadOf<E extends NymbalEventType> = NymbalEventMap[E];
|
|
629
|
+
|
|
630
|
+
type NymbalEnvironment = 'production' | 'staging' | 'development';
|
|
631
|
+
interface EventMetadata {
|
|
632
|
+
storeId: string;
|
|
633
|
+
environment: NymbalEnvironment;
|
|
634
|
+
version: string;
|
|
635
|
+
}
|
|
636
|
+
interface NymbalEvent<T = unknown> {
|
|
637
|
+
id: string;
|
|
638
|
+
type: string;
|
|
639
|
+
timestamp: string;
|
|
640
|
+
source: string;
|
|
641
|
+
correlationId: string;
|
|
642
|
+
payload: T;
|
|
643
|
+
metadata: EventMetadata;
|
|
644
|
+
}
|
|
645
|
+
type EventHandler<T = unknown> = (event: NymbalEvent<T>) => Promise<void> | void;
|
|
646
|
+
|
|
647
|
+
type HealthStatus = 'healthy' | 'degraded' | 'down';
|
|
648
|
+
interface HealthReport {
|
|
649
|
+
status: HealthStatus;
|
|
650
|
+
detail?: string;
|
|
651
|
+
}
|
|
652
|
+
interface AdapterBase {
|
|
653
|
+
readonly capabilities: readonly string[];
|
|
654
|
+
readonly producesEvents: readonly string[];
|
|
655
|
+
readonly consumesEvents: readonly string[];
|
|
656
|
+
initialize(config: unknown): Promise<void>;
|
|
657
|
+
healthCheck(): Promise<HealthReport>;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
interface PutOptions {
|
|
661
|
+
ttl?: number;
|
|
662
|
+
conditionKey?: string;
|
|
663
|
+
conditionValue?: unknown;
|
|
664
|
+
}
|
|
665
|
+
interface QueryParams {
|
|
666
|
+
/** A `value` of `'*'` matches every document in the collection (a full scan). */
|
|
667
|
+
partitionKey: {
|
|
668
|
+
field: string;
|
|
669
|
+
value: unknown;
|
|
670
|
+
};
|
|
671
|
+
sortKey?: {
|
|
672
|
+
field: string;
|
|
673
|
+
operator: 'eq' | 'gt' | 'lt' | 'between';
|
|
674
|
+
value: unknown;
|
|
675
|
+
};
|
|
676
|
+
/**
|
|
677
|
+
* Orders the results without filtering them; `field` may be a dotted path (`priceRange.minMinor`). Ties break by
|
|
678
|
+
* document key, ascending, so the order is total. A cursor issued under one `orderBy` is refused under another.
|
|
679
|
+
*/
|
|
680
|
+
orderBy?: {
|
|
681
|
+
field: string;
|
|
682
|
+
direction: 'asc' | 'desc';
|
|
683
|
+
nulls?: 'last';
|
|
684
|
+
};
|
|
685
|
+
limit?: number;
|
|
686
|
+
cursor?: string;
|
|
687
|
+
ascending?: boolean;
|
|
688
|
+
}
|
|
689
|
+
interface QueryResult<T> {
|
|
690
|
+
items: T[];
|
|
691
|
+
nextCursor: string | null;
|
|
692
|
+
}
|
|
693
|
+
interface DocumentStoreAdapter {
|
|
694
|
+
get<T>(collection: string, key: string): Promise<T | null>;
|
|
695
|
+
put<T>(collection: string, key: string, document: T, options?: PutOptions): Promise<void>;
|
|
696
|
+
delete(collection: string, key: string): Promise<void>;
|
|
697
|
+
query<T>(collection: string, params: QueryParams): Promise<QueryResult<T>>;
|
|
698
|
+
batchGet<T>(collection: string, keys: string[]): Promise<Map<string, T>>;
|
|
699
|
+
batchPut<T>(collection: string, items: Map<string, T>): Promise<void>;
|
|
700
|
+
close(): Promise<void>;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
interface RetryPolicy {
|
|
704
|
+
maxAttempts: number;
|
|
705
|
+
backoff: 'exponential' | 'linear' | 'fixed';
|
|
706
|
+
initialDelayMs?: number;
|
|
707
|
+
}
|
|
708
|
+
interface SubscriptionConfig {
|
|
709
|
+
retryPolicy?: RetryPolicy;
|
|
710
|
+
deadLetterQueue?: string;
|
|
711
|
+
batchSize?: number;
|
|
712
|
+
name?: string;
|
|
713
|
+
/** The subscriber only maintains derived state (a projection, a search index): it also receives `replay`. */
|
|
714
|
+
derived?: boolean;
|
|
715
|
+
}
|
|
716
|
+
interface Subscription {
|
|
717
|
+
id: string;
|
|
718
|
+
patterns: string[];
|
|
719
|
+
unsubscribe(): Promise<void>;
|
|
720
|
+
}
|
|
721
|
+
interface EventBusAdapter {
|
|
722
|
+
publish<T>(event: NymbalEvent<T>): Promise<void>;
|
|
723
|
+
publishBatch(events: NymbalEvent<unknown>[]): Promise<void>;
|
|
724
|
+
/** Delivers to `derived` subscriptions only, so rebuilding derived state never triggers side effects. */
|
|
725
|
+
replay(events: NymbalEvent<unknown>[]): Promise<void>;
|
|
726
|
+
subscribe(eventPattern: string | string[], handler: EventHandler, config?: SubscriptionConfig): Promise<Subscription>;
|
|
727
|
+
unsubscribe(subscription: Subscription): Promise<void>;
|
|
728
|
+
close(): Promise<void>;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
732
|
+
interface RequestAuth {
|
|
733
|
+
userId?: string;
|
|
734
|
+
roles?: string[];
|
|
735
|
+
token?: string;
|
|
736
|
+
}
|
|
737
|
+
interface Logger {
|
|
738
|
+
trace(obj: unknown, msg?: string): void;
|
|
739
|
+
debug(obj: unknown, msg?: string): void;
|
|
740
|
+
info(obj: unknown, msg?: string): void;
|
|
741
|
+
warn(obj: unknown, msg?: string): void;
|
|
742
|
+
error(obj: unknown, msg?: string): void;
|
|
743
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
744
|
+
}
|
|
745
|
+
interface RequestContext<TBody = unknown, TQuery = Record<string, string | string[] | undefined>, TParams = Record<string, string>> {
|
|
746
|
+
method: HttpMethod;
|
|
747
|
+
path: string;
|
|
748
|
+
url: string;
|
|
749
|
+
params: TParams;
|
|
750
|
+
query: TQuery;
|
|
751
|
+
body: TBody;
|
|
752
|
+
rawBody?: Buffer;
|
|
753
|
+
headers: Record<string, string | string[] | undefined>;
|
|
754
|
+
cookies: Record<string, string>;
|
|
755
|
+
auth?: RequestAuth;
|
|
756
|
+
requestId: string;
|
|
757
|
+
correlationId: string;
|
|
758
|
+
logger: Logger;
|
|
759
|
+
ip: string;
|
|
760
|
+
}
|
|
761
|
+
interface ResponseCookie {
|
|
762
|
+
name: string;
|
|
763
|
+
value: string;
|
|
764
|
+
path?: string;
|
|
765
|
+
domain?: string;
|
|
766
|
+
maxAge?: number;
|
|
767
|
+
httpOnly?: boolean;
|
|
768
|
+
secure?: boolean;
|
|
769
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
770
|
+
}
|
|
771
|
+
interface ResponseEnvelope<T = unknown> {
|
|
772
|
+
status: number;
|
|
773
|
+
headers?: Record<string, string>;
|
|
774
|
+
body?: T;
|
|
775
|
+
cookies?: ResponseCookie[];
|
|
776
|
+
}
|
|
777
|
+
type RouteHandler<TBody = unknown, TQuery = Record<string, string | string[] | undefined>, TParams = Record<string, string>, TResponse = unknown> = (ctx: RequestContext<TBody, TQuery, TParams>) => Promise<ResponseEnvelope<TResponse>> | ResponseEnvelope<TResponse>;
|
|
778
|
+
interface RouteOptions {
|
|
779
|
+
name?: string;
|
|
780
|
+
csrf?: boolean;
|
|
781
|
+
rateLimit?: string;
|
|
782
|
+
rawBody?: boolean;
|
|
783
|
+
}
|
|
784
|
+
type MiddlewareHandler = (ctx: RequestContext) => Promise<ResponseEnvelope | void> | ResponseEnvelope | void;
|
|
785
|
+
interface SseEvent {
|
|
786
|
+
id?: string;
|
|
787
|
+
event?: string;
|
|
788
|
+
data: unknown;
|
|
789
|
+
}
|
|
790
|
+
interface StreamContext {
|
|
791
|
+
send(event: SseEvent): void;
|
|
792
|
+
close(): void;
|
|
793
|
+
onClose(callback: () => void): void;
|
|
794
|
+
}
|
|
795
|
+
type StreamHandler = (ctx: RequestContext, stream: StreamContext) => Promise<void> | void;
|
|
796
|
+
interface HttpAdapter {
|
|
797
|
+
registerRoute(method: HttpMethod, path: string, handler: RouteHandler, options?: RouteOptions): void;
|
|
798
|
+
registerStreamRoute(method: 'GET', path: string, handler: StreamHandler, options?: RouteOptions): void;
|
|
799
|
+
registerMiddleware(middleware: MiddlewareHandler): void;
|
|
800
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
801
|
+
start(port: number, host?: string): Promise<void>;
|
|
802
|
+
stop(): Promise<void>;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
type RateLimitAction = 'block' | 'challenge' | 'throttle';
|
|
806
|
+
interface RateLimitRule {
|
|
807
|
+
requests: number;
|
|
808
|
+
window: string;
|
|
809
|
+
action: RateLimitAction;
|
|
810
|
+
}
|
|
811
|
+
interface RateLimitDecision {
|
|
812
|
+
allowed: boolean;
|
|
813
|
+
retryAfterSeconds?: number;
|
|
814
|
+
action: RateLimitAction;
|
|
815
|
+
}
|
|
816
|
+
interface SecurityConfigLike {
|
|
817
|
+
rateLimit: Record<string, RateLimitRule>;
|
|
818
|
+
csrf: boolean;
|
|
819
|
+
headers: {
|
|
820
|
+
hsts: boolean;
|
|
821
|
+
contentSecurityPolicy: string;
|
|
822
|
+
referrerPolicy: string;
|
|
823
|
+
xFrameOptions: string;
|
|
824
|
+
};
|
|
825
|
+
[key: string]: unknown;
|
|
826
|
+
}
|
|
827
|
+
interface ValidationResult {
|
|
828
|
+
valid: boolean;
|
|
829
|
+
errors: Array<{
|
|
830
|
+
code: string;
|
|
831
|
+
message: string;
|
|
832
|
+
path?: string;
|
|
833
|
+
}>;
|
|
834
|
+
}
|
|
835
|
+
interface DriftReport {
|
|
836
|
+
drift: boolean;
|
|
837
|
+
differences: Array<{
|
|
838
|
+
path: string;
|
|
839
|
+
configured: unknown;
|
|
840
|
+
actual: unknown;
|
|
841
|
+
}>;
|
|
842
|
+
}
|
|
843
|
+
interface SecurityState {
|
|
844
|
+
rulesApplied: string[];
|
|
845
|
+
lastValidatedAt: string;
|
|
846
|
+
}
|
|
847
|
+
interface SecurityAdapter extends AdapterBase {
|
|
848
|
+
applyMiddleware(app: HttpAdapter, config: SecurityConfigLike): Promise<void>;
|
|
849
|
+
validate(config: SecurityConfigLike): Promise<ValidationResult>;
|
|
850
|
+
drift?(config: SecurityConfigLike): Promise<DriftReport>;
|
|
851
|
+
inspect?(): Promise<SecurityState>;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
interface CommerceAdapter extends AdapterBase {
|
|
855
|
+
readonly providerName: string;
|
|
856
|
+
}
|
|
857
|
+
interface RefundOptions {
|
|
858
|
+
/** The same key on a retry makes the provider refund at most once. */
|
|
859
|
+
idempotencyKey?: string;
|
|
860
|
+
/** The order's currency: what a provider that no longer holds the payment answers in. */
|
|
861
|
+
currency?: string;
|
|
862
|
+
}
|
|
863
|
+
interface PaymentsAdapter extends CommerceAdapter {
|
|
864
|
+
readonly kind: 'payments';
|
|
865
|
+
createPaymentIntent(params: PaymentIntentParams): Promise<PaymentIntent>;
|
|
866
|
+
capturePayment(intentId: string, amountMinor?: number): Promise<PaymentCapture>;
|
|
867
|
+
/** Throws `PaymentError('refund_rejected')` when no money moved, `PaymentError('refund_unknown')` when it may have. */
|
|
868
|
+
refund(paymentId: string, amountMinor?: number, reason?: string, opts?: RefundOptions): Promise<Refund>;
|
|
869
|
+
getPaymentStatus(intentId: string): Promise<PaymentStatus>;
|
|
870
|
+
/** The intent as the provider holds it now, client secret included: what a shopper needs to pay it again. */
|
|
871
|
+
getPaymentIntent(intentId: string): Promise<PaymentIntent>;
|
|
872
|
+
/** Cancels an intent that has not been paid; throws `PaymentError('cancel_refused')` when the provider will not
|
|
873
|
+
* (the intent is processing or already captured). */
|
|
874
|
+
cancelPaymentIntent(intentId: string): Promise<void>;
|
|
875
|
+
parseWebhook(rawBody: Buffer | string, signature: string): Promise<WebhookResult>;
|
|
876
|
+
}
|
|
877
|
+
interface TransactionalEmail {
|
|
878
|
+
template: string;
|
|
879
|
+
to: string;
|
|
880
|
+
vars: Record<string, unknown>;
|
|
881
|
+
locale?: string;
|
|
882
|
+
}
|
|
883
|
+
interface EmailSendResult {
|
|
884
|
+
messageId: string | null;
|
|
885
|
+
accepted: boolean;
|
|
886
|
+
}
|
|
887
|
+
interface EmailAdapter extends CommerceAdapter {
|
|
888
|
+
readonly kind: 'email';
|
|
889
|
+
sendTransactional(params: TransactionalEmail): Promise<EmailSendResult>;
|
|
890
|
+
syncCustomerToList(customer: CustomerProfile): Promise<void>;
|
|
891
|
+
removeCustomerFromList(customerId: string): Promise<void>;
|
|
892
|
+
}
|
|
893
|
+
interface PaginationParams {
|
|
894
|
+
limit?: number;
|
|
895
|
+
cursor?: string;
|
|
896
|
+
}
|
|
897
|
+
interface ReviewsResult {
|
|
898
|
+
items: Review[];
|
|
899
|
+
nextCursor: string | null;
|
|
900
|
+
}
|
|
901
|
+
interface ReviewSubmission {
|
|
902
|
+
productId: string;
|
|
903
|
+
customerId: string | null;
|
|
904
|
+
orderId: string | null;
|
|
905
|
+
rating: number;
|
|
906
|
+
title: string;
|
|
907
|
+
body: string;
|
|
908
|
+
}
|
|
909
|
+
interface ReviewResult {
|
|
910
|
+
review: Review;
|
|
911
|
+
}
|
|
912
|
+
interface ReviewsAdapter extends CommerceAdapter {
|
|
913
|
+
readonly kind: 'reviews';
|
|
914
|
+
getProductReviews(productId: string, params?: PaginationParams & {
|
|
915
|
+
status?: ReviewModerationStatus;
|
|
916
|
+
}): Promise<ReviewsResult>;
|
|
917
|
+
getAggregateRating(productId: string): Promise<AggregateRating>;
|
|
918
|
+
submitReview(review: ReviewSubmission): Promise<ReviewResult>;
|
|
919
|
+
requestReview(orderId: string): Promise<void>;
|
|
920
|
+
}
|
|
921
|
+
interface SearchDocument {
|
|
922
|
+
id: string;
|
|
923
|
+
type: string;
|
|
924
|
+
fields: Record<string, unknown>;
|
|
925
|
+
}
|
|
926
|
+
interface IndexResult {
|
|
927
|
+
indexed: number;
|
|
928
|
+
}
|
|
929
|
+
interface SearchParams {
|
|
930
|
+
limit?: number;
|
|
931
|
+
cursor?: string;
|
|
932
|
+
filters?: Record<string, unknown>;
|
|
933
|
+
sort?: Array<{
|
|
934
|
+
field: string;
|
|
935
|
+
direction: 'asc' | 'desc';
|
|
936
|
+
}>;
|
|
937
|
+
}
|
|
938
|
+
interface SearchResult {
|
|
939
|
+
items: SearchDocument[];
|
|
940
|
+
total: number;
|
|
941
|
+
nextCursor: string | null;
|
|
942
|
+
}
|
|
943
|
+
interface FacetParams {
|
|
944
|
+
limit?: number;
|
|
945
|
+
filters?: Record<string, unknown>;
|
|
946
|
+
}
|
|
947
|
+
interface Facet {
|
|
948
|
+
field: string;
|
|
949
|
+
label: string;
|
|
950
|
+
values: Array<{
|
|
951
|
+
value: string;
|
|
952
|
+
label?: string;
|
|
953
|
+
count?: number;
|
|
954
|
+
}>;
|
|
955
|
+
}
|
|
956
|
+
interface SearchAdapter extends CommerceAdapter {
|
|
957
|
+
readonly kind: 'search';
|
|
958
|
+
index(documents: SearchDocument[]): Promise<IndexResult>;
|
|
959
|
+
remove(documentIds: string[]): Promise<void>;
|
|
960
|
+
search(query: string, params?: SearchParams): Promise<SearchResult>;
|
|
961
|
+
facet(field: string, params?: FacetParams): Promise<Facet>;
|
|
962
|
+
}
|
|
963
|
+
interface AnalyticsAdapter extends CommerceAdapter {
|
|
964
|
+
readonly kind: 'analytics';
|
|
965
|
+
track(event: string, properties: Record<string, unknown>): Promise<void>;
|
|
966
|
+
identify(userId: string, traits: Record<string, unknown>): Promise<void>;
|
|
967
|
+
}
|
|
968
|
+
interface ShippingRateParams {
|
|
969
|
+
fromPostalCode: string;
|
|
970
|
+
toPostalCode: string;
|
|
971
|
+
toCountry: string;
|
|
972
|
+
weightGrams: number;
|
|
973
|
+
currency: string;
|
|
974
|
+
}
|
|
975
|
+
interface ShippingRate {
|
|
976
|
+
carrier: string;
|
|
977
|
+
service: string;
|
|
978
|
+
amountMinor: number;
|
|
979
|
+
currency: string;
|
|
980
|
+
estimatedDays: number;
|
|
981
|
+
}
|
|
982
|
+
interface ShippingLabelParams {
|
|
983
|
+
orderId: string;
|
|
984
|
+
carrier: string;
|
|
985
|
+
service: string;
|
|
986
|
+
}
|
|
987
|
+
interface ShippingLabel {
|
|
988
|
+
labelUrl: string;
|
|
989
|
+
trackingNumber: string;
|
|
990
|
+
carrier: string;
|
|
991
|
+
}
|
|
992
|
+
interface ShippingTracking {
|
|
993
|
+
status: string;
|
|
994
|
+
lastUpdateAt: string;
|
|
995
|
+
}
|
|
996
|
+
interface ShippingAdapter extends CommerceAdapter {
|
|
997
|
+
readonly kind: 'shipping';
|
|
998
|
+
rate(params: ShippingRateParams): Promise<ShippingRate[]>;
|
|
999
|
+
createLabel(params: ShippingLabelParams): Promise<ShippingLabel>;
|
|
1000
|
+
track(trackingNumber: string): Promise<ShippingTracking>;
|
|
1001
|
+
}
|
|
1002
|
+
interface TaxLine {
|
|
1003
|
+
amountMinor: number;
|
|
1004
|
+
qty: number;
|
|
1005
|
+
}
|
|
1006
|
+
interface TaxCalculationParams {
|
|
1007
|
+
currency: string;
|
|
1008
|
+
shippingCountry: string;
|
|
1009
|
+
shippingRegion: string;
|
|
1010
|
+
lines: TaxLine[];
|
|
1011
|
+
}
|
|
1012
|
+
interface TaxCalculationResult {
|
|
1013
|
+
totalTaxMinor: number;
|
|
1014
|
+
ratePerLine: Array<{
|
|
1015
|
+
taxMinor: number;
|
|
1016
|
+
}>;
|
|
1017
|
+
}
|
|
1018
|
+
interface TaxAdapter extends CommerceAdapter {
|
|
1019
|
+
readonly kind: 'tax';
|
|
1020
|
+
calculate(params: TaxCalculationParams): Promise<TaxCalculationResult>;
|
|
1021
|
+
}
|
|
1022
|
+
interface AiAdapter extends CommerceAdapter {
|
|
1023
|
+
readonly kind: 'ai';
|
|
1024
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
1025
|
+
complete(prompt: string, opts?: {
|
|
1026
|
+
maxTokens?: number;
|
|
1027
|
+
}): Promise<string>;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
export { type AdapterBase, AdapterError, type AdapterErrorV1Payload, type Address, type AggregateRating, type AiAdapter, type AnalyticsAdapter, AuthError, type CaptureMethod, type Cart, type CartAbandonedV1Payload, type CartConvertedV1Payload, type CartCreatedV1Payload, type CartItem, type CartItemAddedV1Payload, type CartItemRemovedV1Payload, type CartUpdatedV1Payload, type Category, type CategoryCreatedV1Payload, type CategoryDeletedV1Payload, type CategoryUpdatedV1Payload, CheckoutError, type CheckoutPayment, type CommerceAdapter, ConfigError, type Customer, type CustomerAddress, type CustomerCreatedV1Payload, type CustomerDeletedV1Payload, type CustomerProfile, type CustomerUpdatedV1Payload, DEFAULT_PRODUCT_SORT, type DocumentStoreAdapter, type DriftReport, EVT_ADAPTER_ERROR, EVT_CART_ABANDONED, EVT_CART_CONVERTED, EVT_CART_CREATED, EVT_CART_ITEM_ADDED, EVT_CART_ITEM_REMOVED, EVT_CART_UPDATED, EVT_CATEGORY_CREATED, EVT_CATEGORY_DELETED, EVT_CATEGORY_UPDATED, EVT_CUSTOMER_CREATED, EVT_CUSTOMER_DELETED, EVT_CUSTOMER_REGISTERED, EVT_CUSTOMER_UPDATED, EVT_INVENTORY_CHANGED, EVT_INVENTORY_LOW_STOCK, EVT_INVENTORY_OUT_OF_STOCK, EVT_INVENTORY_RELEASED, EVT_INVENTORY_RESERVED, EVT_ORDER_CANCELLED, EVT_ORDER_DELIVERED, EVT_ORDER_FULFILLED, EVT_ORDER_PAID, EVT_ORDER_PARTIALLY_REFUNDED, EVT_ORDER_PLACED, EVT_ORDER_REFUNDED, EVT_ORDER_SHIPPED, EVT_PAYMENT_CAPTURED, EVT_PAYMENT_FAILED, EVT_PAYMENT_REFUNDED, EVT_PRODUCT_CREATED, EVT_PRODUCT_DELETED, EVT_PRODUCT_PUBLISHED, EVT_PRODUCT_UNPUBLISHED, EVT_PRODUCT_UPDATED, type EmailAdapter, type EmailSendResult, type ErrorContext, type EventBusAdapter, type EventHandler, type EventMetadata, type Facet, type FacetParams, type HealthReport, type HealthStatus, type HttpAdapter, HttpError, type HttpMethod, type IndexResult, type InventoryChangedV1Payload, type InventoryLowStockV1Payload, type InventoryOutOfStockV1Payload, type InventoryReleasedV1Payload, type InventoryReservation, type InventoryReservedV1Payload, type Logger, type MiddlewareHandler, type Money, NotFoundError, type NymbalEnvironment, NymbalError, type NymbalEvent, type NymbalEventMap, type NymbalEventType, ORDER_STATUS_TRANSITIONS, type Order, type OrderCancelledV1Payload, OrderConflictError, type OrderDeliveredV1Payload, type OrderFulfilledV1Payload, type OrderHistoryEntry, type OrderLineItem, type OrderPaidV1Payload, type OrderPartiallyRefundedV1Payload, type OrderPayment, type OrderPlacedV1Payload, type OrderRefund, type OrderRefundStatus, type OrderRefundedV1Payload, type OrderShippedV1Payload, type OrderStatus, PRODUCT_SORT_KEYS, type PaginationParams, type PayloadOf, type PaymentCapture, type PaymentCapturedV1Payload, PaymentError, type PaymentFailedV1Payload, type PaymentIntent, type PaymentIntentParams, type PaymentRefundedV1Payload, type PaymentState, type PaymentStatus, type PaymentsAdapter, type Product, type ProductCreatedV1Payload, type ProductDeletedV1Payload, type ProductMedia, type ProductPublishedV1Payload, type ProductSnapshot, type ProductSortKey, type ProductStatus, type ProductType, type ProductUnpublishedV1Payload, type ProductUpdatedV1Payload, type PutOptions, type QueryParams, type QueryResult, type RateLimitAction, type RateLimitDecision, type RateLimitRule, type Refund, type RefundOptions, type RequestAuth, type RequestContext, type ResponseCookie, type ResponseEnvelope, type RetryPolicy, type Review, type ReviewModerationStatus, type ReviewResult, type ReviewSubmission, type ReviewsAdapter, type ReviewsResult, type Role, type RouteHandler, type RouteOptions, STANDARD_EVENT_TYPES, type SearchAdapter, type SearchDocument, type SearchParams, type SearchResult, type SecurityAdapter, type SecurityConfigLike, type SecurityState, type ShippingAdapter, type ShippingLabel, type ShippingLabelParams, type ShippingRate, type ShippingRateParams, type ShippingTracking, type SseEvent, StatusTransitionError, type StockAdjustment, type StockAdjustmentReason, type StockStatus, type StreamContext, type StreamHandler, type Subscription, type SubscriptionConfig, type TaxAdapter, type TaxCalculationParams, type TaxCalculationResult, type TaxLine, type TransactionalEmail, ValidationError, type ValidationResult, type Variant, type VariantDimensions, type VariantOption, type VariantStatus, type WebhookResult, add, allocate, assertMinorUnits, assertOrderTransition, canTransitionOrder, money, mulBy, paymentState, refundableMinor, sub, sumMoney };
|