@debugged-development/ticketapp-sdk 0.0.3
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 +196 -0
- package/dist/graphql/generated.d.ts +4325 -0
- package/dist/graphql/generated.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3141 -0
- package/dist/services/basketService.d.ts +42 -0
- package/dist/services/basketService.d.ts.map +1 -0
- package/dist/services/eventService.d.ts +23 -0
- package/dist/services/eventService.d.ts.map +1 -0
- package/dist/services/paymentService.d.ts +17 -0
- package/dist/services/paymentService.d.ts.map +1 -0
- package/dist/store/basketSlice.d.ts +55 -0
- package/dist/store/basketSlice.d.ts.map +1 -0
- package/dist/store/eventSlice.d.ts +83 -0
- package/dist/store/eventSlice.d.ts.map +1 -0
- package/dist/store/store.d.ts +12 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/types/index.d.ts +202 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Basket Manager Usage Guide
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @your-scope/basket-manager luxon
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
You need to provide your GraphQL API client when initializing the BasketService:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { BasketService, store } from '@your-scope/basket-manager';
|
|
15
|
+
import { ApolloClient } from '@apollo/client';
|
|
16
|
+
|
|
17
|
+
// Your GraphQL mutations (from your generated types)
|
|
18
|
+
import {
|
|
19
|
+
useAddToOrderMutation,
|
|
20
|
+
useRemoveFromOrderMutation,
|
|
21
|
+
useConfigurePackageMutation,
|
|
22
|
+
useConfigureOrderDeliveryOptionMutation,
|
|
23
|
+
useCreateOrderCustomerMutation,
|
|
24
|
+
useDeleteOrderMutation,
|
|
25
|
+
} from './order-provider.generated';
|
|
26
|
+
|
|
27
|
+
// Create API client wrapper
|
|
28
|
+
const apiClient = {
|
|
29
|
+
addToOrder: async (variables) => {
|
|
30
|
+
const [mutate] = useAddToOrderMutation();
|
|
31
|
+
return await mutate({ variables });
|
|
32
|
+
},
|
|
33
|
+
removeFromOrder: async (variables) => {
|
|
34
|
+
const [mutate] = useRemoveFromOrderMutation();
|
|
35
|
+
return await mutate({ variables });
|
|
36
|
+
},
|
|
37
|
+
configurePackage: async (variables) => {
|
|
38
|
+
const [mutate] = useConfigurePackageMutation();
|
|
39
|
+
return await mutate({ variables });
|
|
40
|
+
},
|
|
41
|
+
configureDeliveryOption: async (variables) => {
|
|
42
|
+
const [mutate] = useConfigureOrderDeliveryOptionMutation();
|
|
43
|
+
return await mutate({ variables });
|
|
44
|
+
},
|
|
45
|
+
createCustomer: async (variables) => {
|
|
46
|
+
const [mutate] = useCreateOrderCustomerMutation();
|
|
47
|
+
return await mutate({ variables });
|
|
48
|
+
},
|
|
49
|
+
cancelOrder: async (variables) => {
|
|
50
|
+
const [mutate] = useDeleteOrderMutation();
|
|
51
|
+
return await mutate({ variables });
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Initialize the basket service
|
|
56
|
+
const basketService = new BasketService({
|
|
57
|
+
shopId: 'your-shop-id',
|
|
58
|
+
shopSlug: 'your-shop-slug',
|
|
59
|
+
apiClient,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage in React
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { useEffect, useState } from 'react';
|
|
67
|
+
import { store, Currency } from '@your-scope/basket-manager';
|
|
68
|
+
|
|
69
|
+
function MyComponent() {
|
|
70
|
+
const [order, setOrder] = useState(store.getState().basket.order);
|
|
71
|
+
|
|
72
|
+
// Subscribe to store changes
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const unsubscribe = store.subscribe(() => {
|
|
75
|
+
setOrder(store.getState().basket.order);
|
|
76
|
+
});
|
|
77
|
+
return unsubscribe;
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const handleAddProduct = async () => {
|
|
81
|
+
await basketService.addProduct({
|
|
82
|
+
id: 'product-123',
|
|
83
|
+
name: 'My Product',
|
|
84
|
+
price: 29.99,
|
|
85
|
+
currency: Currency.EUR,
|
|
86
|
+
amount: 1,
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<h1>Basket</h1>
|
|
93
|
+
{order && (
|
|
94
|
+
<div>
|
|
95
|
+
<p>Order ID: {order.id}</p>
|
|
96
|
+
<p>Items: {order.items.length}</p>
|
|
97
|
+
</div>
|
|
98
|
+
)}
|
|
99
|
+
<button onClick={handleAddProduct}>Add Product</button>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Usage in Vue
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { ref, onMounted, onUnmounted } from 'vue';
|
|
109
|
+
import { store, Currency } from '@your-scope/basket-manager';
|
|
110
|
+
|
|
111
|
+
export default {
|
|
112
|
+
setup() {
|
|
113
|
+
const order = ref(store.getState().basket.order);
|
|
114
|
+
let unsubscribe;
|
|
115
|
+
|
|
116
|
+
onMounted(() => {
|
|
117
|
+
unsubscribe = store.subscribe(() => {
|
|
118
|
+
order.value = store.getState().basket.order;
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
onUnmounted(() => {
|
|
123
|
+
if (unsubscribe) unsubscribe();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const handleAddProduct = async () => {
|
|
127
|
+
await basketService.addProduct({
|
|
128
|
+
id: 'product-123',
|
|
129
|
+
name: 'My Product',
|
|
130
|
+
price: 29.99,
|
|
131
|
+
currency: Currency.EUR,
|
|
132
|
+
amount: 1,
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return { order, handleAddProduct };
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Usage in Vanilla JS
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { store, basketService, Currency } from '@your-scope/basket-manager';
|
|
145
|
+
|
|
146
|
+
// Subscribe to changes
|
|
147
|
+
store.subscribe(() => {
|
|
148
|
+
const order = store.getState().basket.order;
|
|
149
|
+
console.log('Order updated:', order);
|
|
150
|
+
updateUI(order);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Add product
|
|
154
|
+
document.querySelector('#add-btn').addEventListener('click', async () => {
|
|
155
|
+
await basketService.addProduct({
|
|
156
|
+
id: 'product-123',
|
|
157
|
+
name: 'My Product',
|
|
158
|
+
price: 29.99,
|
|
159
|
+
currency: Currency.EUR,
|
|
160
|
+
amount: 1,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
function updateUI(order) {
|
|
165
|
+
const orderElement = document.querySelector('#order-display');
|
|
166
|
+
if (order) {
|
|
167
|
+
orderElement.innerHTML = `
|
|
168
|
+
<p>Order ID: ${order.id}</p>
|
|
169
|
+
<p>Items: ${order.items.length}</p>
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## API Methods
|
|
176
|
+
|
|
177
|
+
### `addProduct(input: ProductInput)`
|
|
178
|
+
Add a product to the basket.
|
|
179
|
+
|
|
180
|
+
### `removeProduct(input: ProductInput)`
|
|
181
|
+
Remove a product from the basket.
|
|
182
|
+
|
|
183
|
+
### `configurePackage(input: PackageInput)`
|
|
184
|
+
Configure a package in the basket.
|
|
185
|
+
|
|
186
|
+
### `configureDeliveryOption(input?: DeliveryInput)`
|
|
187
|
+
Set or remove delivery option.
|
|
188
|
+
|
|
189
|
+
### `createCustomer(input: CreateCustomerInput)`
|
|
190
|
+
Add customer information to the order.
|
|
191
|
+
|
|
192
|
+
### `cancelOrder()`
|
|
193
|
+
Cancel the current order.
|
|
194
|
+
|
|
195
|
+
### `clearOrderFromSession()`
|
|
196
|
+
Clear the order from session storage and state.
|