@neowhale/storefront 0.1.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/chunk-PR4PUHVN.js +273 -0
- package/dist/chunk-PR4PUHVN.js.map +1 -0
- package/dist/chunk-XMLH3TLA.cjs +275 -0
- package/dist/chunk-XMLH3TLA.cjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.cjs +123 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +117 -0
- package/dist/next/index.d.ts +117 -0
- package/dist/next/index.js +115 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.cjs +673 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +243 -0
- package/dist/react/index.d.ts +243 -0
- package/dist/react/index.js +657 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +70 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXMLH3TLA_cjs = require('./chunk-XMLH3TLA.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "WhaleClient", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkXMLH3TLA_cjs.WhaleClient; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
12
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
interface PricingTier {
|
|
2
|
+
id: string;
|
|
3
|
+
unit: string;
|
|
4
|
+
label: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
sort_order: number;
|
|
7
|
+
default_price: number;
|
|
8
|
+
}
|
|
9
|
+
interface ProductVariation {
|
|
10
|
+
id: string;
|
|
11
|
+
product_id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
sku: string | null;
|
|
14
|
+
price: number;
|
|
15
|
+
stock_quantity: number;
|
|
16
|
+
attributes: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
interface Product {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
sku: string | null;
|
|
23
|
+
description: string | null;
|
|
24
|
+
status: string;
|
|
25
|
+
type: string;
|
|
26
|
+
primary_category_id: string;
|
|
27
|
+
featured_image: string | null;
|
|
28
|
+
image_gallery: string[];
|
|
29
|
+
pricing_data: PricingTier[] | {
|
|
30
|
+
mode?: string;
|
|
31
|
+
tiers?: PricingTier[];
|
|
32
|
+
} | null;
|
|
33
|
+
custom_fields: Record<string, string | null>;
|
|
34
|
+
stock_quantity?: number;
|
|
35
|
+
}
|
|
36
|
+
interface Category {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
}
|
|
41
|
+
interface CartItem {
|
|
42
|
+
id: string;
|
|
43
|
+
product_id: string;
|
|
44
|
+
product_name: string;
|
|
45
|
+
image_url: string | null;
|
|
46
|
+
quantity: number;
|
|
47
|
+
unit_price: number;
|
|
48
|
+
tier_label: string | null;
|
|
49
|
+
line_total: number;
|
|
50
|
+
}
|
|
51
|
+
interface TaxBreakdown {
|
|
52
|
+
name: string;
|
|
53
|
+
rate: number;
|
|
54
|
+
type: string;
|
|
55
|
+
rate_decimal: number;
|
|
56
|
+
}
|
|
57
|
+
interface Cart {
|
|
58
|
+
id: string;
|
|
59
|
+
items: CartItem[];
|
|
60
|
+
item_count: number;
|
|
61
|
+
subtotal: number;
|
|
62
|
+
tax_rate: number;
|
|
63
|
+
tax_amount: number;
|
|
64
|
+
total: number;
|
|
65
|
+
tax_breakdown: TaxBreakdown[];
|
|
66
|
+
discount_amount: number;
|
|
67
|
+
customer_email: string | null;
|
|
68
|
+
}
|
|
69
|
+
interface Order {
|
|
70
|
+
id: string;
|
|
71
|
+
order_number: string;
|
|
72
|
+
status: string;
|
|
73
|
+
total_amount: number;
|
|
74
|
+
subtotal: number;
|
|
75
|
+
tax_amount: number;
|
|
76
|
+
discount_amount: number;
|
|
77
|
+
item_count?: number;
|
|
78
|
+
created_at: string;
|
|
79
|
+
payment_status?: string;
|
|
80
|
+
fulfillment_status?: string;
|
|
81
|
+
items?: OrderItem[];
|
|
82
|
+
}
|
|
83
|
+
interface OrderItem {
|
|
84
|
+
id: string;
|
|
85
|
+
product_name: string;
|
|
86
|
+
quantity: number;
|
|
87
|
+
unit_price?: number;
|
|
88
|
+
cost_per_unit?: number;
|
|
89
|
+
line_total: number;
|
|
90
|
+
}
|
|
91
|
+
interface Customer {
|
|
92
|
+
id: string;
|
|
93
|
+
first_name: string;
|
|
94
|
+
last_name: string;
|
|
95
|
+
email: string | null;
|
|
96
|
+
phone: string | null;
|
|
97
|
+
loyalty_points: number;
|
|
98
|
+
loyalty_tier: string;
|
|
99
|
+
total_spent: number;
|
|
100
|
+
total_orders: number;
|
|
101
|
+
lifetime_value?: number;
|
|
102
|
+
street_address?: string | null;
|
|
103
|
+
city?: string | null;
|
|
104
|
+
state?: string | null;
|
|
105
|
+
postal_code?: string | null;
|
|
106
|
+
date_of_birth?: string | null;
|
|
107
|
+
created_at?: string;
|
|
108
|
+
is_staff?: boolean;
|
|
109
|
+
email_consent?: boolean;
|
|
110
|
+
sms_consent?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface Address {
|
|
113
|
+
firstName: string;
|
|
114
|
+
lastName: string;
|
|
115
|
+
address: string;
|
|
116
|
+
city: string;
|
|
117
|
+
state: string;
|
|
118
|
+
zip: string;
|
|
119
|
+
country: string;
|
|
120
|
+
}
|
|
121
|
+
interface PaymentData {
|
|
122
|
+
payment_method: 'card' | 'cash';
|
|
123
|
+
opaque_data?: {
|
|
124
|
+
dataDescriptor: string;
|
|
125
|
+
dataValue: string;
|
|
126
|
+
};
|
|
127
|
+
billTo?: Address;
|
|
128
|
+
shipTo?: Address;
|
|
129
|
+
}
|
|
130
|
+
interface CustomerAnalytics {
|
|
131
|
+
customer_id: string;
|
|
132
|
+
customer_name: string;
|
|
133
|
+
total_orders: number;
|
|
134
|
+
lifetime_revenue: number;
|
|
135
|
+
avg_order_value: number;
|
|
136
|
+
ltv_tier: string;
|
|
137
|
+
rfm_segment: string;
|
|
138
|
+
churn_risk: string;
|
|
139
|
+
last_order_date: string;
|
|
140
|
+
recency_days: number;
|
|
141
|
+
}
|
|
142
|
+
interface Location {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
address?: string;
|
|
146
|
+
city?: string;
|
|
147
|
+
state?: string;
|
|
148
|
+
zip?: string;
|
|
149
|
+
phone?: string;
|
|
150
|
+
is_active?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface SendCodeResponse {
|
|
153
|
+
sent: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface VerifyCodeResponse {
|
|
156
|
+
object: string;
|
|
157
|
+
token_hash: string;
|
|
158
|
+
needs_profile: boolean;
|
|
159
|
+
customer: Customer | null;
|
|
160
|
+
}
|
|
161
|
+
interface StorefrontSession {
|
|
162
|
+
id: string;
|
|
163
|
+
store_id: string;
|
|
164
|
+
customer_id?: string;
|
|
165
|
+
started_at: string;
|
|
166
|
+
last_active_at: string;
|
|
167
|
+
}
|
|
168
|
+
interface ListResponse<T> {
|
|
169
|
+
object: 'list';
|
|
170
|
+
data: T[];
|
|
171
|
+
has_more: boolean;
|
|
172
|
+
cursors?: {
|
|
173
|
+
before?: string;
|
|
174
|
+
after?: string;
|
|
175
|
+
};
|
|
176
|
+
url?: string;
|
|
177
|
+
}
|
|
178
|
+
interface WhaleStorefrontConfig {
|
|
179
|
+
/** Store UUID */
|
|
180
|
+
storeId: string;
|
|
181
|
+
/** API key (wk_live_... or wk_test_...) */
|
|
182
|
+
apiKey: string;
|
|
183
|
+
/** Gateway base URL. Defaults to https://whale-gateway.fly.dev */
|
|
184
|
+
gatewayUrl?: string;
|
|
185
|
+
/** Client-side proxy path. Defaults to /api/gw */
|
|
186
|
+
proxyPath?: string;
|
|
187
|
+
/** Media signing secret for image/video proxy */
|
|
188
|
+
mediaSigningSecret?: string;
|
|
189
|
+
/** Supabase host for media URL detection */
|
|
190
|
+
supabaseHost?: string;
|
|
191
|
+
/** localStorage key prefix. Defaults to "whale" */
|
|
192
|
+
storagePrefix?: string;
|
|
193
|
+
/** Analytics session TTL in ms. Defaults to 30 minutes */
|
|
194
|
+
sessionTtl?: number;
|
|
195
|
+
/** Enable debug logging */
|
|
196
|
+
debug?: boolean;
|
|
197
|
+
}
|
|
198
|
+
type EventType = 'page_view' | 'product_view' | 'add_to_cart' | 'remove_from_cart' | 'begin_checkout' | 'purchase' | 'category_view' | 'search';
|
|
199
|
+
|
|
200
|
+
declare class WhaleClient {
|
|
201
|
+
readonly storeId: string;
|
|
202
|
+
readonly apiKey: string;
|
|
203
|
+
readonly gatewayUrl: string;
|
|
204
|
+
readonly proxyPath: string;
|
|
205
|
+
private _sessionToken;
|
|
206
|
+
constructor(config: WhaleStorefrontConfig);
|
|
207
|
+
setSessionToken(token: string | null): void;
|
|
208
|
+
getSessionToken(): string | null;
|
|
209
|
+
private get baseUrl();
|
|
210
|
+
private request;
|
|
211
|
+
listProducts(params?: {
|
|
212
|
+
limit?: number;
|
|
213
|
+
starting_after?: string;
|
|
214
|
+
status?: string;
|
|
215
|
+
}): Promise<ListResponse<Product>>;
|
|
216
|
+
getProduct(id: string): Promise<Product>;
|
|
217
|
+
getAllProducts(options?: {
|
|
218
|
+
status?: string;
|
|
219
|
+
maxPages?: number;
|
|
220
|
+
revalidate?: number;
|
|
221
|
+
filter?: (product: Product) => boolean;
|
|
222
|
+
}): Promise<Product[]>;
|
|
223
|
+
createCart(customerEmail?: string): Promise<Cart>;
|
|
224
|
+
getCart(cartId: string): Promise<Cart>;
|
|
225
|
+
addToCart(cartId: string, productId: string, quantity: number, options?: {
|
|
226
|
+
tier?: string;
|
|
227
|
+
unitPrice?: number;
|
|
228
|
+
}): Promise<CartItem>;
|
|
229
|
+
updateCartItem(cartId: string, itemId: string, quantity: number): Promise<Cart>;
|
|
230
|
+
removeCartItem(cartId: string, itemId: string): Promise<void>;
|
|
231
|
+
checkout(cartId: string, customerEmail?: string, payment?: PaymentData): Promise<Order>;
|
|
232
|
+
findCustomer(query: string): Promise<Customer[]>;
|
|
233
|
+
getCustomer(id: string): Promise<Customer>;
|
|
234
|
+
createCustomer(data: {
|
|
235
|
+
first_name: string;
|
|
236
|
+
last_name: string;
|
|
237
|
+
email: string;
|
|
238
|
+
phone?: string;
|
|
239
|
+
}): Promise<Customer>;
|
|
240
|
+
listOrders(params?: {
|
|
241
|
+
customer_id?: string;
|
|
242
|
+
limit?: number;
|
|
243
|
+
starting_after?: string;
|
|
244
|
+
}): Promise<ListResponse<Order>>;
|
|
245
|
+
getOrder(id: string): Promise<Order>;
|
|
246
|
+
getCustomerOrders(customerId: string): Promise<Order[]>;
|
|
247
|
+
sendCode(email: string): Promise<SendCodeResponse>;
|
|
248
|
+
verifyCode(email: string, code: string): Promise<VerifyCodeResponse>;
|
|
249
|
+
getCustomerAnalytics(customerId: string, customerName?: string): Promise<CustomerAnalytics | null>;
|
|
250
|
+
listLocations(): Promise<ListResponse<Location>>;
|
|
251
|
+
getCOAEmbedUrl(productId: string): string;
|
|
252
|
+
createSession(params: {
|
|
253
|
+
user_agent?: string;
|
|
254
|
+
referrer?: string;
|
|
255
|
+
}): Promise<StorefrontSession>;
|
|
256
|
+
updateSession(sessionId: string, params: {
|
|
257
|
+
last_active_at?: string;
|
|
258
|
+
customer_id?: string;
|
|
259
|
+
}): Promise<StorefrontSession>;
|
|
260
|
+
trackEvent(params: {
|
|
261
|
+
session_id: string;
|
|
262
|
+
event_type: EventType;
|
|
263
|
+
event_data?: Record<string, unknown>;
|
|
264
|
+
}): Promise<void>;
|
|
265
|
+
static encodeBase64Url(url: string): string;
|
|
266
|
+
static signMedia(signingSecret: string, encodedUrl: string, w: string, q: string, f: string): string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type Address, type Cart, type CartItem, type Category, type Customer, type CustomerAnalytics, type EventType, type ListResponse, type Location, type Order, type OrderItem, type PaymentData, type PricingTier, type Product, type ProductVariation, type SendCodeResponse, type StorefrontSession, type TaxBreakdown, type VerifyCodeResponse, WhaleClient, type WhaleStorefrontConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
interface PricingTier {
|
|
2
|
+
id: string;
|
|
3
|
+
unit: string;
|
|
4
|
+
label: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
sort_order: number;
|
|
7
|
+
default_price: number;
|
|
8
|
+
}
|
|
9
|
+
interface ProductVariation {
|
|
10
|
+
id: string;
|
|
11
|
+
product_id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
sku: string | null;
|
|
14
|
+
price: number;
|
|
15
|
+
stock_quantity: number;
|
|
16
|
+
attributes: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
interface Product {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
sku: string | null;
|
|
23
|
+
description: string | null;
|
|
24
|
+
status: string;
|
|
25
|
+
type: string;
|
|
26
|
+
primary_category_id: string;
|
|
27
|
+
featured_image: string | null;
|
|
28
|
+
image_gallery: string[];
|
|
29
|
+
pricing_data: PricingTier[] | {
|
|
30
|
+
mode?: string;
|
|
31
|
+
tiers?: PricingTier[];
|
|
32
|
+
} | null;
|
|
33
|
+
custom_fields: Record<string, string | null>;
|
|
34
|
+
stock_quantity?: number;
|
|
35
|
+
}
|
|
36
|
+
interface Category {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
}
|
|
41
|
+
interface CartItem {
|
|
42
|
+
id: string;
|
|
43
|
+
product_id: string;
|
|
44
|
+
product_name: string;
|
|
45
|
+
image_url: string | null;
|
|
46
|
+
quantity: number;
|
|
47
|
+
unit_price: number;
|
|
48
|
+
tier_label: string | null;
|
|
49
|
+
line_total: number;
|
|
50
|
+
}
|
|
51
|
+
interface TaxBreakdown {
|
|
52
|
+
name: string;
|
|
53
|
+
rate: number;
|
|
54
|
+
type: string;
|
|
55
|
+
rate_decimal: number;
|
|
56
|
+
}
|
|
57
|
+
interface Cart {
|
|
58
|
+
id: string;
|
|
59
|
+
items: CartItem[];
|
|
60
|
+
item_count: number;
|
|
61
|
+
subtotal: number;
|
|
62
|
+
tax_rate: number;
|
|
63
|
+
tax_amount: number;
|
|
64
|
+
total: number;
|
|
65
|
+
tax_breakdown: TaxBreakdown[];
|
|
66
|
+
discount_amount: number;
|
|
67
|
+
customer_email: string | null;
|
|
68
|
+
}
|
|
69
|
+
interface Order {
|
|
70
|
+
id: string;
|
|
71
|
+
order_number: string;
|
|
72
|
+
status: string;
|
|
73
|
+
total_amount: number;
|
|
74
|
+
subtotal: number;
|
|
75
|
+
tax_amount: number;
|
|
76
|
+
discount_amount: number;
|
|
77
|
+
item_count?: number;
|
|
78
|
+
created_at: string;
|
|
79
|
+
payment_status?: string;
|
|
80
|
+
fulfillment_status?: string;
|
|
81
|
+
items?: OrderItem[];
|
|
82
|
+
}
|
|
83
|
+
interface OrderItem {
|
|
84
|
+
id: string;
|
|
85
|
+
product_name: string;
|
|
86
|
+
quantity: number;
|
|
87
|
+
unit_price?: number;
|
|
88
|
+
cost_per_unit?: number;
|
|
89
|
+
line_total: number;
|
|
90
|
+
}
|
|
91
|
+
interface Customer {
|
|
92
|
+
id: string;
|
|
93
|
+
first_name: string;
|
|
94
|
+
last_name: string;
|
|
95
|
+
email: string | null;
|
|
96
|
+
phone: string | null;
|
|
97
|
+
loyalty_points: number;
|
|
98
|
+
loyalty_tier: string;
|
|
99
|
+
total_spent: number;
|
|
100
|
+
total_orders: number;
|
|
101
|
+
lifetime_value?: number;
|
|
102
|
+
street_address?: string | null;
|
|
103
|
+
city?: string | null;
|
|
104
|
+
state?: string | null;
|
|
105
|
+
postal_code?: string | null;
|
|
106
|
+
date_of_birth?: string | null;
|
|
107
|
+
created_at?: string;
|
|
108
|
+
is_staff?: boolean;
|
|
109
|
+
email_consent?: boolean;
|
|
110
|
+
sms_consent?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface Address {
|
|
113
|
+
firstName: string;
|
|
114
|
+
lastName: string;
|
|
115
|
+
address: string;
|
|
116
|
+
city: string;
|
|
117
|
+
state: string;
|
|
118
|
+
zip: string;
|
|
119
|
+
country: string;
|
|
120
|
+
}
|
|
121
|
+
interface PaymentData {
|
|
122
|
+
payment_method: 'card' | 'cash';
|
|
123
|
+
opaque_data?: {
|
|
124
|
+
dataDescriptor: string;
|
|
125
|
+
dataValue: string;
|
|
126
|
+
};
|
|
127
|
+
billTo?: Address;
|
|
128
|
+
shipTo?: Address;
|
|
129
|
+
}
|
|
130
|
+
interface CustomerAnalytics {
|
|
131
|
+
customer_id: string;
|
|
132
|
+
customer_name: string;
|
|
133
|
+
total_orders: number;
|
|
134
|
+
lifetime_revenue: number;
|
|
135
|
+
avg_order_value: number;
|
|
136
|
+
ltv_tier: string;
|
|
137
|
+
rfm_segment: string;
|
|
138
|
+
churn_risk: string;
|
|
139
|
+
last_order_date: string;
|
|
140
|
+
recency_days: number;
|
|
141
|
+
}
|
|
142
|
+
interface Location {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
address?: string;
|
|
146
|
+
city?: string;
|
|
147
|
+
state?: string;
|
|
148
|
+
zip?: string;
|
|
149
|
+
phone?: string;
|
|
150
|
+
is_active?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface SendCodeResponse {
|
|
153
|
+
sent: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface VerifyCodeResponse {
|
|
156
|
+
object: string;
|
|
157
|
+
token_hash: string;
|
|
158
|
+
needs_profile: boolean;
|
|
159
|
+
customer: Customer | null;
|
|
160
|
+
}
|
|
161
|
+
interface StorefrontSession {
|
|
162
|
+
id: string;
|
|
163
|
+
store_id: string;
|
|
164
|
+
customer_id?: string;
|
|
165
|
+
started_at: string;
|
|
166
|
+
last_active_at: string;
|
|
167
|
+
}
|
|
168
|
+
interface ListResponse<T> {
|
|
169
|
+
object: 'list';
|
|
170
|
+
data: T[];
|
|
171
|
+
has_more: boolean;
|
|
172
|
+
cursors?: {
|
|
173
|
+
before?: string;
|
|
174
|
+
after?: string;
|
|
175
|
+
};
|
|
176
|
+
url?: string;
|
|
177
|
+
}
|
|
178
|
+
interface WhaleStorefrontConfig {
|
|
179
|
+
/** Store UUID */
|
|
180
|
+
storeId: string;
|
|
181
|
+
/** API key (wk_live_... or wk_test_...) */
|
|
182
|
+
apiKey: string;
|
|
183
|
+
/** Gateway base URL. Defaults to https://whale-gateway.fly.dev */
|
|
184
|
+
gatewayUrl?: string;
|
|
185
|
+
/** Client-side proxy path. Defaults to /api/gw */
|
|
186
|
+
proxyPath?: string;
|
|
187
|
+
/** Media signing secret for image/video proxy */
|
|
188
|
+
mediaSigningSecret?: string;
|
|
189
|
+
/** Supabase host for media URL detection */
|
|
190
|
+
supabaseHost?: string;
|
|
191
|
+
/** localStorage key prefix. Defaults to "whale" */
|
|
192
|
+
storagePrefix?: string;
|
|
193
|
+
/** Analytics session TTL in ms. Defaults to 30 minutes */
|
|
194
|
+
sessionTtl?: number;
|
|
195
|
+
/** Enable debug logging */
|
|
196
|
+
debug?: boolean;
|
|
197
|
+
}
|
|
198
|
+
type EventType = 'page_view' | 'product_view' | 'add_to_cart' | 'remove_from_cart' | 'begin_checkout' | 'purchase' | 'category_view' | 'search';
|
|
199
|
+
|
|
200
|
+
declare class WhaleClient {
|
|
201
|
+
readonly storeId: string;
|
|
202
|
+
readonly apiKey: string;
|
|
203
|
+
readonly gatewayUrl: string;
|
|
204
|
+
readonly proxyPath: string;
|
|
205
|
+
private _sessionToken;
|
|
206
|
+
constructor(config: WhaleStorefrontConfig);
|
|
207
|
+
setSessionToken(token: string | null): void;
|
|
208
|
+
getSessionToken(): string | null;
|
|
209
|
+
private get baseUrl();
|
|
210
|
+
private request;
|
|
211
|
+
listProducts(params?: {
|
|
212
|
+
limit?: number;
|
|
213
|
+
starting_after?: string;
|
|
214
|
+
status?: string;
|
|
215
|
+
}): Promise<ListResponse<Product>>;
|
|
216
|
+
getProduct(id: string): Promise<Product>;
|
|
217
|
+
getAllProducts(options?: {
|
|
218
|
+
status?: string;
|
|
219
|
+
maxPages?: number;
|
|
220
|
+
revalidate?: number;
|
|
221
|
+
filter?: (product: Product) => boolean;
|
|
222
|
+
}): Promise<Product[]>;
|
|
223
|
+
createCart(customerEmail?: string): Promise<Cart>;
|
|
224
|
+
getCart(cartId: string): Promise<Cart>;
|
|
225
|
+
addToCart(cartId: string, productId: string, quantity: number, options?: {
|
|
226
|
+
tier?: string;
|
|
227
|
+
unitPrice?: number;
|
|
228
|
+
}): Promise<CartItem>;
|
|
229
|
+
updateCartItem(cartId: string, itemId: string, quantity: number): Promise<Cart>;
|
|
230
|
+
removeCartItem(cartId: string, itemId: string): Promise<void>;
|
|
231
|
+
checkout(cartId: string, customerEmail?: string, payment?: PaymentData): Promise<Order>;
|
|
232
|
+
findCustomer(query: string): Promise<Customer[]>;
|
|
233
|
+
getCustomer(id: string): Promise<Customer>;
|
|
234
|
+
createCustomer(data: {
|
|
235
|
+
first_name: string;
|
|
236
|
+
last_name: string;
|
|
237
|
+
email: string;
|
|
238
|
+
phone?: string;
|
|
239
|
+
}): Promise<Customer>;
|
|
240
|
+
listOrders(params?: {
|
|
241
|
+
customer_id?: string;
|
|
242
|
+
limit?: number;
|
|
243
|
+
starting_after?: string;
|
|
244
|
+
}): Promise<ListResponse<Order>>;
|
|
245
|
+
getOrder(id: string): Promise<Order>;
|
|
246
|
+
getCustomerOrders(customerId: string): Promise<Order[]>;
|
|
247
|
+
sendCode(email: string): Promise<SendCodeResponse>;
|
|
248
|
+
verifyCode(email: string, code: string): Promise<VerifyCodeResponse>;
|
|
249
|
+
getCustomerAnalytics(customerId: string, customerName?: string): Promise<CustomerAnalytics | null>;
|
|
250
|
+
listLocations(): Promise<ListResponse<Location>>;
|
|
251
|
+
getCOAEmbedUrl(productId: string): string;
|
|
252
|
+
createSession(params: {
|
|
253
|
+
user_agent?: string;
|
|
254
|
+
referrer?: string;
|
|
255
|
+
}): Promise<StorefrontSession>;
|
|
256
|
+
updateSession(sessionId: string, params: {
|
|
257
|
+
last_active_at?: string;
|
|
258
|
+
customer_id?: string;
|
|
259
|
+
}): Promise<StorefrontSession>;
|
|
260
|
+
trackEvent(params: {
|
|
261
|
+
session_id: string;
|
|
262
|
+
event_type: EventType;
|
|
263
|
+
event_data?: Record<string, unknown>;
|
|
264
|
+
}): Promise<void>;
|
|
265
|
+
static encodeBase64Url(url: string): string;
|
|
266
|
+
static signMedia(signingSecret: string, encodedUrl: string, w: string, q: string, f: string): string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type Address, type Cart, type CartItem, type Category, type Customer, type CustomerAnalytics, type EventType, type ListResponse, type Location, type Order, type OrderItem, type PaymentData, type PricingTier, type Product, type ProductVariation, type SendCodeResponse, type StorefrontSession, type TaxBreakdown, type VerifyCodeResponse, WhaleClient, type WhaleStorefrontConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXMLH3TLA_cjs = require('../chunk-XMLH3TLA.cjs');
|
|
4
|
+
var server = require('next/server');
|
|
5
|
+
|
|
6
|
+
// src/next/headers.ts
|
|
7
|
+
var securityHeaders = [
|
|
8
|
+
{
|
|
9
|
+
key: "X-DNS-Prefetch-Control",
|
|
10
|
+
value: "on"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
key: "Strict-Transport-Security",
|
|
14
|
+
value: "max-age=63072000; includeSubDomains; preload"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "X-Content-Type-Options",
|
|
18
|
+
value: "nosniff"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "X-Frame-Options",
|
|
22
|
+
value: "SAMEORIGIN"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "X-XSS-Protection",
|
|
26
|
+
value: "1; mode=block"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "Referrer-Policy",
|
|
30
|
+
value: "strict-origin-when-cross-origin"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "Permissions-Policy",
|
|
34
|
+
value: "camera=(), microphone=(), geolocation=(self), interest-cohort=()"
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
function withSecurityHeaders(extra) {
|
|
38
|
+
const allHeaders = extra ? [...securityHeaders, ...extra] : securityHeaders;
|
|
39
|
+
return async () => [
|
|
40
|
+
{
|
|
41
|
+
source: "/:path*",
|
|
42
|
+
headers: allHeaders
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/next/rewrite.ts
|
|
48
|
+
function whaleGatewayRewrite(gatewayUrl = "https://whale-gateway.fly.dev", proxyPath = "/api/gw") {
|
|
49
|
+
return {
|
|
50
|
+
source: `${proxyPath}/:path*`,
|
|
51
|
+
destination: `${gatewayUrl}/:path*`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/next/server.ts
|
|
56
|
+
function createServerClient(config) {
|
|
57
|
+
return new chunkXMLH3TLA_cjs.WhaleClient({
|
|
58
|
+
storeId: config?.storeId || process.env.NEXT_PUBLIC_STORE_ID || "",
|
|
59
|
+
apiKey: config?.apiKey || process.env.NEXT_PUBLIC_API_KEY || "",
|
|
60
|
+
gatewayUrl: config?.gatewayUrl || process.env.NEXT_PUBLIC_API_URL || "https://whale-gateway.fly.dev",
|
|
61
|
+
proxyPath: config?.proxyPath
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function getAllProducts(options) {
|
|
65
|
+
const client = options?.client ?? createServerClient();
|
|
66
|
+
return client.getAllProducts({
|
|
67
|
+
status: "published",
|
|
68
|
+
revalidate: options?.revalidate ?? 60,
|
|
69
|
+
filter: options?.filter
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/next/image-loader.ts
|
|
74
|
+
var ALLOWED_WIDTHS = [64, 96, 128, 256, 384, 640, 828, 1080, 1280, 1920];
|
|
75
|
+
function snapWidth(w) {
|
|
76
|
+
for (const aw of ALLOWED_WIDTHS) {
|
|
77
|
+
if (aw >= w) return aw;
|
|
78
|
+
}
|
|
79
|
+
return ALLOWED_WIDTHS[ALLOWED_WIDTHS.length - 1];
|
|
80
|
+
}
|
|
81
|
+
function createImageLoader(config) {
|
|
82
|
+
return ({ src, width, quality }) => {
|
|
83
|
+
if (!src.includes(config.supabaseHost)) {
|
|
84
|
+
return src;
|
|
85
|
+
}
|
|
86
|
+
const w = String(snapWidth(width));
|
|
87
|
+
const q = String(quality || 80);
|
|
88
|
+
const f = "webp";
|
|
89
|
+
const encoded = chunkXMLH3TLA_cjs.WhaleClient.encodeBase64Url(src);
|
|
90
|
+
const s = chunkXMLH3TLA_cjs.WhaleClient.signMedia(config.signingSecret, encoded, w, q, f);
|
|
91
|
+
return `${config.gatewayUrl}/v1/stores/${config.storeId}/media?url=${encoded}&w=${w}&q=${q}&f=${f}&s=${s}`;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function createAuthMiddleware(options) {
|
|
95
|
+
const { protectedPaths, loginPath, cookieName = "whale-session" } = options;
|
|
96
|
+
return function middleware(request) {
|
|
97
|
+
const { pathname } = request.nextUrl;
|
|
98
|
+
const isProtected = protectedPaths.some(
|
|
99
|
+
(p) => pathname === p || pathname.startsWith(`${p}/`)
|
|
100
|
+
);
|
|
101
|
+
if (!isProtected) {
|
|
102
|
+
return server.NextResponse.next();
|
|
103
|
+
}
|
|
104
|
+
const token = request.cookies.get(cookieName)?.value;
|
|
105
|
+
if (!token) {
|
|
106
|
+
const url = request.nextUrl.clone();
|
|
107
|
+
url.pathname = loginPath;
|
|
108
|
+
url.searchParams.set("redirect", pathname);
|
|
109
|
+
return server.NextResponse.redirect(url);
|
|
110
|
+
}
|
|
111
|
+
return server.NextResponse.next();
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
exports.createAuthMiddleware = createAuthMiddleware;
|
|
116
|
+
exports.createImageLoader = createImageLoader;
|
|
117
|
+
exports.createServerClient = createServerClient;
|
|
118
|
+
exports.getAllProducts = getAllProducts;
|
|
119
|
+
exports.securityHeaders = securityHeaders;
|
|
120
|
+
exports.whaleGatewayRewrite = whaleGatewayRewrite;
|
|
121
|
+
exports.withSecurityHeaders = withSecurityHeaders;
|
|
122
|
+
//# sourceMappingURL=index.cjs.map
|
|
123
|
+
//# sourceMappingURL=index.cjs.map
|