@returnflows/shop-overlay 1.0.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/README.md +976 -0
- package/dist/index.esm.css +3 -0
- package/dist/index.esm.js +12494 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/messages/da.json +1 -0
- package/dist/messages/de.json +1 -0
- package/dist/messages/en.json +1 -0
- package/dist/messages/es.json +1 -0
- package/dist/messages/fi.json +1 -0
- package/dist/messages/fr.json +1 -0
- package/dist/messages/it.json +1 -0
- package/dist/messages/nb.json +1 -0
- package/dist/messages/nl.json +1 -0
- package/dist/messages/pl.json +1 -0
- package/dist/messages/sv.json +1 -0
- package/dist/types/api/index.d.ts +6 -0
- package/dist/types/api/state-bridge.d.ts +37 -0
- package/dist/types/api/storefront-cart.d.ts +3 -0
- package/dist/types/api/types.d.ts +402 -0
- package/dist/types/api/widget-api.d.ts +20 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/widget/components/dialog/common/dialog-backdrop.d.ts +6 -0
- package/dist/types/widget/components/dialog/common/dialog-button.d.ts +6 -0
- package/dist/types/widget/components/dialog/common/dialog-modal.d.ts +9 -0
- package/dist/types/widget/components/dialog/common/dialog-subtitle.d.ts +2 -0
- package/dist/types/widget/components/dialog/common/dialog-title.d.ts +2 -0
- package/dist/types/widget/components/dialog/common/index.d.ts +10 -0
- package/dist/types/widget/components/dialog/return-decision-dialog.d.ts +2 -0
- package/dist/types/widget/components/drawer/adjustments/exchange-adjustments.d.ts +2 -0
- package/dist/types/widget/components/drawer/adjustments/exchange-banner.d.ts +2 -0
- package/dist/types/widget/components/drawer/adjustments/table/adjustments-table-skeleton.d.ts +2 -0
- package/dist/types/widget/components/drawer/adjustments/table/adjustments-table.d.ts +2 -0
- package/dist/types/widget/components/drawer/annoucement-bar.d.ts +2 -0
- package/dist/types/widget/components/drawer/error-screen.d.ts +6 -0
- package/dist/types/widget/components/drawer/exchange-confirmation.d.ts +2 -0
- package/dist/types/widget/components/drawer/exchange-drawer.d.ts +5 -0
- package/dist/types/widget/components/drawer/exchange-header.d.ts +2 -0
- package/dist/types/widget/components/drawer/exchange-placeholder.d.ts +2 -0
- package/dist/types/widget/components/drawer/product/product-actions.d.ts +8 -0
- package/dist/types/widget/components/drawer/product/product-attributes.d.ts +14 -0
- package/dist/types/widget/components/drawer/product/product-errors.d.ts +2 -0
- package/dist/types/widget/components/drawer/product/product-image.d.ts +7 -0
- package/dist/types/widget/components/drawer/product/product-list.d.ts +2 -0
- package/dist/types/widget/components/drawer/product/product.d.ts +9 -0
- package/dist/types/widget/components/drawer/product/quantity-picker.d.ts +20 -0
- package/dist/types/widget/components/drawer/return/return-product-actions.d.ts +10 -0
- package/dist/types/widget/components/drawer/return/return-product-badge.d.ts +7 -0
- package/dist/types/widget/components/drawer/return/return-product-list.d.ts +2 -0
- package/dist/types/widget/components/drawer/return/return-product-skeleton.d.ts +2 -0
- package/dist/types/widget/components/drawer/return/return-product.d.ts +14 -0
- package/dist/types/widget/components/drawer/scroll-indicator.d.ts +5 -0
- package/dist/types/widget/components/handlers/dialog-handler.d.ts +2 -0
- package/dist/types/widget/components/handlers/initialization-handler.d.ts +2 -0
- package/dist/types/widget/components/icons/arrow-down.d.ts +2 -0
- package/dist/types/widget/components/icons/arrow-left.d.ts +2 -0
- package/dist/types/widget/components/icons/arrow-right.d.ts +2 -0
- package/dist/types/widget/components/icons/bag.d.ts +2 -0
- package/dist/types/widget/components/icons/banner/action.d.ts +2 -0
- package/dist/types/widget/components/icons/banner/info.d.ts +2 -0
- package/dist/types/widget/components/icons/cart.d.ts +2 -0
- package/dist/types/widget/components/icons/chevron.d.ts +2 -0
- package/dist/types/widget/components/icons/giftcard.d.ts +2 -0
- package/dist/types/widget/components/icons/icon.d.ts +17 -0
- package/dist/types/widget/components/icons/spinner.d.ts +2 -0
- package/dist/types/widget/components/icons/star.d.ts +2 -0
- package/dist/types/widget/components/icons/warning.d.ts +2 -0
- package/dist/types/widget/components/icons/x.d.ts +2 -0
- package/dist/types/widget/components/is-mounted.d.ts +4 -0
- package/dist/types/widget/components/providers/error-provider.d.ts +4 -0
- package/dist/types/widget/components/providers/return-context-provider.d.ts +17 -0
- package/dist/types/widget/components/providers/root-provider.d.ts +2 -0
- package/dist/types/widget/components/providers/widget-context-provider.d.ts +6 -0
- package/dist/types/widget/components/return-avatar-stack.d.ts +2 -0
- package/dist/types/widget/components/summary/back-button.d.ts +2 -0
- package/dist/types/widget/components/summary/exchange-summary.d.ts +2 -0
- package/dist/types/widget/components/summary/exchange-total-skeleton.d.ts +2 -0
- package/dist/types/widget/components/summary/exchange-total.d.ts +2 -0
- package/dist/types/widget/components/toast/toast-container.d.ts +2 -0
- package/dist/types/widget/components/toast/toast-provider.d.ts +4 -0
- package/dist/types/widget/components/toast/toast.d.ts +16 -0
- package/dist/types/widget/components/ui/avatar/avatar-stack-skeleton.d.ts +2 -0
- package/dist/types/widget/components/ui/avatar/avatar-stack.d.ts +12 -0
- package/dist/types/widget/components/ui/avatar/avatar.d.ts +10 -0
- package/dist/types/widget/components/ui/banner/banner-skeleton.d.ts +2 -0
- package/dist/types/widget/components/ui/banner/banner.d.ts +13 -0
- package/dist/types/widget/components/ui/button.d.ts +11 -0
- package/dist/types/widget/components/ui/expander.d.ts +8 -0
- package/dist/types/widget/components/ui/image.d.ts +5 -0
- package/dist/types/widget/components/ui/link.d.ts +7 -0
- package/dist/types/widget/components/ui/price.d.ts +7 -0
- package/dist/types/widget/components/ui/skeleton/skeleton-container.d.ts +6 -0
- package/dist/types/widget/components/ui/skeleton/skeleton.d.ts +2 -0
- package/dist/types/widget/components/widget-container.d.ts +3 -0
- package/dist/types/widget/components/widget.d.ts +2 -0
- package/dist/types/widget/lib/constants.d.ts +13 -0
- package/dist/types/widget/lib/context/dialog-context.d.ts +3 -0
- package/dist/types/widget/lib/context/error-context.d.ts +10 -0
- package/dist/types/widget/lib/context/return-context.d.ts +12 -0
- package/dist/types/widget/lib/context/root-context.d.ts +2 -0
- package/dist/types/widget/lib/context/toast-context.d.ts +13 -0
- package/dist/types/widget/lib/context/widget-context.d.ts +9 -0
- package/dist/types/widget/lib/hooks/common/use-array.d.ts +14 -0
- package/dist/types/widget/lib/hooks/common/use-async-state.d.ts +40 -0
- package/dist/types/widget/lib/hooks/common/use-dialog.d.ts +11 -0
- package/dist/types/widget/lib/hooks/common/use-is-mounted.d.ts +2 -0
- package/dist/types/widget/lib/hooks/common/use-once.d.ts +3 -0
- package/dist/types/widget/lib/hooks/common/use-value-state.d.ts +7 -0
- package/dist/types/widget/lib/hooks/common/use-y-scrollable.d.ts +10 -0
- package/dist/types/widget/lib/hooks/context/use-calculation.d.ts +12 -0
- package/dist/types/widget/lib/hooks/context/use-cart-items.d.ts +9 -0
- package/dist/types/widget/lib/hooks/context/use-currency.d.ts +12 -0
- package/dist/types/widget/lib/hooks/context/use-errors.d.ts +2 -0
- package/dist/types/widget/lib/hooks/context/use-navigation.d.ts +6 -0
- package/dist/types/widget/lib/hooks/context/use-return-context.d.ts +2 -0
- package/dist/types/widget/lib/hooks/context/use-root.d.ts +2 -0
- package/dist/types/widget/lib/hooks/context/use-theme.d.ts +5 -0
- package/dist/types/widget/lib/hooks/context/use-toast.d.ts +2 -0
- package/dist/types/widget/lib/hooks/context/use-widget-context.d.ts +2 -0
- package/dist/types/widget/lib/hooks/feature/use-api-bridge.d.ts +6 -0
- package/dist/types/widget/lib/hooks/feature/use-cart-activator.d.ts +2 -0
- package/dist/types/widget/lib/hooks/feature/use-external-events.d.ts +2 -0
- package/dist/types/widget/lib/hooks/feature/use-fetch-interceptor.d.ts +4 -0
- package/dist/types/widget/lib/hooks/feature/use-override-scroll-blocking.d.ts +2 -0
- package/dist/types/widget/lib/types.d.ts +382 -0
- package/dist/types/widget/lib/utils/api.d.ts +26 -0
- package/dist/types/widget/lib/utils/cart-provider-store.d.ts +3 -0
- package/dist/types/widget/lib/utils/cart.d.ts +17 -0
- package/dist/types/widget/lib/utils/custom-events.d.ts +48 -0
- package/dist/types/widget/lib/utils/dom.d.ts +2 -0
- package/dist/types/widget/lib/utils/errors.d.ts +6 -0
- package/dist/types/widget/lib/utils/helpers.d.ts +24 -0
- package/dist/types/widget/lib/utils/i18n.d.ts +8 -0
- package/dist/types/widget/lib/utils/initialization/dataset.d.ts +5 -0
- package/dist/types/widget/lib/utils/initialization/font.d.ts +7 -0
- package/dist/types/widget/lib/utils/initialization/index.d.ts +6 -0
- package/dist/types/widget/lib/utils/initialization/styles.d.ts +4 -0
- package/dist/types/widget/lib/utils/initialization/types.d.ts +51 -0
- package/dist/types/widget/lib/utils/interceptor/fetch.d.ts +5 -0
- package/dist/types/widget/lib/utils/interceptor/index.d.ts +26 -0
- package/dist/types/widget/lib/utils/interceptor/xhr.d.ts +5 -0
- package/dist/types/widget/lib/utils/logger.d.ts +13 -0
- package/dist/types/widget/lib/utils/navigation.d.ts +7 -0
- package/dist/types/widget/lib/utils/session.d.ts +54 -0
- package/dist/types/widget/lib/utils/shopify.d.ts +6 -0
- package/dist/types/widget/lib/utils/storage.d.ts +33 -0
- package/dist/variables.css +1 -0
- package/dist/widget.css +3 -0
- package/dist/widget.js +12006 -0
- package/package.json +112 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Setter<T> = React.Dispatch<React.SetStateAction<T>>;
|
|
2
|
+
export interface ValueState<T> {
|
|
3
|
+
value: T;
|
|
4
|
+
set: Setter<T>;
|
|
5
|
+
}
|
|
6
|
+
declare const useValueState: <T>(initialState: T, stateUpdateCallback?: (newValue: T) => void) => Readonly<ValueState<T>>;
|
|
7
|
+
export default useValueState;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RefObject } from "preact";
|
|
2
|
+
interface UseYScrollableReturn extends ScrollState {
|
|
3
|
+
isYScrollable: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface ScrollState {
|
|
6
|
+
isDirty: boolean;
|
|
7
|
+
isScrolling: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const useYScrollable: <T extends HTMLElement>(ref: RefObject<T>) => UseYScrollableReturn;
|
|
10
|
+
export default useYScrollable;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const useCalculation: () => {
|
|
2
|
+
orderTotal: number;
|
|
3
|
+
cartTotal: number;
|
|
4
|
+
returnTotal: number;
|
|
5
|
+
giftcardValue: number;
|
|
6
|
+
totalPriceDiscount: number;
|
|
7
|
+
giftCardBonusAmount: number;
|
|
8
|
+
returnLabelPrice: number;
|
|
9
|
+
isRefunding: boolean;
|
|
10
|
+
itemCount: number;
|
|
11
|
+
};
|
|
12
|
+
export default useCalculation;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExtendedShopifyProduct } from "../../../components/drawer/product/product";
|
|
2
|
+
/**
|
|
3
|
+
* Merges cart items with their corresponding exchange calculation details.
|
|
4
|
+
* Returns cart items enriched with pricing information from the calculation state.
|
|
5
|
+
*/
|
|
6
|
+
declare const useCartItems: () => {
|
|
7
|
+
cartItems: ExtendedShopifyProduct[];
|
|
8
|
+
};
|
|
9
|
+
export default useCartItems;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NumberFormatOptions } from "use-intl";
|
|
2
|
+
type TCurrencyDisplayOptions = NumberFormatOptions["currencyDisplay"] | "none";
|
|
3
|
+
interface ICurrencyFormatOptions extends Omit<NumberFormatOptions, "style" | "currencyDisplay"> {
|
|
4
|
+
currencyDisplay?: TCurrencyDisplayOptions;
|
|
5
|
+
fractionDigits?: number;
|
|
6
|
+
}
|
|
7
|
+
declare const useCurrency: (hookOptions?: ICurrencyFormatOptions) => {
|
|
8
|
+
format: (value: number | string, options?: ICurrencyFormatOptions) => string;
|
|
9
|
+
applyExchangeRate: (value: number) => number;
|
|
10
|
+
currency: string;
|
|
11
|
+
};
|
|
12
|
+
export default useCurrency;
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
type GlobalShopify = {
|
|
2
|
+
shop: string;
|
|
3
|
+
locale: string;
|
|
4
|
+
currency: {
|
|
5
|
+
active: string;
|
|
6
|
+
rate: string;
|
|
7
|
+
};
|
|
8
|
+
country: string;
|
|
9
|
+
theme: {
|
|
10
|
+
name: string;
|
|
11
|
+
id: number;
|
|
12
|
+
schema_name: string;
|
|
13
|
+
schema_version: string;
|
|
14
|
+
theme_store_id?: number;
|
|
15
|
+
role: string;
|
|
16
|
+
handle: string;
|
|
17
|
+
style: {
|
|
18
|
+
id?: string | null;
|
|
19
|
+
handle?: string | null;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
cdnHost: string;
|
|
23
|
+
routes: {
|
|
24
|
+
root: string;
|
|
25
|
+
};
|
|
26
|
+
ce_forms: {
|
|
27
|
+
q: Array<unknown>;
|
|
28
|
+
};
|
|
29
|
+
captcha: unknown;
|
|
30
|
+
PaymentButton: {
|
|
31
|
+
isStorefrontPortableWallets: boolean;
|
|
32
|
+
};
|
|
33
|
+
analytics: {
|
|
34
|
+
replayQueue: Array<unknown>;
|
|
35
|
+
initialized: boolean;
|
|
36
|
+
};
|
|
37
|
+
modules: boolean;
|
|
38
|
+
featureAssets: {
|
|
39
|
+
"shop-js": unknown;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
type InterceptionProperties = {
|
|
43
|
+
rf_interception?: boolean;
|
|
44
|
+
};
|
|
45
|
+
declare global {
|
|
46
|
+
interface Window {
|
|
47
|
+
__rf_original_fetch?: typeof fetch;
|
|
48
|
+
fetch: typeof fetch & InterceptionProperties;
|
|
49
|
+
__rf_original_xhr?: typeof XMLHttpRequest;
|
|
50
|
+
XMLHttpRequest: typeof XMLHttpRequest & InterceptionProperties;
|
|
51
|
+
__rf_original_search?: string;
|
|
52
|
+
Shopify: GlobalShopify;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export type ReturnAction = "swap" | "exchange" | "giftcard" | "refund";
|
|
56
|
+
export type ProductRule = {
|
|
57
|
+
id: string;
|
|
58
|
+
type: "NO_RETURN" | "NO_REFUND" | "EXTEND_PERIOD" | "NO_EXCHANGE_TO";
|
|
59
|
+
extendedBy: number;
|
|
60
|
+
marketId: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
createdAt: string;
|
|
63
|
+
products: Array<{
|
|
64
|
+
title: string;
|
|
65
|
+
image: string;
|
|
66
|
+
id: string;
|
|
67
|
+
ruleId: string;
|
|
68
|
+
shopifyProductId: string;
|
|
69
|
+
createdAt: string;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
export interface ShopOverlayData {
|
|
73
|
+
id: string;
|
|
74
|
+
orderId: string;
|
|
75
|
+
orderName: string;
|
|
76
|
+
instantExchange: boolean;
|
|
77
|
+
freeExchangeLabel: boolean;
|
|
78
|
+
productsToExchange: Array<OrderProduct>;
|
|
79
|
+
totalPrice: number;
|
|
80
|
+
productRules: Array<ProductRule>;
|
|
81
|
+
returnWindows: {
|
|
82
|
+
exchangeReturnWindow: boolean;
|
|
83
|
+
refundReturnWindow: boolean;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export interface OrderProduct {
|
|
87
|
+
id: string;
|
|
88
|
+
shopifyLineId: string;
|
|
89
|
+
title: string;
|
|
90
|
+
variantTitle: string;
|
|
91
|
+
image: string;
|
|
92
|
+
handle: string;
|
|
93
|
+
price: number;
|
|
94
|
+
quantity: number;
|
|
95
|
+
}
|
|
96
|
+
export interface ShopifyCartAddResponse {
|
|
97
|
+
id: number;
|
|
98
|
+
properties: Record<string, unknown>;
|
|
99
|
+
quantity: number;
|
|
100
|
+
variant_id: number;
|
|
101
|
+
key: string;
|
|
102
|
+
title: string;
|
|
103
|
+
product_title: string;
|
|
104
|
+
variant_title: string;
|
|
105
|
+
price: number;
|
|
106
|
+
original_price: number;
|
|
107
|
+
discounted_price: number;
|
|
108
|
+
line_price: number;
|
|
109
|
+
original_line_price: number;
|
|
110
|
+
presentment_price: number;
|
|
111
|
+
total_discount: number;
|
|
112
|
+
discounts: Array<unknown>;
|
|
113
|
+
sku: string;
|
|
114
|
+
grams: number;
|
|
115
|
+
vendor: string;
|
|
116
|
+
taxable: boolean;
|
|
117
|
+
product_id: number;
|
|
118
|
+
product_has_only_default_variant: boolean;
|
|
119
|
+
gift_card: boolean;
|
|
120
|
+
final_price: number;
|
|
121
|
+
final_line_price: number;
|
|
122
|
+
url: string;
|
|
123
|
+
featured_image: {
|
|
124
|
+
alt: string;
|
|
125
|
+
aspect_ratio: number;
|
|
126
|
+
height: number;
|
|
127
|
+
url: string;
|
|
128
|
+
width: number;
|
|
129
|
+
};
|
|
130
|
+
image: string;
|
|
131
|
+
handle: string;
|
|
132
|
+
requires_shipping: boolean;
|
|
133
|
+
product_type: string;
|
|
134
|
+
untranslated_product_title: string;
|
|
135
|
+
product_description: string;
|
|
136
|
+
untranslated_variant_title: string;
|
|
137
|
+
variant_options: Array<string>;
|
|
138
|
+
options_with_values: Array<{
|
|
139
|
+
name: string;
|
|
140
|
+
value: string;
|
|
141
|
+
}>;
|
|
142
|
+
line_level_discount_allocations: Array<unknown>;
|
|
143
|
+
line_level_total_discount: number;
|
|
144
|
+
sections: {
|
|
145
|
+
"cart-notification-product": string;
|
|
146
|
+
"cart-notification-button": string;
|
|
147
|
+
"cart-icon-bubble": string;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export interface ShopifyCart {
|
|
151
|
+
items: Array<ShopifyCartItem>;
|
|
152
|
+
item_count: number;
|
|
153
|
+
token?: string;
|
|
154
|
+
note?: string;
|
|
155
|
+
attributes?: Record<string, unknown>;
|
|
156
|
+
original_total_price?: number;
|
|
157
|
+
total_price?: number;
|
|
158
|
+
total_discount?: number;
|
|
159
|
+
total_weight?: number;
|
|
160
|
+
requires_shipping?: boolean;
|
|
161
|
+
currency?: string;
|
|
162
|
+
items_subtotal_price?: number;
|
|
163
|
+
cart_level_discount_applications?: Array<unknown>;
|
|
164
|
+
discount_codes?: Array<unknown>;
|
|
165
|
+
}
|
|
166
|
+
export interface ShopifyCartChangeResponse extends ShopifyCart {
|
|
167
|
+
items_added: Array<ShopifyCartItem>;
|
|
168
|
+
items_removed: Array<ShopifyCartItem>;
|
|
169
|
+
}
|
|
170
|
+
export interface ShopifyCartItem {
|
|
171
|
+
variant_id: number;
|
|
172
|
+
quantity: number;
|
|
173
|
+
title: string;
|
|
174
|
+
price: number;
|
|
175
|
+
product_id: number;
|
|
176
|
+
product_title: string;
|
|
177
|
+
handle: string;
|
|
178
|
+
image: string;
|
|
179
|
+
grams: number;
|
|
180
|
+
line_price: number;
|
|
181
|
+
final_price: number;
|
|
182
|
+
final_line_price: number;
|
|
183
|
+
id?: number;
|
|
184
|
+
line_id?: string;
|
|
185
|
+
merchandise_id?: string;
|
|
186
|
+
properties?: Record<string, unknown>;
|
|
187
|
+
key?: string;
|
|
188
|
+
variant_title?: string;
|
|
189
|
+
quantity_rule?: {
|
|
190
|
+
min: number | null;
|
|
191
|
+
max: number | null;
|
|
192
|
+
increment: number | null;
|
|
193
|
+
};
|
|
194
|
+
original_price?: number;
|
|
195
|
+
presentment_price?: number;
|
|
196
|
+
discounted_price?: number;
|
|
197
|
+
original_line_price?: number;
|
|
198
|
+
total_discount?: number;
|
|
199
|
+
discounts?: Array<unknown>;
|
|
200
|
+
sku?: string;
|
|
201
|
+
vendor?: string;
|
|
202
|
+
taxable?: boolean;
|
|
203
|
+
product_has_only_default_variant?: boolean;
|
|
204
|
+
gift_card?: boolean;
|
|
205
|
+
url?: string;
|
|
206
|
+
featured_image?: {
|
|
207
|
+
aspect_ratio: number;
|
|
208
|
+
alt: string;
|
|
209
|
+
height: number;
|
|
210
|
+
url: string;
|
|
211
|
+
width: number;
|
|
212
|
+
};
|
|
213
|
+
requires_shipping?: boolean;
|
|
214
|
+
product_type?: string;
|
|
215
|
+
product_description?: string;
|
|
216
|
+
variant_options?: Array<string>;
|
|
217
|
+
options_with_values?: Array<{
|
|
218
|
+
name: string;
|
|
219
|
+
value: string;
|
|
220
|
+
}>;
|
|
221
|
+
line_level_discount_allocations?: Array<unknown>;
|
|
222
|
+
line_level_total_discount?: number;
|
|
223
|
+
has_components?: boolean;
|
|
224
|
+
}
|
|
225
|
+
export interface ShopifyErrorResponse {
|
|
226
|
+
status: string;
|
|
227
|
+
message: string;
|
|
228
|
+
description: string;
|
|
229
|
+
}
|
|
230
|
+
export interface CalculationExchangeProduct {
|
|
231
|
+
variantId: string | undefined;
|
|
232
|
+
productId: string;
|
|
233
|
+
productTitle: string;
|
|
234
|
+
price: number;
|
|
235
|
+
compareAtPrice: number | null;
|
|
236
|
+
coverage: {
|
|
237
|
+
originalProductId: string;
|
|
238
|
+
originalVariantId: string;
|
|
239
|
+
quantityCovered: number;
|
|
240
|
+
originalUnitPrice: number;
|
|
241
|
+
exchangeUnitPrice: number;
|
|
242
|
+
coveredAmount: number;
|
|
243
|
+
} | null;
|
|
244
|
+
}
|
|
245
|
+
export interface CalculationLineItem {
|
|
246
|
+
id: string;
|
|
247
|
+
lineItemId: string;
|
|
248
|
+
variantId: string;
|
|
249
|
+
productId: string;
|
|
250
|
+
quantity: number;
|
|
251
|
+
lineItemDistributionKey: number;
|
|
252
|
+
action: "NOT_DECIDED" | "REFUND" | "EXCHANGE" | "SWAP" | "GIFTCARD";
|
|
253
|
+
originalPrice: number;
|
|
254
|
+
price: number;
|
|
255
|
+
discountedPrice: number;
|
|
256
|
+
originalTotal: number;
|
|
257
|
+
total: number;
|
|
258
|
+
discountedTotal: number;
|
|
259
|
+
metafield: {
|
|
260
|
+
namespace: unknown;
|
|
261
|
+
key: unknown;
|
|
262
|
+
value: unknown;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export interface CalculationResponse {
|
|
266
|
+
percentageOfReturn: number;
|
|
267
|
+
returnLabelPrice: number;
|
|
268
|
+
giftCardBonusAmount: number;
|
|
269
|
+
refundMethods: {
|
|
270
|
+
refund: number;
|
|
271
|
+
giftcard: number;
|
|
272
|
+
exchange: number;
|
|
273
|
+
};
|
|
274
|
+
distributionKeysByAction: {
|
|
275
|
+
REFUND: number;
|
|
276
|
+
EXCHANGE: number;
|
|
277
|
+
GIFTCARD: number;
|
|
278
|
+
};
|
|
279
|
+
shipping: {
|
|
280
|
+
amount: number;
|
|
281
|
+
amountInCurrency: number;
|
|
282
|
+
originalOrderShipping: number;
|
|
283
|
+
};
|
|
284
|
+
orderDiscounts: Array<unknown>;
|
|
285
|
+
discountSummary: {
|
|
286
|
+
originalDiscountTotal: number;
|
|
287
|
+
adjustedDiscountTotal: number;
|
|
288
|
+
appliedToReturnSubtotal: number;
|
|
289
|
+
hasDiscounts: boolean;
|
|
290
|
+
hasAdjustedDiscounts: boolean;
|
|
291
|
+
discountAppliedToExchange: boolean;
|
|
292
|
+
discountAddedToReturnSubtotal: boolean;
|
|
293
|
+
shippingRefundAppliedToReturnSubtotal: boolean;
|
|
294
|
+
};
|
|
295
|
+
lineItems: Array<CalculationLineItem>;
|
|
296
|
+
exchange: {
|
|
297
|
+
originalTotal: number;
|
|
298
|
+
newTotal: number;
|
|
299
|
+
priceDifference: number;
|
|
300
|
+
isUpsell: boolean;
|
|
301
|
+
additionalCharge: number;
|
|
302
|
+
totalCoveredAmount: number;
|
|
303
|
+
discountSummary: {
|
|
304
|
+
originalDiscountTotal: number;
|
|
305
|
+
adjustedDiscountTotal: number;
|
|
306
|
+
appliedToReturnSubtotal: number;
|
|
307
|
+
hasDiscounts: boolean;
|
|
308
|
+
hasAdjustedDiscounts: boolean;
|
|
309
|
+
discountAppliedToExchange: boolean;
|
|
310
|
+
discountAddedToReturnSubtotal: boolean;
|
|
311
|
+
shippingRefundAppliedToReturnSubtotal: boolean;
|
|
312
|
+
};
|
|
313
|
+
exchangeDetails: Array<CalculationExchangeProduct>;
|
|
314
|
+
};
|
|
315
|
+
currency: {
|
|
316
|
+
localCurrency: string;
|
|
317
|
+
shopCurrency: string;
|
|
318
|
+
exchangeRate: number;
|
|
319
|
+
};
|
|
320
|
+
options: {
|
|
321
|
+
coverPriceChange: boolean;
|
|
322
|
+
orderDiscountMatch: boolean;
|
|
323
|
+
productDiscountMatch: boolean;
|
|
324
|
+
giftCardBonusPercentage: number;
|
|
325
|
+
refundOriginalShippingType: string;
|
|
326
|
+
};
|
|
327
|
+
returnSubtotal: number;
|
|
328
|
+
orderSubtotal: number;
|
|
329
|
+
preferedLabelDeduction: string;
|
|
330
|
+
total: number;
|
|
331
|
+
calculatedAt: string;
|
|
332
|
+
detailedBreakdown: {
|
|
333
|
+
originalOrder: {
|
|
334
|
+
subtotal: number;
|
|
335
|
+
shipping: number;
|
|
336
|
+
discounts: Array<unknown>;
|
|
337
|
+
total: number;
|
|
338
|
+
};
|
|
339
|
+
return: {
|
|
340
|
+
subtotal: {
|
|
341
|
+
items: number;
|
|
342
|
+
returnLabelPrice: number;
|
|
343
|
+
shippingRefund: number;
|
|
344
|
+
discounts: Array<unknown>;
|
|
345
|
+
total: number;
|
|
346
|
+
};
|
|
347
|
+
refundMethods: {
|
|
348
|
+
refund: {
|
|
349
|
+
amount: number;
|
|
350
|
+
description: string;
|
|
351
|
+
};
|
|
352
|
+
giftcard: {
|
|
353
|
+
baseAmount: number;
|
|
354
|
+
bonusAmount: number;
|
|
355
|
+
bonusPercentage: number;
|
|
356
|
+
totalAmount: number;
|
|
357
|
+
};
|
|
358
|
+
exchange: {
|
|
359
|
+
amount: number;
|
|
360
|
+
priceDifference: number;
|
|
361
|
+
finalAmount: number;
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
total: number;
|
|
365
|
+
};
|
|
366
|
+
preferedLabelDeduction: string;
|
|
367
|
+
currency: {
|
|
368
|
+
localCurrency: string;
|
|
369
|
+
shopCurrency: string;
|
|
370
|
+
exchangeRate: number;
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
export declare enum WidgetViewState {
|
|
375
|
+
Collapsed = "COLLAPSED",
|
|
376
|
+
Open = "OPEN"
|
|
377
|
+
}
|
|
378
|
+
export declare enum ReturnViewState {
|
|
379
|
+
Collapsed = "COLLAPSED",
|
|
380
|
+
Open = "OPEN"
|
|
381
|
+
}
|
|
382
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CalculationParams } from "../../components/providers/return-context-provider";
|
|
2
|
+
import { CalculationResponse, ShopifyCart, ShopOverlayData } from "../types";
|
|
3
|
+
import { WidgetConfiguration } from "./initialization/types";
|
|
4
|
+
import { StorageKey } from "./storage";
|
|
5
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
6
|
+
interface FetchStoreOptions extends StorageKey {
|
|
7
|
+
storeResult?: boolean;
|
|
8
|
+
shouldUseCachedResult?: boolean;
|
|
9
|
+
logging?: boolean;
|
|
10
|
+
expiration?: number;
|
|
11
|
+
}
|
|
12
|
+
interface FetchAPIOptions extends Omit<RequestInit, "body" | "method"> {
|
|
13
|
+
method?: HttpMethod;
|
|
14
|
+
body?: unknown;
|
|
15
|
+
params?: Record<string, string | number | boolean> | URLSearchParams;
|
|
16
|
+
clientStorage?: FetchStoreOptions;
|
|
17
|
+
}
|
|
18
|
+
export declare function apiQuery<T>(path: string, { clientStorage: storageOptions, ...init }?: FetchAPIOptions): Promise<T>;
|
|
19
|
+
export declare function getCalculation({ orderId, cart, lineItems }: CalculationParams, labelCount: number): Promise<CalculationResponse>;
|
|
20
|
+
export declare function getShopOverlayData(isFirstLoad: boolean, internalReturnId: string, lineIds: string): Promise<ShopOverlayData>;
|
|
21
|
+
export type ProcessOrderInitializationReturn = {
|
|
22
|
+
orderData: ShopOverlayData;
|
|
23
|
+
updatedCart: ShopifyCart | null;
|
|
24
|
+
};
|
|
25
|
+
export declare function processOrderInitialization({ isFirstLoad, options: { clearCartOnStart }, id: internalId, data: cache }: WidgetConfiguration): Promise<ProcessOrderInitializationReturn>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProductRule, ShopifyCart, ShopifyCartChangeResponse } from "../types";
|
|
2
|
+
export declare function getRuleProductIds(rules: ProductRule[], type: ProductRule["type"]): number[];
|
|
3
|
+
export declare function normalizeCart<T extends ShopifyCart>(cart: T, rules: ProductRule[]): T;
|
|
4
|
+
export declare function compareCarts(cart1: ShopifyCart, cart2: ShopifyCart, rules: ProductRule[]): boolean;
|
|
5
|
+
export declare function getCart(preferStorage?: boolean): Promise<ShopifyCart>;
|
|
6
|
+
export declare function clearCart(): Promise<ShopifyCart>;
|
|
7
|
+
export declare function setCartItems(items: Array<{
|
|
8
|
+
id: number;
|
|
9
|
+
quantity: number;
|
|
10
|
+
}>): Promise<ShopifyCart>;
|
|
11
|
+
export declare function updateCartItemQuantity({ variantId, quantity, isRetry }: {
|
|
12
|
+
variantId: number;
|
|
13
|
+
quantity: number;
|
|
14
|
+
isRetry?: boolean;
|
|
15
|
+
}): Promise<ShopifyCartChangeResponse | ShopifyCart>;
|
|
16
|
+
export declare function updateCartStorage(cart: ShopifyCart | null): void;
|
|
17
|
+
export declare function getCartStorage(): ShopifyCart | null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WidgetViewState } from "../types";
|
|
2
|
+
import { WidgetConfiguration } from "./initialization/types";
|
|
3
|
+
export declare const enum InternalCustomEvent {
|
|
4
|
+
FetchInterception = "RF_FETCH_INTERCEPTION",
|
|
5
|
+
XHRInterception = "RF_XHR_INTERCEPTION",
|
|
6
|
+
DrawerStateChange = "RF_DRAWER_STATE_CHANGE",
|
|
7
|
+
WidgetInitialization = "RF_WIDGET_INITIALIZATION"
|
|
8
|
+
}
|
|
9
|
+
export declare const enum ExternalCustomEvent {
|
|
10
|
+
DrawerOpen = "RF_DRAWER_OPEN",
|
|
11
|
+
DrawerClose = "RF_DRAWER_CLOSE",
|
|
12
|
+
DrawerToggle = "RF_DRAWER_TOGGLE",
|
|
13
|
+
CalculationRefetch = "RF_CALCULATION_REFETCH",
|
|
14
|
+
CartRefetch = "RF_CART_REFETCH",
|
|
15
|
+
CartAndCalculationRefetch = "RF_CART_AND_CALCULATION_REFETCH",
|
|
16
|
+
DrawerOpenAndRefetch = "RF_DRAWER_OPEN_AND_REFETCH"
|
|
17
|
+
}
|
|
18
|
+
export type XHRResponse = string | Record<string, unknown> | undefined;
|
|
19
|
+
export type FetchResponse = Response | undefined;
|
|
20
|
+
export type InterceptionResponse = XHRResponse | FetchResponse;
|
|
21
|
+
export interface InterceptionPayload {
|
|
22
|
+
response: InterceptionResponse;
|
|
23
|
+
requestUrl: string | URL;
|
|
24
|
+
}
|
|
25
|
+
export type CustomEventPayloadMap = {
|
|
26
|
+
[InternalCustomEvent.FetchInterception]: InterceptionPayload;
|
|
27
|
+
[InternalCustomEvent.XHRInterception]: InterceptionPayload;
|
|
28
|
+
[InternalCustomEvent.DrawerStateChange]: {
|
|
29
|
+
state: WidgetViewState;
|
|
30
|
+
};
|
|
31
|
+
[InternalCustomEvent.WidgetInitialization]: WidgetConfiguration;
|
|
32
|
+
[ExternalCustomEvent.DrawerOpen]: undefined;
|
|
33
|
+
[ExternalCustomEvent.DrawerClose]: undefined;
|
|
34
|
+
[ExternalCustomEvent.DrawerToggle]: undefined;
|
|
35
|
+
[ExternalCustomEvent.CalculationRefetch]: undefined;
|
|
36
|
+
[ExternalCustomEvent.CartRefetch]: undefined;
|
|
37
|
+
[ExternalCustomEvent.CartAndCalculationRefetch]: undefined;
|
|
38
|
+
[ExternalCustomEvent.DrawerOpenAndRefetch]: undefined;
|
|
39
|
+
};
|
|
40
|
+
declare function subscribe<K extends keyof CustomEventPayloadMap>(eventName: K, callback: (event: CustomEvent<CustomEventPayloadMap[K]>) => void): () => void;
|
|
41
|
+
declare function publish<K extends InternalCustomEvent>(eventName: K, ...args: K extends keyof CustomEventPayloadMap ? [detail: CustomEventPayloadMap[K]] : [detail?: undefined]): void;
|
|
42
|
+
declare function unsubscribe<K extends keyof CustomEventPayloadMap>(eventName: K, callback: (event: CustomEvent<CustomEventPayloadMap[K]>) => void): void;
|
|
43
|
+
declare const customEvents: {
|
|
44
|
+
subscribe: typeof subscribe;
|
|
45
|
+
publish: typeof publish;
|
|
46
|
+
unsubscribe: typeof unsubscribe;
|
|
47
|
+
};
|
|
48
|
+
export default customEvents;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ClassValue } from "clsx";
|
|
2
|
+
export declare function cn(...inputs: ClassValue[]): string;
|
|
3
|
+
export declare function assert(variable: unknown, message: string): asserts variable;
|
|
4
|
+
export declare function wait(ms: number): Promise<unknown>;
|
|
5
|
+
export declare function isNil(value: unknown): value is null | undefined;
|
|
6
|
+
export declare function ensureHttpUrl(url: string, secure?: boolean): string;
|
|
7
|
+
export declare function isNumber(value: unknown): value is number;
|
|
8
|
+
export declare function hexToHsl(hex: string): string;
|
|
9
|
+
export declare function isOnCartPage(): boolean;
|
|
10
|
+
interface WrapperOptions {
|
|
11
|
+
shouldThrow?: boolean;
|
|
12
|
+
logError?: boolean;
|
|
13
|
+
fallbackValue?: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function attempt<T, TThrow extends boolean = false>(fn: () => T, errorMessage: string, options?: WrapperOptions & {
|
|
16
|
+
shouldThrow?: TThrow;
|
|
17
|
+
}): TThrow extends true ? T : T | undefined;
|
|
18
|
+
export declare function parseToNumber(value: string | number | null | undefined, fallback?: number): number;
|
|
19
|
+
export declare function daysToMilliseconds(days: number): number;
|
|
20
|
+
export declare function secondsToMilliseconds(seconds: number): number;
|
|
21
|
+
export declare function setNestedValue<T>(obj: Record<string, unknown>, path: string, value: T): T;
|
|
22
|
+
export declare function getResolvedSearchParams(): URLSearchParams;
|
|
23
|
+
export declare function resolveSetStateAction<T>(action: React.SetStateAction<T>, currentState: T): T;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Messages } from "use-intl";
|
|
2
|
+
export type Locale = string;
|
|
3
|
+
export declare const DEFAULT_LOCALE: Locale;
|
|
4
|
+
export declare const DEFAULT_CURRENCY: string;
|
|
5
|
+
export declare function loadMessages(...locales: Locale[]): Promise<{
|
|
6
|
+
messages: Messages;
|
|
7
|
+
locale: Locale;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InitOptions, InitResult, WidgetSettings } from "./types";
|
|
2
|
+
export declare function isDOMStringMap(value: DOMStringMap | InitOptions): value is DOMStringMap;
|
|
3
|
+
export declare function parseScriptDataset(dataset: DOMStringMap): InitOptions;
|
|
4
|
+
export declare function getSettingsFromScript(): WidgetSettings | null;
|
|
5
|
+
export declare function prepareInitializationOptions(dataset: DOMStringMap | InitOptions): Promise<InitResult>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComponentChild } from "preact";
|
|
2
|
+
import { InitOptions, InitResult, WidgetConfiguration } from "./types";
|
|
3
|
+
type RenderNode = (config: WidgetConfiguration) => ComponentChild;
|
|
4
|
+
declare function initialize(renderNode: RenderNode, options: DOMStringMap | InitOptions): Promise<InitResult>;
|
|
5
|
+
export type { InitResult };
|
|
6
|
+
export default initialize;
|