@instockng/api-client 1.0.39 → 1.0.41

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.
@@ -128,19 +128,17 @@ export function useRemoveDiscount(cartId, options) {
128
128
  export function useAddCartItem(cartId, options) {
129
129
  const queryClient = useQueryClient();
130
130
  return useMutation({
131
+ ...options,
131
132
  mutationFn: (data) => addCartItem(cartId, data.sku, data.quantity, data.fbc, data.fbp, data.ttp, data.ttclid, data.fromUpsell, data.upsellDiscountPercent),
132
- onSuccess: (_, variables) => {
133
+ onSuccess: (...args) => {
134
+ const [, variables] = args;
133
135
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
134
- // Refresh recommendations only if cart is not visible (refreshRecommendations flag is true)
135
136
  if (variables.refreshRecommendations) {
136
137
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.recommendations(cartId) });
137
138
  }
138
- // Refresh upsell addons when item is added from upsell
139
- if (variables.fromUpsell) {
140
- queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.upsellAddons(cartId) });
141
- }
139
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.upsellAddons(cartId) });
140
+ options?.onSuccess?.(...args);
142
141
  },
143
- ...options,
144
142
  });
145
143
  }
146
144
  /**
@@ -158,11 +156,13 @@ export function useAddCartItem(cartId, options) {
158
156
  export function useUpdateCartItem(cartId, options) {
159
157
  const queryClient = useQueryClient();
160
158
  return useMutation({
159
+ ...options,
161
160
  mutationFn: ({ itemId, quantity }) => updateCartItem(cartId, itemId, quantity),
162
- onSuccess: () => {
161
+ onSuccess: (...args) => {
163
162
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
163
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.upsellAddons(cartId) });
164
+ options?.onSuccess?.(...args);
164
165
  },
165
- ...options,
166
166
  });
167
167
  }
168
168
  /**
@@ -180,13 +180,14 @@ export function useUpdateCartItem(cartId, options) {
180
180
  export function useRemoveCartItem(cartId, options) {
181
181
  const queryClient = useQueryClient();
182
182
  return useMutation({
183
+ ...options,
183
184
  mutationFn: (itemId) => removeCartItem(cartId, itemId),
184
- onSuccess: () => {
185
+ onSuccess: (...args) => {
185
186
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.detail(cartId) });
186
- // Refresh recommendations when item is removed
187
187
  queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.recommendations(cartId) });
188
+ queryClient.invalidateQueries({ queryKey: queryKeys.public.carts.upsellAddons(cartId) });
189
+ options?.onSuccess?.(...args);
188
190
  },
189
- ...options,
190
191
  });
191
192
  }
192
193
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instockng/api-client",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "React Query hooks for OMS API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,13 @@
22
22
  "dist",
23
23
  "README.md"
24
24
  ],
25
+ "scripts": {
26
+ "type-check": "tsc --noEmit",
27
+ "build": "tsc --project tsconfig.build.json --noEmitOnError false && node scripts/fix-dist.mjs",
28
+ "generate-types": "node scripts/generate-backend-types.mjs",
29
+ "prebuild": "pnpm run generate-types",
30
+ "prepublishOnly": "pnpm run build"
31
+ },
25
32
  "keywords": [
26
33
  "api",
27
34
  "react-query",
@@ -45,11 +52,5 @@
45
52
  "axios": "^1.6.5",
46
53
  "react": "^19.0.0",
47
54
  "typescript": "^5.3.3"
48
- },
49
- "scripts": {
50
- "type-check": "tsc --noEmit",
51
- "build": "tsc --project tsconfig.build.json --noEmitOnError false && node scripts/fix-dist.mjs",
52
- "generate-types": "node scripts/generate-backend-types.mjs",
53
- "prebuild": "pnpm run generate-types"
54
55
  }
55
- }
56
+ }