@proveanything/smartlinks 2.1.36 → 2.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ /** How a price is delivered: shipped, or delivered when paid. */
2
+ export type ShopDelivery = 'physical' | 'digital';
3
+ /**
4
+ * How a digital price is delivered:
5
+ * - `proof` a proof of ownership minted for the buyer (needs a signed-in buyer)
6
+ * - `download` files from the product's assets
7
+ * - `access` membership of a user group (needs a signed-in buyer)
8
+ * - `app` an app delivers it on `order.paid` and marks the line delivered
9
+ */
10
+ export type ShopDigitalKind = 'proof' | 'download' | 'access' | 'app';
11
+ export type ShopDeliveryConfig = {
12
+ kind: 'proof';
13
+ productId?: string;
14
+ } | {
15
+ kind: 'download';
16
+ assetIds: string[];
17
+ maxDownloads?: number;
18
+ } | {
19
+ kind: 'access';
20
+ userGroupId: string;
21
+ } | {
22
+ kind: 'app';
23
+ appId: string;
24
+ };
25
+ /** One price: a product (or variant) for sale in one currency. For sale = has an active price. */
26
+ export interface ShopPrice {
27
+ id: string;
28
+ collectionId: string;
29
+ productId: string;
30
+ variantId: string | null;
31
+ /** The app that put it on sale ('shop' unless another app did). SmartLinks' fee follows it. */
32
+ appId: string;
33
+ currency: string;
34
+ /** Minor units, VAT included. */
35
+ amount: number;
36
+ /** A "was" price to show crossed out. */
37
+ compareAtAmount: number | null;
38
+ delivery: ShopDelivery;
39
+ deliveryConfig: ShopDeliveryConfig | Record<string, never>;
40
+ /** Sell only what stock says is available; it's held while the buyer pays. */
41
+ trackStock: boolean;
42
+ active: boolean;
43
+ sort: number;
44
+ metadata: Record<string, any>;
45
+ createdAt: string;
46
+ updatedAt: string;
47
+ }
48
+ export interface ShopPriceInput {
49
+ productId: string;
50
+ variantId?: string | null;
51
+ /** The app putting it on sale. Must be installed in the collection; 'shop' by default. */
52
+ appId?: string;
53
+ /** Defaults to the shop's currency. */
54
+ currency?: string;
55
+ amount: number;
56
+ compareAtAmount?: number | null;
57
+ delivery?: ShopDelivery;
58
+ deliveryConfig?: ShopDeliveryConfig;
59
+ trackStock?: boolean;
60
+ active?: boolean;
61
+ sort?: number;
62
+ metadata?: Record<string, any>;
63
+ }
64
+ export type ShopPriceUpdate = Partial<Omit<ShopPriceInput, 'productId' | 'variantId' | 'currency'>>;
65
+ export interface ShopPriceListParams {
66
+ productId?: string;
67
+ currency?: string;
68
+ active?: boolean;
69
+ appId?: string;
70
+ limit?: number;
71
+ offset?: number;
72
+ }
73
+ export interface ShopShippingRate {
74
+ id: string;
75
+ label: string;
76
+ /** Minor units. */
77
+ amount: number;
78
+ /** "2-3 working days" */
79
+ days?: string;
80
+ }
81
+ /** The shop's settings (admin). Nothing here is secret; SmartLinks' own Stripe keys are server-side. */
82
+ export interface ShopSettings {
83
+ currency: string;
84
+ /** The app whose flows run on order events (emails, staff alerts). */
85
+ appId: string;
86
+ /** Shown to buyers before they pay (UK law: name, address, a way to get in touch). */
87
+ seller: {
88
+ name?: string;
89
+ address?: string;
90
+ email?: string;
91
+ phone?: string;
92
+ vatNumber?: string;
93
+ };
94
+ vat: {
95
+ registered: boolean;
96
+ rate: number;
97
+ };
98
+ shipping: {
99
+ rates: ShopShippingRate[];
100
+ /** Free delivery from this subtotal (minor units). */
101
+ freeOver: number | null;
102
+ /** Offer collection in person. */
103
+ collection: {
104
+ label: string;
105
+ } | null;
106
+ };
107
+ policies: {
108
+ returns?: string;
109
+ terms?: string;
110
+ privacy?: string;
111
+ };
112
+ /** Set by connecting Stripe (`shop.admin.connect`), never directly. */
113
+ stripe: {
114
+ accountId: string | null;
115
+ };
116
+ /** Where shop stock is held (any container with stock when not set). */
117
+ stockContainerId: string | null;
118
+ checkout: {
119
+ /** Where Stripe sends the buyer after paying; `?session_id=` is added. */
120
+ successUrl: string | null;
121
+ cancelUrl: string | null;
122
+ /** How long stock is held for an unpaid checkout: 30 to 1440 minutes. */
123
+ expiresMinutes: number;
124
+ /** Other hosts the checkout may return to (beyond smartlinks.app, smartlinks.host and the pages above). */
125
+ allowedHosts: string[];
126
+ };
127
+ digital: {
128
+ euBuyers: boolean;
129
+ };
130
+ /** Record a purchase interaction when an order is paid. */
131
+ interaction: {
132
+ interactionId: string | null;
133
+ };
134
+ }
135
+ /** What's still needed before the shop can take money. */
136
+ export interface ShopReadiness {
137
+ ready: boolean;
138
+ missing: {
139
+ key: string;
140
+ text: string;
141
+ }[];
142
+ }
143
+ /** GET /shop/settings: the settings, what's missing, and what SmartLinks takes (read-only). */
144
+ export interface ShopSettingsView extends ShopSettings {
145
+ readiness: ShopReadiness;
146
+ fee: {
147
+ appId: string;
148
+ bps: number;
149
+ percent: number;
150
+ };
151
+ }
152
+ /** A settings change: merged into what's stored; shipping rates are replaced as a whole. */
153
+ export type ShopSettingsPatch = Partial<Omit<ShopSettings, 'stripe' | 'shipping' | 'checkout' | 'vat' | 'seller' | 'digital' | 'interaction'>> & {
154
+ seller?: Partial<ShopSettings['seller']>;
155
+ vat?: Partial<ShopSettings['vat']>;
156
+ shipping?: Partial<ShopSettings['shipping']>;
157
+ checkout?: Partial<ShopSettings['checkout']>;
158
+ digital?: Partial<ShopSettings['digital']>;
159
+ interaction?: Partial<ShopSettings['interaction']>;
160
+ };
161
+ export interface ShopConnectStatus {
162
+ connected: boolean;
163
+ chargesEnabled?: boolean;
164
+ detailsSubmitted?: boolean;
165
+ payoutsEnabled?: boolean;
166
+ id?: string;
167
+ }
168
+ /** What a shop front reads: nothing private. */
169
+ export interface ShopPublicConfig {
170
+ currency: string;
171
+ seller: {
172
+ name: string | null;
173
+ address: string | null;
174
+ email: string | null;
175
+ vatNumber?: string;
176
+ };
177
+ vat: {
178
+ registered: boolean;
179
+ rate: number;
180
+ };
181
+ shipping: ShopSettings['shipping'];
182
+ policies: ShopSettings['policies'];
183
+ digital: {
184
+ euBuyers: boolean;
185
+ };
186
+ /** false until the shop can take payments. */
187
+ ready: boolean;
188
+ }
189
+ /** One thing for sale, as a shop front shows it. */
190
+ export interface ShopProduct {
191
+ priceId: string;
192
+ productId: string;
193
+ variantId: string | null;
194
+ name: string;
195
+ description: string | null;
196
+ heroImage: any;
197
+ amount: number;
198
+ compareAtAmount: number | null;
199
+ currency: string;
200
+ delivery: ShopDelivery;
201
+ deliveryKind: ShopDigitalKind | null;
202
+ /** A proof or access goes to an account: the buyer must sign in before checking out. */
203
+ needsSignIn: boolean;
204
+ /** How many can be bought now (tracked stock), or null when stock isn't tracked. */
205
+ available: number | null;
206
+ inStock: boolean;
207
+ }
208
+ export interface ShopCheckoutLine {
209
+ productId: string;
210
+ variantId?: string | null;
211
+ quantity?: number;
212
+ }
213
+ export interface ShopCheckoutInput {
214
+ lines: ShopCheckoutLine[];
215
+ /** Needed for physical items when the shop has several rates (collection is `'collection'`). */
216
+ shippingRateId?: string;
217
+ /** Pre-fills Stripe's form; the order's email comes from the payment. */
218
+ email?: string;
219
+ /** Defaults to the shop's checkout pages. Must be on an allowed host. */
220
+ successUrl?: string;
221
+ cancelUrl?: string;
222
+ /** Digital items: the buyer agreed to delivery straight away, ending the 14-day right to cancel. Required for them. */
223
+ acceptances?: {
224
+ digitalImmediate?: boolean;
225
+ };
226
+ }
227
+ export interface ShopCheckoutResult {
228
+ orderId: string;
229
+ /** Send the buyer here (Stripe's hosted checkout). */
230
+ checkoutUrl: string;
231
+ /** The stock is held until then. */
232
+ expiresAt: string;
233
+ total: number;
234
+ currency: string;
235
+ }
236
+ export type ShopOrderStatus = 'pending-payment' | 'paid' | 'fulfilled' | 'partly-refunded' | 'refunded' | 'expired';
237
+ export interface ShopOrderLine {
238
+ id: string;
239
+ productId: string;
240
+ variantId: string | null;
241
+ name: string | null;
242
+ quantity: number;
243
+ unitAmount: number | null;
244
+ lineTotal: number | null;
245
+ delivery: ShopDelivery | null;
246
+ deliveryKind: ShopDigitalKind | null;
247
+ /** Shipped, or delivered. */
248
+ quantityDone: number;
249
+ quantityRefunded: number;
250
+ priceId: string | null;
251
+ appId: string;
252
+ /** Asset ids, for a download line. */
253
+ files?: string[];
254
+ /** Admin only: SmartLinks' fee on this line. */
255
+ fee?: {
256
+ bps: number;
257
+ amount: number;
258
+ };
259
+ }
260
+ export interface ShopShipment {
261
+ id: string;
262
+ at: string;
263
+ lines: {
264
+ itemId: string;
265
+ quantity: number;
266
+ }[];
267
+ carrier?: string;
268
+ trackingNumber?: string;
269
+ trackingUrl?: string;
270
+ }
271
+ export interface ShopOrder {
272
+ id: string;
273
+ collectionId: string;
274
+ orderRef: string | null;
275
+ status: ShopOrderStatus;
276
+ source: 'shop';
277
+ contactId: string | null;
278
+ currency: string;
279
+ subtotal: number | null;
280
+ shipping: number | null;
281
+ /** VAT inside the total, for the receipt. */
282
+ tax: number | null;
283
+ total: number | null;
284
+ refunded: number;
285
+ paidAt: string | null;
286
+ expiresAt: string | null;
287
+ createdAt: string;
288
+ updatedAt: string;
289
+ email: string | null;
290
+ shippingChoice: ShopShippingRate | null;
291
+ shippingAddress: Record<string, any> | null;
292
+ shipments: ShopShipment[];
293
+ lines: ShopOrderLine[];
294
+ }
295
+ /** The seller's view: payment, refunds, anything that needs a look, and SmartLinks' fee. */
296
+ export interface ShopAdminOrder extends ShopOrder {
297
+ payment: {
298
+ provider: 'stripe';
299
+ sessionId: string;
300
+ paymentIntentId: string | null;
301
+ amount: number;
302
+ currency: string;
303
+ } | null;
304
+ refunds: {
305
+ id: string;
306
+ amount: number;
307
+ at: string;
308
+ lines: {
309
+ itemId: string;
310
+ quantity: number;
311
+ }[];
312
+ shipping?: number;
313
+ restock?: boolean;
314
+ reason?: string;
315
+ external?: boolean;
316
+ }[];
317
+ /** AMOUNT_MISMATCH, STOCK_SHORT, DELIVERY_FAILED, PROOF_NOT_WITHDRAWN… */
318
+ attention: {
319
+ code: string;
320
+ text: string;
321
+ itemId?: string;
322
+ }[];
323
+ acceptances: {
324
+ digitalImmediate?: boolean;
325
+ at: string;
326
+ } | null;
327
+ paymentRef: string | null;
328
+ fee: {
329
+ amount: number;
330
+ };
331
+ }
332
+ /** The buyer's view, with links for bought files once paid. */
333
+ export interface ShopBuyerOrder extends ShopOrder {
334
+ downloads: {
335
+ name: string;
336
+ url: string;
337
+ }[];
338
+ }
339
+ export interface ShopOrderListParams {
340
+ /** One status or several, comma-separated. Unpaid and expired checkouts are left out unless asked for. */
341
+ status?: string;
342
+ contactId?: string;
343
+ includeExpired?: boolean;
344
+ limit?: number;
345
+ offset?: number;
346
+ }
347
+ export interface ShopPage<T> {
348
+ items: T[];
349
+ total: number;
350
+ limit: number;
351
+ offset: number;
352
+ }
353
+ export interface ShopShipInput {
354
+ /** Which lines and how many; all that's left when omitted. */
355
+ lines?: {
356
+ itemId: string;
357
+ quantity?: number;
358
+ }[];
359
+ carrier?: string;
360
+ trackingNumber?: string;
361
+ /** https only. */
362
+ trackingUrl?: string;
363
+ }
364
+ export interface ShopRefundInput {
365
+ /** Lines and quantities at the price sold. With no lines and no amount: everything left, shipping included. */
366
+ lines?: {
367
+ itemId: string;
368
+ quantity?: number;
369
+ }[];
370
+ /** Refund the shipping too (with `lines`). */
371
+ shipping?: boolean;
372
+ /** A goodwill amount instead of lines (minor units). */
373
+ amount?: number;
374
+ /** Unsent held stock goes back to available. Default true. */
375
+ restock?: boolean;
376
+ reason?: string;
377
+ }
@@ -0,0 +1,5 @@
1
+ // src/types/shop.ts
2
+ // Basic commerce: prices, the shop's settings, checkout and shop orders — see docs/shop.md.
3
+ //
4
+ // Money is always a whole number of MINOR units (pence, cents): 1299 = £12.99. Prices include VAT.
5
+ export {};