@getmicdrop/venue-calendar 3.2.0 → 3.3.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 +661 -661
- package/dist/{VenueCalendar-Xppig0q_.js → VenueCalendar-BMSfRl2d.js} +10 -13
- package/dist/VenueCalendar-BMSfRl2d.js.map +1 -0
- package/dist/{index-BjErG0CG.js → index-CoJaem3n.js} +2 -2
- package/dist/{index-BjErG0CG.js.map → index-CoJaem3n.js.map} +1 -1
- package/dist/types/index.d.ts +395 -395
- package/dist/venue-calendar.css +1 -1
- package/dist/venue-calendar.es.js +1 -1
- package/dist/venue-calendar.iife.js +4 -4
- package/dist/venue-calendar.iife.js.map +1 -1
- package/dist/venue-calendar.umd.js +4 -4
- package/dist/venue-calendar.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/api/client.ts +210 -210
- package/src/lib/api/events.ts +358 -358
- package/src/lib/api/index.ts +182 -182
- package/src/lib/api/orders.ts +390 -390
- package/src/lib/api/promo.ts +164 -164
- package/src/lib/api/transformers/event.ts +248 -248
- package/src/lib/api/transformers/index.ts +29 -29
- package/src/lib/api/transformers/order.ts +207 -207
- package/src/lib/api/transformers/venue.ts +118 -118
- package/src/lib/api/types.ts +289 -289
- package/src/lib/api/venues.ts +100 -100
- package/src/lib/theme.js +209 -209
- package/dist/VenueCalendar-Xppig0q_.js.map +0 -1
package/src/lib/api/promo.ts
CHANGED
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Promo Codes API
|
|
3
|
-
*
|
|
4
|
-
* Functions for validating and checking promo codes
|
|
5
|
-
* in the public checkout flow.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { logger } from '../utils/logger.js';
|
|
9
|
-
import { getPublicBaseUrl } from './client.js';
|
|
10
|
-
import type { PromoValidationResponse, HasPromoCodesResponse } from './types.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Validate a promo code for an event
|
|
14
|
-
*
|
|
15
|
-
* Checks if a promo code is valid and returns its effects:
|
|
16
|
-
* - Discount amount and type
|
|
17
|
-
* - Hidden ticket reveal
|
|
18
|
-
*
|
|
19
|
-
* @param eventId - The event ID
|
|
20
|
-
* @param code - The promo code to validate
|
|
21
|
-
* @returns Validation result with discount info
|
|
22
|
-
*/
|
|
23
|
-
export async function validatePromoCode(
|
|
24
|
-
eventId: string | number,
|
|
25
|
-
code: string
|
|
26
|
-
): Promise<PromoValidationResponse> {
|
|
27
|
-
try {
|
|
28
|
-
if (!code || !code.trim()) {
|
|
29
|
-
return { valid: false, error: 'Promo code is required' };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// API uses GET with code in URL path
|
|
33
|
-
const encodedCode = encodeURIComponent(code.trim());
|
|
34
|
-
const response = await fetch(
|
|
35
|
-
`${getPublicBaseUrl()}/promo-codes/validate/${eventId}/${encodedCode}`
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
// 404 = invalid code, other errors are server issues
|
|
40
|
-
if (response.status === 404) {
|
|
41
|
-
return { valid: false, error: 'Invalid promo code' };
|
|
42
|
-
}
|
|
43
|
-
const errorData = await response.json().catch(() => ({}));
|
|
44
|
-
return { valid: false, error: errorData.error || 'Failed to validate code' };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result = await response.json();
|
|
48
|
-
return {
|
|
49
|
-
valid: result.valid ?? true,
|
|
50
|
-
revealHiddenTickets: result.revealHiddenTickets,
|
|
51
|
-
revealTicketIds: result.revealTicketIds,
|
|
52
|
-
provideDiscount: result.provideDiscount,
|
|
53
|
-
discountType: result.discountType,
|
|
54
|
-
amount: result.amount,
|
|
55
|
-
code: result.code || code,
|
|
56
|
-
};
|
|
57
|
-
} catch (error) {
|
|
58
|
-
logger.error('Error validating promo code:', error);
|
|
59
|
-
return { valid: false, error: 'Network error validating code' };
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Check if promo codes are available for an event
|
|
65
|
-
*
|
|
66
|
-
* Used to conditionally show/hide the promo code input field.
|
|
67
|
-
*
|
|
68
|
-
* @param eventId - The event ID
|
|
69
|
-
* @returns Whether promo codes exist for this event
|
|
70
|
-
*/
|
|
71
|
-
export async function hasPromoCodes(eventId: string | number): Promise<boolean> {
|
|
72
|
-
try {
|
|
73
|
-
const response = await fetch(
|
|
74
|
-
`${getPublicBaseUrl()}/promo-codes/check/${eventId}`
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
if (!response.ok) {
|
|
78
|
-
// If endpoint doesn't exist or errors, default to showing the input
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const result: HasPromoCodesResponse = await response.json();
|
|
83
|
-
return result.hasPromoCodes === true;
|
|
84
|
-
} catch (error) {
|
|
85
|
-
logger.error('Error checking promo codes availability:', error);
|
|
86
|
-
// Default to showing promo input if we can't check
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Apply a promo code to a cart
|
|
93
|
-
*
|
|
94
|
-
* This updates the cart with the promo code discount.
|
|
95
|
-
*
|
|
96
|
-
* @param cartId - The cart UUID
|
|
97
|
-
* @param code - The promo code to apply
|
|
98
|
-
* @returns Success status
|
|
99
|
-
*/
|
|
100
|
-
export async function applyPromoCode(
|
|
101
|
-
cartId: string,
|
|
102
|
-
code: string
|
|
103
|
-
): Promise<{ success: boolean; error?: string }> {
|
|
104
|
-
try {
|
|
105
|
-
const response = await fetch(
|
|
106
|
-
`${getPublicBaseUrl()}/orders/${cartId}/apply-promo`,
|
|
107
|
-
{
|
|
108
|
-
method: 'POST',
|
|
109
|
-
headers: {
|
|
110
|
-
'Content-Type': 'application/json',
|
|
111
|
-
},
|
|
112
|
-
body: JSON.stringify({ code }),
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
if (!response.ok) {
|
|
117
|
-
const errorData = await response.json().catch(() => ({}));
|
|
118
|
-
return {
|
|
119
|
-
success: false,
|
|
120
|
-
error: errorData.error || 'Failed to apply promo code',
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return { success: true };
|
|
125
|
-
} catch (error) {
|
|
126
|
-
logger.error('Error applying promo code:', error);
|
|
127
|
-
return { success: false, error: 'Network error applying code' };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Remove a promo code from a cart
|
|
133
|
-
*
|
|
134
|
-
* @param cartId - The cart UUID
|
|
135
|
-
* @returns Success status
|
|
136
|
-
*/
|
|
137
|
-
export async function removePromoCode(
|
|
138
|
-
cartId: string
|
|
139
|
-
): Promise<{ success: boolean; error?: string }> {
|
|
140
|
-
try {
|
|
141
|
-
const response = await fetch(
|
|
142
|
-
`${getPublicBaseUrl()}/orders/${cartId}/remove-promo`,
|
|
143
|
-
{
|
|
144
|
-
method: 'POST',
|
|
145
|
-
headers: {
|
|
146
|
-
'Content-Type': 'application/json',
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (!response.ok) {
|
|
152
|
-
const errorData = await response.json().catch(() => ({}));
|
|
153
|
-
return {
|
|
154
|
-
success: false,
|
|
155
|
-
error: errorData.error || 'Failed to remove promo code',
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return { success: true };
|
|
160
|
-
} catch (error) {
|
|
161
|
-
logger.error('Error removing promo code:', error);
|
|
162
|
-
return { success: false, error: 'Network error removing code' };
|
|
163
|
-
}
|
|
164
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Promo Codes API
|
|
3
|
+
*
|
|
4
|
+
* Functions for validating and checking promo codes
|
|
5
|
+
* in the public checkout flow.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
|
+
import { getPublicBaseUrl } from './client.js';
|
|
10
|
+
import type { PromoValidationResponse, HasPromoCodesResponse } from './types.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validate a promo code for an event
|
|
14
|
+
*
|
|
15
|
+
* Checks if a promo code is valid and returns its effects:
|
|
16
|
+
* - Discount amount and type
|
|
17
|
+
* - Hidden ticket reveal
|
|
18
|
+
*
|
|
19
|
+
* @param eventId - The event ID
|
|
20
|
+
* @param code - The promo code to validate
|
|
21
|
+
* @returns Validation result with discount info
|
|
22
|
+
*/
|
|
23
|
+
export async function validatePromoCode(
|
|
24
|
+
eventId: string | number,
|
|
25
|
+
code: string
|
|
26
|
+
): Promise<PromoValidationResponse> {
|
|
27
|
+
try {
|
|
28
|
+
if (!code || !code.trim()) {
|
|
29
|
+
return { valid: false, error: 'Promo code is required' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// API uses GET with code in URL path
|
|
33
|
+
const encodedCode = encodeURIComponent(code.trim());
|
|
34
|
+
const response = await fetch(
|
|
35
|
+
`${getPublicBaseUrl()}/promo-codes/validate/${eventId}/${encodedCode}`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
// 404 = invalid code, other errors are server issues
|
|
40
|
+
if (response.status === 404) {
|
|
41
|
+
return { valid: false, error: 'Invalid promo code' };
|
|
42
|
+
}
|
|
43
|
+
const errorData = await response.json().catch(() => ({}));
|
|
44
|
+
return { valid: false, error: errorData.error || 'Failed to validate code' };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result = await response.json();
|
|
48
|
+
return {
|
|
49
|
+
valid: result.valid ?? true,
|
|
50
|
+
revealHiddenTickets: result.revealHiddenTickets,
|
|
51
|
+
revealTicketIds: result.revealTicketIds,
|
|
52
|
+
provideDiscount: result.provideDiscount,
|
|
53
|
+
discountType: result.discountType,
|
|
54
|
+
amount: result.amount,
|
|
55
|
+
code: result.code || code,
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logger.error('Error validating promo code:', error);
|
|
59
|
+
return { valid: false, error: 'Network error validating code' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Check if promo codes are available for an event
|
|
65
|
+
*
|
|
66
|
+
* Used to conditionally show/hide the promo code input field.
|
|
67
|
+
*
|
|
68
|
+
* @param eventId - The event ID
|
|
69
|
+
* @returns Whether promo codes exist for this event
|
|
70
|
+
*/
|
|
71
|
+
export async function hasPromoCodes(eventId: string | number): Promise<boolean> {
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(
|
|
74
|
+
`${getPublicBaseUrl()}/promo-codes/check/${eventId}`
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
// If endpoint doesn't exist or errors, default to showing the input
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result: HasPromoCodesResponse = await response.json();
|
|
83
|
+
return result.hasPromoCodes === true;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
logger.error('Error checking promo codes availability:', error);
|
|
86
|
+
// Default to showing promo input if we can't check
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Apply a promo code to a cart
|
|
93
|
+
*
|
|
94
|
+
* This updates the cart with the promo code discount.
|
|
95
|
+
*
|
|
96
|
+
* @param cartId - The cart UUID
|
|
97
|
+
* @param code - The promo code to apply
|
|
98
|
+
* @returns Success status
|
|
99
|
+
*/
|
|
100
|
+
export async function applyPromoCode(
|
|
101
|
+
cartId: string,
|
|
102
|
+
code: string
|
|
103
|
+
): Promise<{ success: boolean; error?: string }> {
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetch(
|
|
106
|
+
`${getPublicBaseUrl()}/orders/${cartId}/apply-promo`,
|
|
107
|
+
{
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({ code }),
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
const errorData = await response.json().catch(() => ({}));
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
error: errorData.error || 'Failed to apply promo code',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { success: true };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
logger.error('Error applying promo code:', error);
|
|
127
|
+
return { success: false, error: 'Network error applying code' };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Remove a promo code from a cart
|
|
133
|
+
*
|
|
134
|
+
* @param cartId - The cart UUID
|
|
135
|
+
* @returns Success status
|
|
136
|
+
*/
|
|
137
|
+
export async function removePromoCode(
|
|
138
|
+
cartId: string
|
|
139
|
+
): Promise<{ success: boolean; error?: string }> {
|
|
140
|
+
try {
|
|
141
|
+
const response = await fetch(
|
|
142
|
+
`${getPublicBaseUrl()}/orders/${cartId}/remove-promo`,
|
|
143
|
+
{
|
|
144
|
+
method: 'POST',
|
|
145
|
+
headers: {
|
|
146
|
+
'Content-Type': 'application/json',
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
const errorData = await response.json().catch(() => ({}));
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
error: errorData.error || 'Failed to remove promo code',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return { success: true };
|
|
160
|
+
} catch (error) {
|
|
161
|
+
logger.error('Error removing promo code:', error);
|
|
162
|
+
return { success: false, error: 'Network error removing code' };
|
|
163
|
+
}
|
|
164
|
+
}
|