@instockng/api-client 1.0.25 → 1.0.27

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.
@@ -5,7 +5,7 @@
5
5
  * They can also be imported directly in Server Components.
6
6
  */
7
7
  import { createRpcClients } from '../rpc-client';
8
- import { API_BASE_URL } from '../provider';
8
+ const API_URL = 'https://oms-api.instock.com.ng';
9
9
  /**
10
10
  * Fetch brand configuration by slug
11
11
  *
@@ -13,7 +13,7 @@ import { API_BASE_URL } from '../provider';
13
13
  * @returns Brand with metaPixelId and other configuration
14
14
  */
15
15
  export async function fetchBrandBySlug(slug) {
16
- const clients = createRpcClients(API_BASE_URL);
16
+ const clients = createRpcClients(API_URL);
17
17
  const res = await clients.brands[':slug'].$get({
18
18
  param: { slug },
19
19
  });
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Cart fetcher functions
3
- *
4
3
  * These are the actual data-fetching functions used by hooks.
5
4
  * They can also be imported directly in Server Components.
6
5
  */
@@ -4992,6 +4991,23 @@ export declare function checkoutCart(cartId: string, checkoutData: {
4992
4991
  prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
4993
4992
  userActionToken: string;
4994
4993
  }>;
4994
+ /**
4995
+ * Initiate checkout tracking
4996
+ *
4997
+ * @param cartId - Cart UUID
4998
+ * @param data - Checking out user data and attribution cookies
4999
+ * @returns Success status
5000
+ */
5001
+ export declare function initiateCheckout(cartId: string, data: {
5002
+ email?: string | null;
5003
+ phone?: string | null;
5004
+ fbc?: string;
5005
+ fbp?: string;
5006
+ ttp?: string;
5007
+ ttclid?: string;
5008
+ }): Promise<{
5009
+ success: true;
5010
+ }>;
4995
5011
  /**
4996
5012
  * Fetch recommended products for a cart
4997
5013
  *
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * Cart fetcher functions
3
- *
4
3
  * These are the actual data-fetching functions used by hooks.
5
4
  * They can also be imported directly in Server Components.
6
5
  */
7
6
  import { createRpcClients } from '../rpc-client';
8
- import { API_BASE_URL } from '../provider';
7
+ const API_URL = 'https://oms-api.instock.com.ng';
9
8
  /**
10
9
  * Fetch a cart by ID
11
10
  *
@@ -13,7 +12,7 @@ import { API_BASE_URL } from '../provider';
13
12
  * @returns Cart with items, brand, and delivery zone
14
13
  */
15
14
  export async function fetchCart(cartId) {
16
- const clients = createRpcClients(API_BASE_URL);
15
+ const clients = createRpcClients(API_URL);
17
16
  const res = await clients.carts[':id'].$get({
18
17
  param: { id: cartId },
19
18
  });
@@ -29,7 +28,7 @@ export async function fetchCart(cartId) {
29
28
  * @returns Newly created cart
30
29
  */
31
30
  export async function createCart(brandSlug) {
32
- const clients = createRpcClients(API_BASE_URL);
31
+ const clients = createRpcClients(API_URL);
33
32
  const res = await clients.carts.index.$post({
34
33
  json: { brandSlug },
35
34
  });
@@ -46,7 +45,7 @@ export async function createCart(brandSlug) {
46
45
  * @returns Updated cart
47
46
  */
48
47
  export async function updateCart(cartId, data) {
49
- const clients = createRpcClients(API_BASE_URL);
48
+ const clients = createRpcClients(API_URL);
50
49
  const res = await clients.carts[':id'].$patch({
51
50
  param: { id: cartId },
52
51
  // @ts-expect-error - Hono RPC type inference issue
@@ -70,7 +69,7 @@ export async function updateCart(cartId, data) {
70
69
  * @returns Updated cart
71
70
  */
72
71
  export async function addCartItem(cartId, sku, quantity, fbc, fbp, ttp, ttclid) {
73
- const clients = createRpcClients(API_BASE_URL);
72
+ const clients = createRpcClients(API_URL);
74
73
  const res = await clients.carts[':id'].items.$post({
75
74
  param: { id: cartId },
76
75
  // @ts-expect-error - Hono RPC type inference issue
@@ -90,7 +89,7 @@ export async function addCartItem(cartId, sku, quantity, fbc, fbp, ttp, ttclid)
90
89
  * @returns Updated cart
91
90
  */
92
91
  export async function updateCartItem(cartId, itemId, quantity) {
93
- const clients = createRpcClients(API_BASE_URL);
92
+ const clients = createRpcClients(API_URL);
94
93
  const res = await clients.carts[':id'].items[':itemId'].$patch({
95
94
  param: { id: cartId, itemId },
96
95
  // @ts-expect-error - Hono RPC type inference issue
@@ -109,7 +108,7 @@ export async function updateCartItem(cartId, itemId, quantity) {
109
108
  * @returns Updated cart
110
109
  */
111
110
  export async function removeCartItem(cartId, itemId) {
112
- const clients = createRpcClients(API_BASE_URL);
111
+ const clients = createRpcClients(API_URL);
113
112
  const res = await clients.carts[':id'].items[':itemId'].$delete({
114
113
  param: { id: cartId, itemId },
115
114
  });
@@ -126,7 +125,7 @@ export async function removeCartItem(cartId, itemId) {
126
125
  * @returns Updated cart
127
126
  */
128
127
  export async function applyDiscount(cartId, code) {
129
- const clients = createRpcClients(API_BASE_URL);
128
+ const clients = createRpcClients(API_URL);
130
129
  const res = await clients.carts[':id']['apply-discount'].$post({
131
130
  param: { id: cartId },
132
131
  // @ts-expect-error - Hono RPC type inference issue
@@ -144,7 +143,7 @@ export async function applyDiscount(cartId, code) {
144
143
  * @returns Updated cart
145
144
  */
146
145
  export async function removeDiscount(cartId) {
147
- const clients = createRpcClients(API_BASE_URL);
146
+ const clients = createRpcClients(API_URL);
148
147
  const res = await clients.carts[':id']['remove-discount'].$post({
149
148
  param: { id: cartId },
150
149
  });
@@ -161,7 +160,7 @@ export async function removeDiscount(cartId) {
161
160
  * @returns Created order
162
161
  */
163
162
  export async function checkoutCart(cartId, checkoutData) {
164
- const clients = createRpcClients(API_BASE_URL);
163
+ const clients = createRpcClients(API_URL);
165
164
  const res = await clients.carts[':id'].checkout.$post({
166
165
  param: { id: cartId },
167
166
  // @ts-expect-error - Hono RPC type inference issue
@@ -172,6 +171,25 @@ export async function checkoutCart(cartId, checkoutData) {
172
171
  }
173
172
  return res.json();
174
173
  }
174
+ /**
175
+ * Initiate checkout tracking
176
+ *
177
+ * @param cartId - Cart UUID
178
+ * @param data - Checking out user data and attribution cookies
179
+ * @returns Success status
180
+ */
181
+ export async function initiateCheckout(cartId, data) {
182
+ const clients = createRpcClients(API_URL);
183
+ const res = await clients.carts[':id']['initiate-checkout'].$post({
184
+ param: { id: cartId },
185
+ // @ts-expect-error - Hono RPC type inference issue
186
+ json: data,
187
+ });
188
+ if (!res.ok) {
189
+ throw new Error(`Failed to initiate checkout intent: ${res.statusText}`);
190
+ }
191
+ return res.json();
192
+ }
175
193
  /**
176
194
  * Fetch recommended products for a cart
177
195
  *
@@ -180,7 +198,7 @@ export async function checkoutCart(cartId, checkoutData) {
180
198
  * @returns Array of recommended products from the same brand
181
199
  */
182
200
  export async function fetchCartRecommendations(cartId, limit) {
183
- const clients = createRpcClients(API_BASE_URL);
201
+ const clients = createRpcClients(API_URL);
184
202
  const res = await clients.carts[':id'].recommendations.$get({
185
203
  param: { id: cartId },
186
204
  // @ts-ignore - Hono RPC type inference issue with query parameters
@@ -5,7 +5,7 @@
5
5
  * They can also be imported directly in Server Components.
6
6
  */
7
7
  import { createRpcClients } from '../rpc-client';
8
- import { API_BASE_URL } from '../provider';
8
+ const API_URL = 'https://oms-api.instock.com.ng';
9
9
  /**
10
10
  * Fetch delivery zones
11
11
  *
@@ -13,7 +13,7 @@ import { API_BASE_URL } from '../provider';
13
13
  * @returns List of delivery zones with states
14
14
  */
15
15
  export async function fetchDeliveryZones(brandId) {
16
- const clients = createRpcClients(API_BASE_URL);
16
+ const clients = createRpcClients(API_URL);
17
17
  const res = await clients.deliveryZones.index.$get({
18
18
  query: brandId ? { brandId } : {},
19
19
  });
@@ -5,7 +5,7 @@
5
5
  * They can also be imported directly in Server Components.
6
6
  */
7
7
  import { createRpcClients } from '../rpc-client';
8
- import { API_BASE_URL } from '../provider';
8
+ const API_URL = 'https://oms-api.instock.com.ng';
9
9
  /**
10
10
  * Fetch an order by ID and token
11
11
  *
@@ -14,7 +14,7 @@ import { API_BASE_URL } from '../provider';
14
14
  * @returns Order with items, delivery zone, and brand
15
15
  */
16
16
  export async function fetchOrder(orderId, token) {
17
- const clients = createRpcClients(API_BASE_URL);
17
+ const clients = createRpcClients(API_URL);
18
18
  const res = await clients.orders[':id'][':token'].$get({
19
19
  param: { id: orderId, token },
20
20
  });
@@ -31,7 +31,7 @@ export async function fetchOrder(orderId, token) {
31
31
  * @returns Confirmed order
32
32
  */
33
33
  export async function confirmOrder(orderId, token) {
34
- const clients = createRpcClients(API_BASE_URL);
34
+ const clients = createRpcClients(API_URL);
35
35
  const res = await clients.orders.confirm.$post({
36
36
  json: { orderId, token },
37
37
  });
@@ -49,7 +49,7 @@ export async function confirmOrder(orderId, token) {
49
49
  * @returns Array of recommended products
50
50
  */
51
51
  export async function fetchOrderRecommendations(orderId, token, limit = 4) {
52
- const clients = createRpcClients(API_BASE_URL);
52
+ const clients = createRpcClients(API_URL);
53
53
  const res = await clients.orders[':id'][':token'].recommendations.$get({
54
54
  param: { id: orderId, token },
55
55
  // @ts-ignore - Hono RPC type inference issue with query parameters
@@ -5,7 +5,7 @@
5
5
  * They can also be imported directly in Server Components.
6
6
  */
7
7
  import { createRpcClients } from '../rpc-client';
8
- import { API_BASE_URL } from '../provider';
8
+ const API_URL = 'https://oms-api.instock.com.ng';
9
9
  /**
10
10
  * Fetch products by brand ID
11
11
  *
@@ -13,7 +13,7 @@ import { API_BASE_URL } from '../provider';
13
13
  * @returns Products for the brand with variants and availability
14
14
  */
15
15
  export async function fetchProductsByBrand(brandId) {
16
- const clients = createRpcClients(API_BASE_URL);
16
+ const clients = createRpcClients(API_URL);
17
17
  const res = await clients.products[':brandId'].$get({
18
18
  param: { brandId },
19
19
  });
@@ -29,7 +29,7 @@ export async function fetchProductsByBrand(brandId) {
29
29
  * @returns Product with variants and availability
30
30
  */
31
31
  export async function fetchProductBySlug(slug) {
32
- const clients = createRpcClients(API_BASE_URL);
32
+ const clients = createRpcClients(API_URL);
33
33
  const res = await clients.products.product[':slug'].$get({
34
34
  param: { slug },
35
35
  });
@@ -46,7 +46,7 @@ export async function fetchProductBySlug(slug) {
46
46
  * @returns List of add-on products
47
47
  */
48
48
  export async function fetchProductAddons(slug, limit) {
49
- const clients = createRpcClients(API_BASE_URL);
49
+ const clients = createRpcClients(API_URL);
50
50
  const res = await clients.productAddons[':slug'].$get({
51
51
  param: { slug },
52
52
  query: limit !== undefined ? { limit: String(limit) } : {},
@@ -5,7 +5,7 @@
5
5
  * providing end-to-end type safety without code generation.
6
6
  */
7
7
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
8
- import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, fetchCartRecommendations } from '../../fetchers/carts';
8
+ import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, initiateCheckout, fetchCartRecommendations } from '../../fetchers/carts';
9
9
  /**
10
10
  * Hook to get cart by ID using RPC
11
11
  *
@@ -5068,6 +5068,28 @@ export declare function useCheckoutCart(cartId: string, options?: UseMutationOpt
5068
5068
  ttp?: string;
5069
5069
  ttclid?: string;
5070
5070
  }, unknown>;
5071
+ /**
5072
+ * Hook to initiate checkout tracking using RPC
5073
+ *
5074
+ * @param cartId - Cart UUID
5075
+ * @param options - React Query mutation options
5076
+ *
5077
+ * @example
5078
+ * ```tsx
5079
+ * const initiateCheckout = useInitiateCheckout('cart-123');
5080
+ * initiateCheckout.mutate({ email: 'user@example.com' });
5081
+ * ```
5082
+ */
5083
+ export declare function useInitiateCheckout(cartId: string, options?: UseMutationOptions<Awaited<ReturnType<typeof initiateCheckout>>, Error, Parameters<typeof initiateCheckout>[1]>): import("@tanstack/react-query").UseMutationResult<{
5084
+ success: true;
5085
+ }, Error, {
5086
+ email?: string | null;
5087
+ phone?: string | null;
5088
+ fbc?: string;
5089
+ fbp?: string;
5090
+ ttp?: string;
5091
+ ttclid?: string;
5092
+ }, unknown>;
5071
5093
  /**
5072
5094
  * Hook to get recommended products for a cart using RPC
5073
5095
  *
@@ -7,7 +7,7 @@
7
7
  import { useMutation, useQueryClient } from '@tanstack/react-query';
8
8
  import { useQueryUnwrapped } from '../use-query-unwrapped';
9
9
  import { queryKeys } from '../../utils/query-keys';
10
- import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, fetchCartRecommendations, } from '../../fetchers/carts';
10
+ import { fetchCart, updateCart, createCart, addCartItem, updateCartItem, removeCartItem, applyDiscount, removeDiscount, checkoutCart, initiateCheckout, fetchCartRecommendations, } from '../../fetchers/carts';
11
11
  /**
12
12
  * Hook to get cart by ID using RPC
13
13
  *
@@ -217,6 +217,24 @@ export function useCheckoutCart(cartId, options) {
217
217
  ...options,
218
218
  });
219
219
  }
220
+ /**
221
+ * Hook to initiate checkout tracking using RPC
222
+ *
223
+ * @param cartId - Cart UUID
224
+ * @param options - React Query mutation options
225
+ *
226
+ * @example
227
+ * ```tsx
228
+ * const initiateCheckout = useInitiateCheckout('cart-123');
229
+ * initiateCheckout.mutate({ email: 'user@example.com' });
230
+ * ```
231
+ */
232
+ export function useInitiateCheckout(cartId, options) {
233
+ return useMutation({
234
+ mutationFn: (data) => initiateCheckout(cartId, data),
235
+ ...options,
236
+ });
237
+ }
220
238
  /**
221
239
  * Hook to get recommended products for a cart using RPC
222
240
  *
@@ -4,7 +4,7 @@
4
4
  * Export all RPC hooks for use in applications
5
5
  */
6
6
  export * from './carts';
7
- export * from './orders';
7
+ export * from './brands';
8
8
  export * from './products';
9
+ export * from './orders';
9
10
  export * from './delivery-zones';
10
- export * from './brands';
@@ -4,7 +4,7 @@
4
4
  * Export all RPC hooks for use in applications
5
5
  */
6
6
  export * from './carts';
7
- export * from './orders';
7
+ export * from './brands';
8
8
  export * from './products';
9
+ export * from './orders';
9
10
  export * from './delivery-zones';
10
- export * from './brands';
@@ -16,7 +16,6 @@ export interface ApiClientProviderProps {
16
16
  onError?: (error: AxiosError) => void;
17
17
  queryClient?: QueryClient;
18
18
  }
19
- export declare const API_BASE_URL = "https://oms-api.instock.com.ng";
20
19
  /**
21
20
  * Provider component that initializes the API client and React Query
22
21
  *
package/dist/provider.js CHANGED
@@ -6,7 +6,6 @@ import { createContext, useContext, useEffect, useMemo } from 'react';
6
6
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
7
7
  import { initializeApiClient } from './client';
8
8
  const ApiClientContext = createContext(null);
9
- export const API_BASE_URL = 'https://oms-api.instock.com.ng';
10
9
  /**
11
10
  * Provider component that initializes the API client and React Query
12
11
  *
@@ -19,7 +18,7 @@ export const API_BASE_URL = 'https://oms-api.instock.com.ng';
19
18
  * </ApiClientProvider>
20
19
  * ```
21
20
  */
22
- export function ApiClientProvider({ children, baseURL = API_BASE_URL, getAuthToken, onError, queryClient: externalQueryClient }) {
21
+ export function ApiClientProvider({ children, baseURL = 'https://oms-api.instock.com.ng', getAuthToken, onError, queryClient: externalQueryClient }) {
23
22
  // Initialize client synchronously on first render
24
23
  const config = {
25
24
  baseURL,
@@ -4696,6 +4696,51 @@ export declare function createRpcClients(baseURL: string): {
4696
4696
  }>;
4697
4697
  };
4698
4698
  };
4699
+ } & {
4700
+ ":id": {
4701
+ "initiate-checkout": import("hono/client").ClientRequest<{
4702
+ $post: {
4703
+ input: {
4704
+ param: {
4705
+ id: string;
4706
+ };
4707
+ };
4708
+ output: {
4709
+ error: {
4710
+ code: string;
4711
+ message: string;
4712
+ };
4713
+ };
4714
+ outputFormat: "json";
4715
+ status: 404;
4716
+ } | {
4717
+ input: {
4718
+ param: {
4719
+ id: string;
4720
+ };
4721
+ };
4722
+ output: {
4723
+ success: true;
4724
+ };
4725
+ outputFormat: "json";
4726
+ status: 200;
4727
+ } | {
4728
+ input: {
4729
+ param: {
4730
+ id: string;
4731
+ };
4732
+ };
4733
+ output: {
4734
+ error: {
4735
+ code: string;
4736
+ message: any;
4737
+ };
4738
+ };
4739
+ outputFormat: "json";
4740
+ status: 500;
4741
+ };
4742
+ }>;
4743
+ };
4699
4744
  } & {
4700
4745
  ":id": {
4701
4746
  checkout: import("hono/client").ClientRequest<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instockng/api-client",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "React Query hooks for OMS API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",