@putiikkipalvelu/storefront-sdk 0.7.3 → 0.8.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/dist/index.cjs +88 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +134 -22
- package/dist/index.d.ts +134 -22
- package/dist/index.js +82 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -345,6 +345,8 @@ interface Product {
|
|
|
345
345
|
saleStartDate: string | null;
|
|
346
346
|
/** Sale end date (ISO 8601), null = no end */
|
|
347
347
|
saleEndDate: string | null;
|
|
348
|
+
/** True if this product is delivered as a digital download (no shipping) */
|
|
349
|
+
isDigital?: boolean;
|
|
348
350
|
/** Product variations (minimal fields for listing) */
|
|
349
351
|
variations: ProductVariationListing[];
|
|
350
352
|
}
|
|
@@ -362,6 +364,10 @@ interface ProductTicketInfo {
|
|
|
362
364
|
requiresHolder: boolean;
|
|
363
365
|
/** Maximum uses per ticket (0 = unlimited) */
|
|
364
366
|
maxUses: number;
|
|
367
|
+
/** Ticket sales start (ISO 8601), null = sales open immediately */
|
|
368
|
+
salesStart: string | null;
|
|
369
|
+
/** Ticket sales end (ISO 8601), null = sales never end */
|
|
370
|
+
salesEnd: string | null;
|
|
365
371
|
}
|
|
366
372
|
interface ProductDetail extends Omit<Product, "variations"> {
|
|
367
373
|
/** Product weight in kg (for shipping calculations) */
|
|
@@ -378,6 +384,11 @@ interface ProductDetail extends Omit<Product, "variations"> {
|
|
|
378
384
|
variations: ProductVariation[];
|
|
379
385
|
/** Ticket info (present if product is a ticket, null otherwise) */
|
|
380
386
|
ticketInfo: ProductTicketInfo | null;
|
|
387
|
+
/**
|
|
388
|
+
* HTML instructions shown to the buyer after a digital purchase.
|
|
389
|
+
* Only populated when isDigital=true; null otherwise.
|
|
390
|
+
*/
|
|
391
|
+
digitalContent?: string | null;
|
|
381
392
|
}
|
|
382
393
|
/**
|
|
383
394
|
* Response from /sorted-products
|
|
@@ -472,6 +483,8 @@ interface CartItem {
|
|
|
472
483
|
variation?: ProductVariation;
|
|
473
484
|
/** Whether this item is a ticket product (no shipping required) */
|
|
474
485
|
isTicket?: boolean;
|
|
486
|
+
/** Whether this item is a digital product (no shipping required) */
|
|
487
|
+
isDigital?: boolean;
|
|
475
488
|
}
|
|
476
489
|
/**
|
|
477
490
|
* Response from GET /cart, POST /cart, PATCH /cart, DELETE /cart
|
|
@@ -496,6 +509,8 @@ interface CartValidationChanges {
|
|
|
496
509
|
quantityAdjusted: number;
|
|
497
510
|
/** Number of items with changed price */
|
|
498
511
|
priceChanged: number;
|
|
512
|
+
/** Number of ticket items removed because sales window is not open or has ended */
|
|
513
|
+
ticketSalesWindowRemoved: number;
|
|
499
514
|
/** Whether discount code was removed */
|
|
500
515
|
discountCouponRemoved: boolean;
|
|
501
516
|
/** Reason why discount was removed (only present if discountCouponRemoved is true) */
|
|
@@ -737,6 +752,11 @@ interface ConfirmationOrderLineItem {
|
|
|
737
752
|
vatRate: number;
|
|
738
753
|
/** Product images array */
|
|
739
754
|
images: string[];
|
|
755
|
+
/**
|
|
756
|
+
* Snapshot of the product's digital instructions at purchase time.
|
|
757
|
+
* Populated for digital products; null otherwise.
|
|
758
|
+
*/
|
|
759
|
+
digitalContent?: string | null;
|
|
740
760
|
}
|
|
741
761
|
/**
|
|
742
762
|
* Customer delivery information attached to an order
|
|
@@ -1698,6 +1718,80 @@ interface TicketUseResponse {
|
|
|
1698
1718
|
ticket: PurchasedTicket;
|
|
1699
1719
|
}
|
|
1700
1720
|
|
|
1721
|
+
/**
|
|
1722
|
+
* Digital Downloads Types
|
|
1723
|
+
*
|
|
1724
|
+
* Types for digital product downloads (instructions + downloadable files).
|
|
1725
|
+
*/
|
|
1726
|
+
/**
|
|
1727
|
+
* A single downloadable file within an order line item.
|
|
1728
|
+
* Snapshotted at purchase time — persists even if the merchant deletes the
|
|
1729
|
+
* original product or file.
|
|
1730
|
+
*/
|
|
1731
|
+
interface OrderDownload {
|
|
1732
|
+
/** Unique download record ID (pass this to getDownloadUrl) */
|
|
1733
|
+
id: string;
|
|
1734
|
+
/** Merchant-editable file name shown to the customer */
|
|
1735
|
+
displayName: string;
|
|
1736
|
+
/** File size in bytes */
|
|
1737
|
+
sizeBytes: number;
|
|
1738
|
+
/** MIME type, e.g. "application/pdf" */
|
|
1739
|
+
mimeType: string;
|
|
1740
|
+
/** How many times this file has been downloaded on this order */
|
|
1741
|
+
downloadCount: number;
|
|
1742
|
+
/** Max downloads allowed on this order (null = unlimited) */
|
|
1743
|
+
maxDownloads: number | null;
|
|
1744
|
+
/** Downloads remaining (null = unlimited) */
|
|
1745
|
+
remaining: number | null;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* A line item in an order with digital content and/or downloadable files.
|
|
1749
|
+
* Only line items that either have instructions or files are returned by
|
|
1750
|
+
* the downloads list endpoint.
|
|
1751
|
+
*/
|
|
1752
|
+
interface OrderDownloadLineItem {
|
|
1753
|
+
/** Order line item ID */
|
|
1754
|
+
id: string;
|
|
1755
|
+
/** Product/variation display name */
|
|
1756
|
+
name: string;
|
|
1757
|
+
/** Quantity ordered */
|
|
1758
|
+
quantity: number;
|
|
1759
|
+
/** Sanitized HTML instructions (from merchant's TipTap field). May be null. */
|
|
1760
|
+
digitalContent: string | null;
|
|
1761
|
+
/** Downloadable files attached to this line item. May be empty. */
|
|
1762
|
+
downloads: OrderDownload[];
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Response from GET /order/:id/downloads
|
|
1766
|
+
*/
|
|
1767
|
+
interface OrderDownloadsResponse {
|
|
1768
|
+
/** Order ID the downloads belong to */
|
|
1769
|
+
orderId: string;
|
|
1770
|
+
/** Line items with digital content and/or downloads */
|
|
1771
|
+
items: OrderDownloadLineItem[];
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Response from POST /order/:id/downloads/:downloadId
|
|
1775
|
+
* Short-lived presigned URL for downloading the file directly from R2.
|
|
1776
|
+
*/
|
|
1777
|
+
interface DownloadUrlResponse {
|
|
1778
|
+
/** Presigned download URL (typically valid ~5 minutes) */
|
|
1779
|
+
url: string;
|
|
1780
|
+
/** How long the URL stays valid, in seconds */
|
|
1781
|
+
expiresIn: number;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Options for calling the downloads endpoints.
|
|
1785
|
+
* Authentication is granted via EITHER a token (from order confirmation email)
|
|
1786
|
+
* OR a valid customer session (logged-in customer who owns the order).
|
|
1787
|
+
*/
|
|
1788
|
+
interface DownloadsAuthOptions {
|
|
1789
|
+
/** Download token from the confirmation email URL. Use this for guest access. */
|
|
1790
|
+
token?: string;
|
|
1791
|
+
/** Customer session token. Use this for logged-in customer access. */
|
|
1792
|
+
sessionId?: string;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1701
1795
|
/**
|
|
1702
1796
|
* Putiikkipalvelu Storefront SDK Types
|
|
1703
1797
|
*
|
|
@@ -2567,7 +2661,7 @@ declare function createCustomerResource(fetcher: Fetcher): {
|
|
|
2567
2661
|
type CustomerResource = ReturnType<typeof createCustomerResource>;
|
|
2568
2662
|
|
|
2569
2663
|
/**
|
|
2570
|
-
* Order resource for fetching order details
|
|
2664
|
+
* Order resource for fetching order details and digital downloads
|
|
2571
2665
|
*
|
|
2572
2666
|
* Used for order confirmation pages and viewing order details.
|
|
2573
2667
|
* For customer order history, use the customer.getOrders() method instead.
|
|
@@ -2590,36 +2684,54 @@ declare function createOrderResource(fetcher: Fetcher): {
|
|
|
2590
2684
|
* console.log(`Order #${order.orderNumber} - ${order.status}`);
|
|
2591
2685
|
* console.log(`Total: ${order.totalAmount / 100} EUR`);
|
|
2592
2686
|
* ```
|
|
2687
|
+
*/
|
|
2688
|
+
get(orderId: string, options?: FetchOptions): Promise<Order>;
|
|
2689
|
+
/**
|
|
2690
|
+
* List downloadable files for a paid order.
|
|
2593
2691
|
*
|
|
2594
|
-
*
|
|
2692
|
+
* Requires EITHER a download token (from the order confirmation email)
|
|
2693
|
+
* OR a valid customer session (for logged-in customers viewing their own
|
|
2694
|
+
* order history).
|
|
2695
|
+
*
|
|
2696
|
+
* Returns only line items that have digital content or downloadable files.
|
|
2697
|
+
* The order must be paid (status !== PENDING or FAILED).
|
|
2698
|
+
*
|
|
2699
|
+
* @param orderId - The order ID
|
|
2700
|
+
* @param auth - Token (guest) or sessionId (logged-in customer)
|
|
2701
|
+
* @param options - Fetch options
|
|
2702
|
+
*
|
|
2703
|
+
* @example Guest access via email token
|
|
2595
2704
|
* ```typescript
|
|
2596
|
-
* const
|
|
2597
|
-
*
|
|
2598
|
-
* });
|
|
2705
|
+
* const token = new URLSearchParams(location.search).get("token");
|
|
2706
|
+
* const { items } = await client.order.listDownloads(orderId, { token });
|
|
2599
2707
|
* ```
|
|
2600
2708
|
*
|
|
2601
|
-
* @example
|
|
2709
|
+
* @example Logged-in customer
|
|
2602
2710
|
* ```typescript
|
|
2603
|
-
* const
|
|
2604
|
-
* order.OrderLineItems.forEach(item => {
|
|
2605
|
-
* if (item.itemType !== 'SHIPPING') {
|
|
2606
|
-
* console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);
|
|
2607
|
-
* }
|
|
2608
|
-
* });
|
|
2711
|
+
* const { items } = await client.order.listDownloads(orderId, { sessionId });
|
|
2609
2712
|
* ```
|
|
2713
|
+
*/
|
|
2714
|
+
listDownloads(orderId: string, auth?: DownloadsAuthOptions, options?: FetchOptions): Promise<OrderDownloadsResponse>;
|
|
2715
|
+
/**
|
|
2716
|
+
* Issue a short-lived presigned URL to download a specific file from a
|
|
2717
|
+
* paid order. Increments the download counter and records a download
|
|
2718
|
+
* event (IP, user agent) on the server.
|
|
2719
|
+
*
|
|
2720
|
+
* The returned URL is typically valid for ~5 minutes — redirect the
|
|
2721
|
+
* browser to it or trigger a download immediately.
|
|
2722
|
+
*
|
|
2723
|
+
* @param orderId - The order ID
|
|
2724
|
+
* @param downloadId - The OrderDownload.id
|
|
2725
|
+
* @param auth - Token (guest) or sessionId (logged-in customer)
|
|
2726
|
+
* @param options - Fetch options
|
|
2610
2727
|
*
|
|
2611
|
-
* @example
|
|
2728
|
+
* @example
|
|
2612
2729
|
* ```typescript
|
|
2613
|
-
* const
|
|
2614
|
-
*
|
|
2615
|
-
* console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);
|
|
2616
|
-
* order.orderShipmentMethod.trackingUrls?.forEach(url => {
|
|
2617
|
-
* console.log(`Track at: ${url}`);
|
|
2618
|
-
* });
|
|
2619
|
-
* }
|
|
2730
|
+
* const { url } = await client.order.getDownloadUrl(orderId, downloadId, { token });
|
|
2731
|
+
* window.location.href = url;
|
|
2620
2732
|
* ```
|
|
2621
2733
|
*/
|
|
2622
|
-
|
|
2734
|
+
getDownloadUrl(orderId: string, downloadId: string, auth?: DownloadsAuthOptions, options?: FetchOptions): Promise<DownloadUrlResponse>;
|
|
2623
2735
|
};
|
|
2624
2736
|
/**
|
|
2625
2737
|
* Type for the order resource
|
|
@@ -3224,4 +3336,4 @@ declare class VerificationRequiredError extends StorefrontError {
|
|
|
3224
3336
|
constructor(message: string, customerId: string);
|
|
3225
3337
|
}
|
|
3226
3338
|
|
|
3227
|
-
export { type AboutBlock, type AccordionBlock, type AccordionItem, type AddToCartParams, type AddToWishlistResponse, type AnalyticsConfig, type AppliedDiscount, type ApplyDiscountParams, type ApplyDiscountResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CarouselContentBlock, type CarouselContentItem, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type DiscountApplyErrorCode, type DiscountCodeError, type DiscountMessageLocale, type DiscountRemovalReason, type DiscountType, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FormatDiscountOptions, type GalleryBlock, type GalleryItem, type GetDiscountParams, type GetDiscountResponse, type GetOrdersResponse, type GetUserResponse, type HomeDeliveryOption, type ImageAspectRatio, type ImageGridBlock, type ImageGridItem, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, type MarkdownBlock, type NavPage, NotFoundError, type OpeningHours, type OpeningHoursBlock, type OpeningHoursEntry, type Order, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PageBlock, type PageSeo, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupPointOption, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductTicketInfo, type ProductVariation, type ProductVariationListing, type PurchasedTicket, RateLimitError, type RegisterData, type RegisterResponse, type RemoveDiscountParams, type RemoveDiscountResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type ShipmentMethodsResponse, type ShowcaseBlock, type ShowcaseItem, type StoreConfig, type StoreInfo, type StorePage, type StoreSeo, type StorefrontClient, type StorefrontClientConfig, StorefrontError, type StripeCheckoutResponse, type TableBlock, type TextGridBlock, type TextGridItem, type TicketEvent, type TicketEventsResponse, type TicketGetResponse, type TicketHolderData, type TicketStatus, type TicketUseResponse, type TicketValidatePinResponse, type UpdateCartQuantityParams, type UpdateProfileData, type UpdateProfileResponse, ValidationError, type VariationOption, VerificationRequiredError, type VerifyEmailResponse, type WishlistItem, type WishlistProduct, type WishlistResponse, type WishlistVariation, type WishlistVariationOption, calculateCartWithCampaigns, calculateDiscountAmount, createStorefrontClient, formatDiscountValue, getDiscountApplyErrorMessage, getDiscountRemovalMessage, getPriceInfo, isSaleActive };
|
|
3339
|
+
export { type AboutBlock, type AccordionBlock, type AccordionItem, type AddToCartParams, type AddToWishlistResponse, type AnalyticsConfig, type AppliedDiscount, type ApplyDiscountParams, type ApplyDiscountResponse, AuthError, type BuyXPayYCampaign, type CalculatedCartItem, type Campaign, type CampaignType, type CarouselContentBlock, type CarouselContentItem, type CartCalculationResult, type CartItem, type CartResponse, type CartSessionOptions, type CartValidationChanges, type CartValidationResponse, type Category, type CategoryReference, type CategoryResponse, type CheckoutCustomerData, type CheckoutErrorCode, type CheckoutErrorDetails, type CheckoutOptions, type CheckoutParams, type CheckoutShipmentMethod, type ConfirmationItemType, type ConfirmationOrderCustomerData, type ConfirmationOrderLineItem, type ConfirmationOrderShipmentMethod, type Customer, type CustomerOrder, type DeleteAccountResponse, type DiscountApplyErrorCode, type DiscountCodeError, type DiscountMessageLocale, type DiscountRemovalReason, type DiscountType, type DownloadUrlResponse, type DownloadsAuthOptions, type FeatureFlags, type FetchOptions, type ForgotPasswordResponse, type FormatDiscountOptions, type GalleryBlock, type GalleryItem, type GetDiscountParams, type GetDiscountResponse, type GetOrdersResponse, type GetUserResponse, type HomeDeliveryOption, type ImageAspectRatio, type ImageGridBlock, type ImageGridItem, type LoginOptions, type LoginResponse, type LoginVerificationRequiredResponse, type LogoutResponse, type MarkdownBlock, type NavPage, NotFoundError, type OpeningHours, type OpeningHoursBlock, type OpeningHoursEntry, type Order, type OrderDownload, type OrderDownloadLineItem, type OrderDownloadsResponse, type OrderLineItem, type OrderProductInfo, type OrderShipmentMethod, type OrderStatus, type PageBlock, type PageSeo, type PaymentConfig, type PaytrailCheckoutResponse, type PaytrailGroup, type PaytrailProvider, type PickupPointOption, type PriceInfo, type Product, type ProductCountResponse, type ProductDetail, type ProductListParams, type ProductListResponse, type ProductSortOption, type ProductTicketInfo, type ProductVariation, type ProductVariationListing, type PurchasedTicket, RateLimitError, type RegisterData, type RegisterResponse, type RemoveDiscountParams, type RemoveDiscountResponse, type RemoveFromCartParams, type RemoveFromWishlistResponse, type ResendVerificationResponse, type ResetPasswordResponse, type ShipitShippingMethod, type ShipmentMethod, type ShipmentMethodsResponse, type ShowcaseBlock, type ShowcaseItem, type StoreConfig, type StoreInfo, type StorePage, type StoreSeo, type StorefrontClient, type StorefrontClientConfig, StorefrontError, type StripeCheckoutResponse, type TableBlock, type TextGridBlock, type TextGridItem, type TicketEvent, type TicketEventsResponse, type TicketGetResponse, type TicketHolderData, type TicketStatus, type TicketUseResponse, type TicketValidatePinResponse, type UpdateCartQuantityParams, type UpdateProfileData, type UpdateProfileResponse, ValidationError, type VariationOption, VerificationRequiredError, type VerifyEmailResponse, type WishlistItem, type WishlistProduct, type WishlistResponse, type WishlistVariation, type WishlistVariationOption, calculateCartWithCampaigns, calculateDiscountAmount, createStorefrontClient, formatDiscountValue, getDiscountApplyErrorMessage, getDiscountRemovalMessage, getPriceInfo, isSaleActive };
|
package/dist/index.js
CHANGED
|
@@ -847,7 +847,7 @@ function createCustomerResource(fetcher) {
|
|
|
847
847
|
*/
|
|
848
848
|
async register(data, fetchOptions) {
|
|
849
849
|
return fetcher.request(
|
|
850
|
-
"/api/storefront/v1/customer/
|
|
850
|
+
"/api/storefront/v1/customer/register",
|
|
851
851
|
{
|
|
852
852
|
method: "POST",
|
|
853
853
|
body: data,
|
|
@@ -894,7 +894,7 @@ function createCustomerResource(fetcher) {
|
|
|
894
894
|
headers["x-cart-id"] = options.cartId;
|
|
895
895
|
}
|
|
896
896
|
return fetcher.request(
|
|
897
|
-
"/api/storefront/v1/customer/
|
|
897
|
+
"/api/storefront/v1/customer/login",
|
|
898
898
|
{
|
|
899
899
|
method: "POST",
|
|
900
900
|
body: { email, password },
|
|
@@ -926,7 +926,7 @@ function createCustomerResource(fetcher) {
|
|
|
926
926
|
*/
|
|
927
927
|
async logout(sessionId, fetchOptions) {
|
|
928
928
|
return fetcher.request(
|
|
929
|
-
"/api/storefront/v1/customer/
|
|
929
|
+
"/api/storefront/v1/customer/logout",
|
|
930
930
|
{
|
|
931
931
|
method: "POST",
|
|
932
932
|
headers: buildSessionHeaders(sessionId),
|
|
@@ -953,7 +953,7 @@ function createCustomerResource(fetcher) {
|
|
|
953
953
|
*/
|
|
954
954
|
async getUser(sessionId, fetchOptions) {
|
|
955
955
|
return fetcher.request(
|
|
956
|
-
"/api/storefront/v1/customer/
|
|
956
|
+
"/api/storefront/v1/customer/get-user",
|
|
957
957
|
{
|
|
958
958
|
method: "GET",
|
|
959
959
|
headers: buildSessionHeaders(sessionId),
|
|
@@ -980,7 +980,7 @@ function createCustomerResource(fetcher) {
|
|
|
980
980
|
*/
|
|
981
981
|
async verifyEmail(token, fetchOptions) {
|
|
982
982
|
return fetcher.request(
|
|
983
|
-
"/api/storefront/v1/customer/
|
|
983
|
+
"/api/storefront/v1/customer/verify-email",
|
|
984
984
|
{
|
|
985
985
|
method: "GET",
|
|
986
986
|
params: { token },
|
|
@@ -1008,7 +1008,7 @@ function createCustomerResource(fetcher) {
|
|
|
1008
1008
|
*/
|
|
1009
1009
|
async resendVerification(customerId, fetchOptions) {
|
|
1010
1010
|
return fetcher.request(
|
|
1011
|
-
"/api/storefront/v1/customer/
|
|
1011
|
+
"/api/storefront/v1/customer/resend-verification",
|
|
1012
1012
|
{
|
|
1013
1013
|
method: "POST",
|
|
1014
1014
|
body: { customerId },
|
|
@@ -1039,7 +1039,7 @@ function createCustomerResource(fetcher) {
|
|
|
1039
1039
|
*/
|
|
1040
1040
|
async forgotPassword(email, fetchOptions) {
|
|
1041
1041
|
return fetcher.request(
|
|
1042
|
-
"/api/storefront/v1/customer/
|
|
1042
|
+
"/api/storefront/v1/customer/forgot-password",
|
|
1043
1043
|
{
|
|
1044
1044
|
method: "POST",
|
|
1045
1045
|
body: { email },
|
|
@@ -1079,7 +1079,7 @@ function createCustomerResource(fetcher) {
|
|
|
1079
1079
|
*/
|
|
1080
1080
|
async resetPassword(token, password, fetchOptions) {
|
|
1081
1081
|
return fetcher.request(
|
|
1082
|
-
"/api/storefront/v1/customer/
|
|
1082
|
+
"/api/storefront/v1/customer/reset-password",
|
|
1083
1083
|
{
|
|
1084
1084
|
method: "POST",
|
|
1085
1085
|
body: { token, password },
|
|
@@ -1296,6 +1296,11 @@ function createCustomerResource(fetcher) {
|
|
|
1296
1296
|
}
|
|
1297
1297
|
|
|
1298
1298
|
// src/resources/order.ts
|
|
1299
|
+
function buildDownloadAuthHeaders(auth) {
|
|
1300
|
+
const headers = {};
|
|
1301
|
+
if (auth?.sessionId) headers["x-session-id"] = auth.sessionId;
|
|
1302
|
+
return headers;
|
|
1303
|
+
}
|
|
1299
1304
|
function createOrderResource(fetcher) {
|
|
1300
1305
|
return {
|
|
1301
1306
|
/**
|
|
@@ -1315,40 +1320,87 @@ function createOrderResource(fetcher) {
|
|
|
1315
1320
|
* console.log(`Order #${order.orderNumber} - ${order.status}`);
|
|
1316
1321
|
* console.log(`Total: ${order.totalAmount / 100} EUR`);
|
|
1317
1322
|
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
async get(orderId, options) {
|
|
1325
|
+
return fetcher.request(
|
|
1326
|
+
`/api/storefront/v1/order/${encodeURIComponent(orderId)}`,
|
|
1327
|
+
{
|
|
1328
|
+
...options
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
},
|
|
1332
|
+
/**
|
|
1333
|
+
* List downloadable files for a paid order.
|
|
1318
1334
|
*
|
|
1319
|
-
*
|
|
1335
|
+
* Requires EITHER a download token (from the order confirmation email)
|
|
1336
|
+
* OR a valid customer session (for logged-in customers viewing their own
|
|
1337
|
+
* order history).
|
|
1338
|
+
*
|
|
1339
|
+
* Returns only line items that have digital content or downloadable files.
|
|
1340
|
+
* The order must be paid (status !== PENDING or FAILED).
|
|
1341
|
+
*
|
|
1342
|
+
* @param orderId - The order ID
|
|
1343
|
+
* @param auth - Token (guest) or sessionId (logged-in customer)
|
|
1344
|
+
* @param options - Fetch options
|
|
1345
|
+
*
|
|
1346
|
+
* @example Guest access via email token
|
|
1320
1347
|
* ```typescript
|
|
1321
|
-
* const
|
|
1322
|
-
*
|
|
1323
|
-
* });
|
|
1348
|
+
* const token = new URLSearchParams(location.search).get("token");
|
|
1349
|
+
* const { items } = await client.order.listDownloads(orderId, { token });
|
|
1324
1350
|
* ```
|
|
1325
1351
|
*
|
|
1326
|
-
* @example
|
|
1352
|
+
* @example Logged-in customer
|
|
1327
1353
|
* ```typescript
|
|
1328
|
-
* const
|
|
1329
|
-
* order.OrderLineItems.forEach(item => {
|
|
1330
|
-
* if (item.itemType !== 'SHIPPING') {
|
|
1331
|
-
* console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);
|
|
1332
|
-
* }
|
|
1333
|
-
* });
|
|
1354
|
+
* const { items } = await client.order.listDownloads(orderId, { sessionId });
|
|
1334
1355
|
* ```
|
|
1356
|
+
*/
|
|
1357
|
+
async listDownloads(orderId, auth, options) {
|
|
1358
|
+
const { headers: extraHeaders, ...restOptions } = options ?? {};
|
|
1359
|
+
return fetcher.request(
|
|
1360
|
+
`/api/storefront/v1/order/${encodeURIComponent(orderId)}/downloads`,
|
|
1361
|
+
{
|
|
1362
|
+
...restOptions,
|
|
1363
|
+
params: auth?.token ? { token: auth.token } : void 0,
|
|
1364
|
+
headers: {
|
|
1365
|
+
...buildDownloadAuthHeaders(auth),
|
|
1366
|
+
...extraHeaders ?? {}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
);
|
|
1370
|
+
},
|
|
1371
|
+
/**
|
|
1372
|
+
* Issue a short-lived presigned URL to download a specific file from a
|
|
1373
|
+
* paid order. Increments the download counter and records a download
|
|
1374
|
+
* event (IP, user agent) on the server.
|
|
1375
|
+
*
|
|
1376
|
+
* The returned URL is typically valid for ~5 minutes — redirect the
|
|
1377
|
+
* browser to it or trigger a download immediately.
|
|
1378
|
+
*
|
|
1379
|
+
* @param orderId - The order ID
|
|
1380
|
+
* @param downloadId - The OrderDownload.id
|
|
1381
|
+
* @param auth - Token (guest) or sessionId (logged-in customer)
|
|
1382
|
+
* @param options - Fetch options
|
|
1335
1383
|
*
|
|
1336
|
-
* @example
|
|
1384
|
+
* @example
|
|
1337
1385
|
* ```typescript
|
|
1338
|
-
* const
|
|
1339
|
-
*
|
|
1340
|
-
* console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);
|
|
1341
|
-
* order.orderShipmentMethod.trackingUrls?.forEach(url => {
|
|
1342
|
-
* console.log(`Track at: ${url}`);
|
|
1343
|
-
* });
|
|
1344
|
-
* }
|
|
1386
|
+
* const { url } = await client.order.getDownloadUrl(orderId, downloadId, { token });
|
|
1387
|
+
* window.location.href = url;
|
|
1345
1388
|
* ```
|
|
1346
1389
|
*/
|
|
1347
|
-
async
|
|
1390
|
+
async getDownloadUrl(orderId, downloadId, auth, options) {
|
|
1391
|
+
const { headers: extraHeaders, ...restOptions } = options ?? {};
|
|
1348
1392
|
return fetcher.request(
|
|
1349
|
-
`/api/storefront/v1/order/${encodeURIComponent(
|
|
1393
|
+
`/api/storefront/v1/order/${encodeURIComponent(
|
|
1394
|
+
orderId
|
|
1395
|
+
)}/downloads/${encodeURIComponent(downloadId)}`,
|
|
1350
1396
|
{
|
|
1351
|
-
...
|
|
1397
|
+
...restOptions,
|
|
1398
|
+
method: "POST",
|
|
1399
|
+
params: auth?.token ? { token: auth.token } : void 0,
|
|
1400
|
+
headers: {
|
|
1401
|
+
...buildDownloadAuthHeaders(auth),
|
|
1402
|
+
...extraHeaders ?? {}
|
|
1403
|
+
}
|
|
1352
1404
|
}
|
|
1353
1405
|
);
|
|
1354
1406
|
}
|