@arraypress/waveform-bar 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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module actions
3
+ * @description Action button handlers (favorite, cart) for WaveformBar
4
+ */
5
+
6
+ /**
7
+ * Fire an action to an endpoint or callback
8
+ * @param {Object} actionConfig - { endpoint, method, headers }
9
+ * @param {Object} payload - Data to send
10
+ */
11
+ export function fireAction(actionConfig, payload) {
12
+ if (!actionConfig || !actionConfig.endpoint) return;
13
+
14
+ // Callback function
15
+ if (typeof actionConfig.endpoint === 'function') {
16
+ try {
17
+ actionConfig.endpoint(payload);
18
+ } catch (err) {
19
+ console.warn('WaveformBar action callback error:', err);
20
+ }
21
+ return;
22
+ }
23
+
24
+ // REST endpoint
25
+ if (typeof actionConfig.endpoint === 'string') {
26
+ fetch(actionConfig.endpoint, {
27
+ method: actionConfig.method || 'POST',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ ...(actionConfig.headers || {})
31
+ },
32
+ body: JSON.stringify(payload)
33
+ }).catch(err => console.warn('WaveformBar action request failed:', err));
34
+ }
35
+ }