@commercengine/storefront-sdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * JWT payload structure for storefront tokens
3
+ */
4
+ export interface JwtPayload {
5
+ token_type: string;
6
+ exp: number;
7
+ iat: number;
8
+ jti: string;
9
+ ulid: string;
10
+ email: string | null;
11
+ phone: string | null;
12
+ username: string;
13
+ first_name: string | null;
14
+ last_name: string | null;
15
+ store_id: string;
16
+ is_logged_in: boolean;
17
+ customer_id: string | null;
18
+ customer_group_id: string | null;
19
+ anonymous_id: string;
20
+ }
21
+ /**
22
+ * User information extracted from JWT token
23
+ */
24
+ export interface UserInfo {
25
+ id: string;
26
+ email: string | null;
27
+ phone: string | null;
28
+ username: string;
29
+ firstName: string | null;
30
+ lastName: string | null;
31
+ storeId: string;
32
+ isLoggedIn: boolean;
33
+ isAnonymous: boolean;
34
+ customerId: string | null;
35
+ customerGroupId: string | null;
36
+ anonymousId: string;
37
+ tokenExpiry: Date;
38
+ tokenIssuedAt: Date;
39
+ }
40
+ /**
41
+ * Decode and extract user information from a JWT token
42
+ *
43
+ * @param token - The JWT token to decode
44
+ * @returns User information or null if token is invalid
45
+ */
46
+ export declare function extractUserInfoFromToken(token: string): UserInfo | null;
47
+ /**
48
+ * Check if a JWT token is expired
49
+ *
50
+ * @param token - The JWT token to check
51
+ * @param bufferSeconds - Buffer time in seconds (default: 30)
52
+ * @returns True if token is expired or will expire within buffer time
53
+ */
54
+ export declare function isTokenExpired(token: string, bufferSeconds?: number): boolean;
55
+ /**
56
+ * Get the user ID from a JWT token
57
+ *
58
+ * @param token - The JWT token
59
+ * @returns User ID (ulid) or null if token is invalid
60
+ */
61
+ export declare function getUserIdFromToken(token: string): string | null;
62
+ /**
63
+ * Check if user is logged in based on JWT token
64
+ *
65
+ * @param token - The JWT token
66
+ * @returns True if user is logged in, false otherwise
67
+ */
68
+ export declare function isUserLoggedIn(token: string): boolean;
69
+ /**
70
+ * Check if user is anonymous based on JWT token
71
+ *
72
+ * @param token - The JWT token
73
+ * @returns True if user is anonymous, false otherwise
74
+ */
75
+ export declare function isUserAnonymous(token: string): boolean;
@@ -0,0 +1,84 @@
1
+ import { decodeJwt } from "jose";
2
+ /**
3
+ * Decode and extract user information from a JWT token
4
+ *
5
+ * @param token - The JWT token to decode
6
+ * @returns User information or null if token is invalid
7
+ */
8
+ export function extractUserInfoFromToken(token) {
9
+ try {
10
+ const payload = decodeJwt(token);
11
+ return {
12
+ id: payload.ulid,
13
+ email: payload.email,
14
+ phone: payload.phone,
15
+ username: payload.username,
16
+ firstName: payload.first_name,
17
+ lastName: payload.last_name,
18
+ storeId: payload.store_id,
19
+ isLoggedIn: payload.is_logged_in,
20
+ isAnonymous: !payload.is_logged_in,
21
+ customerId: payload.customer_id,
22
+ customerGroupId: payload.customer_group_id,
23
+ anonymousId: payload.anonymous_id,
24
+ tokenExpiry: new Date(payload.exp * 1000),
25
+ tokenIssuedAt: new Date(payload.iat * 1000),
26
+ };
27
+ }
28
+ catch (error) {
29
+ console.warn("Failed to decode JWT token:", error);
30
+ return null;
31
+ }
32
+ }
33
+ /**
34
+ * Check if a JWT token is expired
35
+ *
36
+ * @param token - The JWT token to check
37
+ * @param bufferSeconds - Buffer time in seconds (default: 30)
38
+ * @returns True if token is expired or will expire within buffer time
39
+ */
40
+ export function isTokenExpired(token, bufferSeconds = 30) {
41
+ try {
42
+ const payload = decodeJwt(token);
43
+ if (!payload.exp)
44
+ return true;
45
+ const currentTime = Math.floor(Date.now() / 1000);
46
+ const expiryTime = payload.exp;
47
+ // Consider token expired if it expires within the buffer time
48
+ return currentTime >= (expiryTime - bufferSeconds);
49
+ }
50
+ catch (error) {
51
+ console.warn("Failed to decode JWT token:", error);
52
+ return true; // Treat invalid tokens as expired
53
+ }
54
+ }
55
+ /**
56
+ * Get the user ID from a JWT token
57
+ *
58
+ * @param token - The JWT token
59
+ * @returns User ID (ulid) or null if token is invalid
60
+ */
61
+ export function getUserIdFromToken(token) {
62
+ const userInfo = extractUserInfoFromToken(token);
63
+ return userInfo?.id || null;
64
+ }
65
+ /**
66
+ * Check if user is logged in based on JWT token
67
+ *
68
+ * @param token - The JWT token
69
+ * @returns True if user is logged in, false otherwise
70
+ */
71
+ export function isUserLoggedIn(token) {
72
+ const userInfo = extractUserInfoFromToken(token);
73
+ return userInfo?.isLoggedIn || false;
74
+ }
75
+ /**
76
+ * Check if user is anonymous based on JWT token
77
+ *
78
+ * @param token - The JWT token
79
+ * @returns True if user is anonymous, false otherwise
80
+ */
81
+ export function isUserAnonymous(token) {
82
+ const userInfo = extractUserInfoFromToken(token);
83
+ return userInfo?.isAnonymous || true;
84
+ }
@@ -0,0 +1,83 @@
1
+ import type { Middleware } from "openapi-fetch";
2
+ /**
3
+ * Token storage interface for the auth middleware
4
+ */
5
+ export interface TokenStorage {
6
+ getAccessToken(): Promise<string | null>;
7
+ setAccessToken(token: string): Promise<void>;
8
+ getRefreshToken(): Promise<string | null>;
9
+ setRefreshToken(token: string): Promise<void>;
10
+ clearTokens(): Promise<void>;
11
+ }
12
+ /**
13
+ * Simple in-memory token storage implementation
14
+ */
15
+ export declare class MemoryTokenStorage implements TokenStorage {
16
+ private accessToken;
17
+ private refreshToken;
18
+ getAccessToken(): Promise<string | null>;
19
+ setAccessToken(token: string): Promise<void>;
20
+ getRefreshToken(): Promise<string | null>;
21
+ setRefreshToken(token: string): Promise<void>;
22
+ clearTokens(): Promise<void>;
23
+ }
24
+ /**
25
+ * Browser localStorage token storage implementation
26
+ */
27
+ export declare class BrowserTokenStorage implements TokenStorage {
28
+ private accessTokenKey;
29
+ private refreshTokenKey;
30
+ constructor(prefix?: string);
31
+ getAccessToken(): Promise<string | null>;
32
+ setAccessToken(token: string): Promise<void>;
33
+ getRefreshToken(): Promise<string | null>;
34
+ setRefreshToken(token: string): Promise<void>;
35
+ clearTokens(): Promise<void>;
36
+ }
37
+ /**
38
+ * Configuration for the auth middleware
39
+ */
40
+ export interface AuthMiddlewareConfig {
41
+ /**
42
+ * Token storage implementation
43
+ */
44
+ tokenStorage: TokenStorage;
45
+ /**
46
+ * API key for anonymous endpoints
47
+ */
48
+ apiKey?: string;
49
+ /**
50
+ * Base URL for the API (used for refresh token endpoint)
51
+ */
52
+ baseUrl: string;
53
+ /**
54
+ * Function to refresh tokens
55
+ * Should make a call to /auth/refresh-token endpoint
56
+ */
57
+ refreshTokenFn?: (refreshToken: string) => Promise<{
58
+ access_token: string;
59
+ refresh_token: string;
60
+ }>;
61
+ /**
62
+ * Callback when tokens are updated (login/refresh)
63
+ */
64
+ onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
65
+ /**
66
+ * Callback when tokens are cleared (logout/error)
67
+ */
68
+ onTokensCleared?: () => void;
69
+ }
70
+ /**
71
+ * Create authentication middleware for openapi-fetch
72
+ */
73
+ export declare function createAuthMiddleware(config: AuthMiddlewareConfig): Middleware;
74
+ /**
75
+ * Helper function to create auth middleware with sensible defaults
76
+ */
77
+ export declare function createDefaultAuthMiddleware(options: {
78
+ apiKey?: string;
79
+ baseUrl: string;
80
+ tokenStorage?: TokenStorage;
81
+ onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
82
+ onTokensCleared?: () => void;
83
+ }): Middleware;
@@ -0,0 +1,257 @@
1
+ import { isTokenExpired } from "./jwt-utils";
2
+ /**
3
+ * Simple in-memory token storage implementation
4
+ */
5
+ export class MemoryTokenStorage {
6
+ accessToken = null;
7
+ refreshToken = null;
8
+ async getAccessToken() {
9
+ return this.accessToken;
10
+ }
11
+ async setAccessToken(token) {
12
+ this.accessToken = token;
13
+ }
14
+ async getRefreshToken() {
15
+ return this.refreshToken;
16
+ }
17
+ async setRefreshToken(token) {
18
+ this.refreshToken = token;
19
+ }
20
+ async clearTokens() {
21
+ this.accessToken = null;
22
+ this.refreshToken = null;
23
+ }
24
+ }
25
+ /**
26
+ * Browser localStorage token storage implementation
27
+ */
28
+ export class BrowserTokenStorage {
29
+ accessTokenKey;
30
+ refreshTokenKey;
31
+ constructor(prefix = "storefront_") {
32
+ this.accessTokenKey = `${prefix}access_token`;
33
+ this.refreshTokenKey = `${prefix}refresh_token`;
34
+ }
35
+ async getAccessToken() {
36
+ if (typeof localStorage === "undefined")
37
+ return null;
38
+ return localStorage.getItem(this.accessTokenKey);
39
+ }
40
+ async setAccessToken(token) {
41
+ if (typeof localStorage !== "undefined") {
42
+ localStorage.setItem(this.accessTokenKey, token);
43
+ }
44
+ }
45
+ async getRefreshToken() {
46
+ if (typeof localStorage === "undefined")
47
+ return null;
48
+ return localStorage.getItem(this.refreshTokenKey);
49
+ }
50
+ async setRefreshToken(token) {
51
+ if (typeof localStorage !== "undefined") {
52
+ localStorage.setItem(this.refreshTokenKey, token);
53
+ }
54
+ }
55
+ async clearTokens() {
56
+ if (typeof localStorage !== "undefined") {
57
+ localStorage.removeItem(this.accessTokenKey);
58
+ localStorage.removeItem(this.refreshTokenKey);
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * Check if a URL path is an auth endpoint that should use API key
64
+ */
65
+ function isAnonymousAuthEndpoint(pathname) {
66
+ return pathname.endsWith("/auth/anonymous");
67
+ }
68
+ /**
69
+ * Check if a URL path is a login/register endpoint that returns tokens
70
+ */
71
+ function isTokenReturningEndpoint(pathname) {
72
+ const tokenEndpoints = [
73
+ "/auth/login/password",
74
+ "/auth/register/phone",
75
+ "/auth/register/email",
76
+ "/auth/verify-otp",
77
+ "/auth/refresh-token"
78
+ ];
79
+ return tokenEndpoints.some(endpoint => pathname.endsWith(endpoint));
80
+ }
81
+ /**
82
+ * Check if a URL path is the logout endpoint
83
+ */
84
+ function isLogoutEndpoint(pathname) {
85
+ return pathname.endsWith("/auth/logout");
86
+ }
87
+ /**
88
+ * Extract pathname from URL
89
+ */
90
+ function getPathnameFromUrl(url) {
91
+ try {
92
+ const urlObj = new URL(url);
93
+ return urlObj.pathname;
94
+ }
95
+ catch {
96
+ // If URL parsing fails, assume it's a relative path
97
+ return url.split('?')[0];
98
+ }
99
+ }
100
+ /**
101
+ * Create authentication middleware for openapi-fetch
102
+ */
103
+ export function createAuthMiddleware(config) {
104
+ let isRefreshing = false;
105
+ let refreshPromise = null;
106
+ const refreshTokens = async () => {
107
+ if (isRefreshing && refreshPromise) {
108
+ return refreshPromise;
109
+ }
110
+ isRefreshing = true;
111
+ refreshPromise = (async () => {
112
+ try {
113
+ const refreshToken = await config.tokenStorage.getRefreshToken();
114
+ if (!refreshToken) {
115
+ throw new Error("No refresh token available");
116
+ }
117
+ let newTokens;
118
+ if (config.refreshTokenFn) {
119
+ // Use provided refresh function
120
+ newTokens = await config.refreshTokenFn(refreshToken);
121
+ }
122
+ else {
123
+ // Default refresh implementation
124
+ const response = await fetch(`${config.baseUrl}/auth/refresh-token`, {
125
+ method: "POST",
126
+ headers: {
127
+ "Content-Type": "application/json",
128
+ },
129
+ body: JSON.stringify({ refresh_token: refreshToken }),
130
+ });
131
+ if (!response.ok) {
132
+ throw new Error(`Token refresh failed: ${response.status}`);
133
+ }
134
+ const data = await response.json();
135
+ newTokens = data.content;
136
+ }
137
+ // Store new tokens
138
+ await config.tokenStorage.setAccessToken(newTokens.access_token);
139
+ await config.tokenStorage.setRefreshToken(newTokens.refresh_token);
140
+ // Notify callback
141
+ config.onTokensUpdated?.(newTokens.access_token, newTokens.refresh_token);
142
+ }
143
+ catch (error) {
144
+ console.error("Token refresh failed:", error);
145
+ // Clear tokens on refresh failure
146
+ await config.tokenStorage.clearTokens();
147
+ config.onTokensCleared?.();
148
+ throw error;
149
+ }
150
+ finally {
151
+ isRefreshing = false;
152
+ refreshPromise = null;
153
+ }
154
+ })();
155
+ return refreshPromise;
156
+ };
157
+ return {
158
+ async onRequest({ request }) {
159
+ const pathname = getPathnameFromUrl(request.url);
160
+ // Handle anonymous auth endpoint - use API key
161
+ if (isAnonymousAuthEndpoint(pathname)) {
162
+ if (config.apiKey) {
163
+ request.headers.set("X-Api-Key", config.apiKey);
164
+ }
165
+ // Also send existing access token if available (even if expired)
166
+ // This helps the server maintain anonymous user continuity
167
+ const existingToken = await config.tokenStorage.getAccessToken();
168
+ if (existingToken) {
169
+ request.headers.set("Authorization", `Bearer ${existingToken}`);
170
+ }
171
+ return request;
172
+ }
173
+ // For all other endpoints, use access token
174
+ let accessToken = await config.tokenStorage.getAccessToken();
175
+ // Check if token needs refresh
176
+ if (accessToken && isTokenExpired(accessToken)) {
177
+ try {
178
+ await refreshTokens();
179
+ accessToken = await config.tokenStorage.getAccessToken();
180
+ }
181
+ catch (error) {
182
+ // If refresh fails, continue with expired token
183
+ // The server will return 401 and we'll handle it in onResponse
184
+ }
185
+ }
186
+ // Add Authorization header if we have a token
187
+ if (accessToken) {
188
+ request.headers.set("Authorization", `Bearer ${accessToken}`);
189
+ }
190
+ return request;
191
+ },
192
+ async onResponse({ request, response }) {
193
+ const pathname = getPathnameFromUrl(request.url);
194
+ // Handle successful responses that return tokens
195
+ if (response.ok) {
196
+ if (isTokenReturningEndpoint(pathname) || isAnonymousAuthEndpoint(pathname)) {
197
+ try {
198
+ const data = await response.clone().json();
199
+ const content = data.content;
200
+ if (content?.access_token && content?.refresh_token) {
201
+ await config.tokenStorage.setAccessToken(content.access_token);
202
+ await config.tokenStorage.setRefreshToken(content.refresh_token);
203
+ config.onTokensUpdated?.(content.access_token, content.refresh_token);
204
+ }
205
+ }
206
+ catch (error) {
207
+ console.warn("Failed to extract tokens from response:", error);
208
+ }
209
+ }
210
+ else if (isLogoutEndpoint(pathname)) {
211
+ // Clear tokens on successful logout
212
+ await config.tokenStorage.clearTokens();
213
+ config.onTokensCleared?.();
214
+ }
215
+ }
216
+ // Handle 401 responses - only retry if token was expired
217
+ if (response.status === 401 && !isAnonymousAuthEndpoint(pathname)) {
218
+ const currentToken = await config.tokenStorage.getAccessToken();
219
+ // Only attempt refresh if we have a token and it's expired
220
+ // This prevents infinite retries for privilege-related 401s
221
+ if (currentToken && isTokenExpired(currentToken, 0)) {
222
+ try {
223
+ await refreshTokens();
224
+ // Retry the original request with new token
225
+ const newToken = await config.tokenStorage.getAccessToken();
226
+ if (newToken) {
227
+ const retryRequest = request.clone();
228
+ retryRequest.headers.set("Authorization", `Bearer ${newToken}`);
229
+ return fetch(retryRequest);
230
+ }
231
+ }
232
+ catch (error) {
233
+ // If refresh fails, let the original 401 response through
234
+ console.warn("Token refresh failed on 401 response:", error);
235
+ }
236
+ }
237
+ }
238
+ return response;
239
+ },
240
+ };
241
+ }
242
+ /**
243
+ * Helper function to create auth middleware with sensible defaults
244
+ */
245
+ export function createDefaultAuthMiddleware(options) {
246
+ const tokenStorage = options.tokenStorage ||
247
+ (typeof localStorage !== "undefined"
248
+ ? new BrowserTokenStorage()
249
+ : new MemoryTokenStorage());
250
+ return createAuthMiddleware({
251
+ tokenStorage,
252
+ apiKey: options.apiKey,
253
+ baseUrl: options.baseUrl,
254
+ onTokensUpdated: options.onTokensUpdated,
255
+ onTokensCleared: options.onTokensCleared,
256
+ });
257
+ }
@@ -0,0 +1,73 @@
1
+ import { ApiResult, CancelOrderBody, CancelOrderContent, CancelOrderPathParams, CreateOrderBody, CreateOrderContent, GetOrderDetailContent, GetOrderDetailPathParams, GetPaymentStatusContent, ListOrderPaymentsContent, ListOrderPaymentsPathParams, ListOrderRefundsContent, ListOrderRefundsPathParams, ListOrdersContent, ListOrderShipmentsContent, ListOrderShipmentsPathParams, ListOrdersQuery, RetryOrderPaymentBody, RetryOrderPaymentContent, RetryOrderPaymentPathParams } from "../types/storefront-api-types";
2
+ import { StorefrontAPIClient, StorefrontAPIConfig } from "./client";
3
+ /**
4
+ * Client for interacting with order endpoints
5
+ */
6
+ export declare class OrderClient extends StorefrontAPIClient {
7
+ constructor(config: StorefrontAPIConfig);
8
+ /**
9
+ * Get order details
10
+ *
11
+ * @param orderNumber - Order number
12
+ * @returns Promise with order details
13
+ */
14
+ getOrderDetails(pathParams: GetOrderDetailPathParams): Promise<ApiResult<GetOrderDetailContent>>;
15
+ /**
16
+ * Create order
17
+ *
18
+ * @param cartId - Cart ID
19
+ * @param paymentGateway - Payment gateway
20
+ * @param paymentGatewayParams - Params for the selected payment gateway
21
+ * @returns Promise with order details
22
+ */
23
+ createOrder(body: CreateOrderBody): Promise<ApiResult<CreateOrderContent>>;
24
+ /**
25
+ * List all orders
26
+ *
27
+ * @param queryParams - Query parameters
28
+ * @returns Promise with order details
29
+ */
30
+ listOrders(queryParams: ListOrdersQuery): Promise<ApiResult<ListOrdersContent>>;
31
+ /**
32
+ * Get payment status for an order
33
+ *
34
+ * @param orderNumber - Order number
35
+ * @returns Promise with payment status
36
+ */
37
+ getPaymentStatus(orderNumber: string): Promise<ApiResult<GetPaymentStatusContent>>;
38
+ /**
39
+ * Get all shipments for an order
40
+ *
41
+ * @param orderNumber - Order number
42
+ * @returns Promise with shipments
43
+ */
44
+ listOrderShipments(pathParams: ListOrderShipmentsPathParams): Promise<ApiResult<ListOrderShipmentsContent>>;
45
+ /**
46
+ * List order payments
47
+ *
48
+ * @param orderNumber - Order number
49
+ * @returns Promise with payments
50
+ */
51
+ listOrderPayments(pathParams: ListOrderPaymentsPathParams): Promise<ApiResult<ListOrderPaymentsContent>>;
52
+ /**
53
+ * List order refunds
54
+ *
55
+ * @param orderNumber - Order number
56
+ * @returns Promise with refunds
57
+ */
58
+ listOrderRefunds(pathParams: ListOrderRefundsPathParams): Promise<ApiResult<ListOrderRefundsContent>>;
59
+ /**
60
+ * Cancel an order
61
+ *
62
+ * @param orderNumber - Order number
63
+ * @returns Promise with order details
64
+ */
65
+ cancelOrder(pathParams: CancelOrderPathParams, body: CancelOrderBody): Promise<ApiResult<CancelOrderContent>>;
66
+ /**
67
+ * Retry payment for an order
68
+ *
69
+ * @param orderNumber - Order number
70
+ * @returns Promise with order details
71
+ */
72
+ retryOrderPayment(pathParams: RetryOrderPaymentPathParams, body: RetryOrderPaymentBody): Promise<ApiResult<RetryOrderPaymentContent>>;
73
+ }
@@ -0,0 +1,128 @@
1
+ import { StorefrontAPIClient } from "./client";
2
+ /**
3
+ * Client for interacting with order endpoints
4
+ */
5
+ export class OrderClient extends StorefrontAPIClient {
6
+ constructor(config) {
7
+ super(config);
8
+ }
9
+ /**
10
+ * Get order details
11
+ *
12
+ * @param orderNumber - Order number
13
+ * @returns Promise with order details
14
+ */
15
+ async getOrderDetails(pathParams) {
16
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}", {
17
+ params: {
18
+ path: pathParams,
19
+ },
20
+ }));
21
+ }
22
+ /**
23
+ * Create order
24
+ *
25
+ * @param cartId - Cart ID
26
+ * @param paymentGateway - Payment gateway
27
+ * @param paymentGatewayParams - Params for the selected payment gateway
28
+ * @returns Promise with order details
29
+ */
30
+ async createOrder(body) {
31
+ return this.executeRequest(() => this.client.POST("/orders", {
32
+ body: body,
33
+ }));
34
+ }
35
+ /**
36
+ * List all orders
37
+ *
38
+ * @param queryParams - Query parameters
39
+ * @returns Promise with order details
40
+ */
41
+ async listOrders(queryParams) {
42
+ return this.executeRequest(() => this.client.GET("/orders", {
43
+ params: {
44
+ query: queryParams,
45
+ },
46
+ }));
47
+ }
48
+ /**
49
+ * Get payment status for an order
50
+ *
51
+ * @param orderNumber - Order number
52
+ * @returns Promise with payment status
53
+ */
54
+ async getPaymentStatus(orderNumber) {
55
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/payment-status", {
56
+ params: {
57
+ path: { order_number: orderNumber },
58
+ },
59
+ }));
60
+ }
61
+ /**
62
+ * Get all shipments for an order
63
+ *
64
+ * @param orderNumber - Order number
65
+ * @returns Promise with shipments
66
+ */
67
+ async listOrderShipments(pathParams) {
68
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/shipments", {
69
+ params: {
70
+ path: pathParams,
71
+ },
72
+ }));
73
+ }
74
+ /**
75
+ * List order payments
76
+ *
77
+ * @param orderNumber - Order number
78
+ * @returns Promise with payments
79
+ */
80
+ async listOrderPayments(pathParams) {
81
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/payments", {
82
+ params: {
83
+ path: pathParams,
84
+ },
85
+ }));
86
+ }
87
+ /**
88
+ * List order refunds
89
+ *
90
+ * @param orderNumber - Order number
91
+ * @returns Promise with refunds
92
+ */
93
+ async listOrderRefunds(pathParams) {
94
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/refunds", {
95
+ params: {
96
+ path: pathParams,
97
+ },
98
+ }));
99
+ }
100
+ /**
101
+ * Cancel an order
102
+ *
103
+ * @param orderNumber - Order number
104
+ * @returns Promise with order details
105
+ */
106
+ async cancelOrder(pathParams, body) {
107
+ return this.executeRequest(() => this.client.POST("/orders/{order_number}/cancel", {
108
+ params: {
109
+ path: pathParams,
110
+ },
111
+ body: body,
112
+ }));
113
+ }
114
+ /**
115
+ * Retry payment for an order
116
+ *
117
+ * @param orderNumber - Order number
118
+ * @returns Promise with order details
119
+ */
120
+ async retryOrderPayment(pathParams, body) {
121
+ return this.executeRequest(() => this.client.POST("/orders/{order_number}/retry-payment", {
122
+ params: {
123
+ path: pathParams,
124
+ },
125
+ body: body,
126
+ }));
127
+ }
128
+ }