@classytic/commerce-sdk 0.1.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.
Potentially problematic release.
This version of @classytic/commerce-sdk might be problematic. Click here for more details.
- package/LICENSE +14 -0
- package/README.md +104 -0
- package/dist/adjustment-DTSLM7AN.js +5 -0
- package/dist/adjustment-DTSLM7AN.js.map +1 -0
- package/dist/analytics/index.d.ts +27 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics-DMcD-o8w.d.ts +76 -0
- package/dist/api-factory-B_h4RKBm.d.ts +280 -0
- package/dist/auth/index.d.ts +39 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/catalog/index.d.ts +479 -0
- package/dist/catalog/index.js +9 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/chunk-4ZQK3FFN.js +40 -0
- package/dist/chunk-4ZQK3FFN.js.map +1 -0
- package/dist/chunk-5L6EXDGH.js +465 -0
- package/dist/chunk-5L6EXDGH.js.map +1 -0
- package/dist/chunk-5ZFW3FEI.js +183 -0
- package/dist/chunk-5ZFW3FEI.js.map +1 -0
- package/dist/chunk-66OQAZSL.js +94 -0
- package/dist/chunk-66OQAZSL.js.map +1 -0
- package/dist/chunk-6RYGA6MF.js +123 -0
- package/dist/chunk-6RYGA6MF.js.map +1 -0
- package/dist/chunk-B6MPVOV7.js +328 -0
- package/dist/chunk-B6MPVOV7.js.map +1 -0
- package/dist/chunk-BDA2WSJA.js +148 -0
- package/dist/chunk-BDA2WSJA.js.map +1 -0
- package/dist/chunk-EIVYT3HM.js +126 -0
- package/dist/chunk-EIVYT3HM.js.map +1 -0
- package/dist/chunk-EPQN7ZKZ.js +27 -0
- package/dist/chunk-EPQN7ZKZ.js.map +1 -0
- package/dist/chunk-FA7QFJ2G.js +177 -0
- package/dist/chunk-FA7QFJ2G.js.map +1 -0
- package/dist/chunk-I5TIKUIQ.js +261 -0
- package/dist/chunk-I5TIKUIQ.js.map +1 -0
- package/dist/chunk-ILQUH444.js +135 -0
- package/dist/chunk-ILQUH444.js.map +1 -0
- package/dist/chunk-IXMWZJLV.js +616 -0
- package/dist/chunk-IXMWZJLV.js.map +1 -0
- package/dist/chunk-KZIGRIQG.js +75 -0
- package/dist/chunk-KZIGRIQG.js.map +1 -0
- package/dist/chunk-OF5M6R2S.js +769 -0
- package/dist/chunk-OF5M6R2S.js.map +1 -0
- package/dist/chunk-PYYLHUV6.js +3 -0
- package/dist/chunk-PYYLHUV6.js.map +1 -0
- package/dist/chunk-QO5AGZFP.js +159 -0
- package/dist/chunk-QO5AGZFP.js.map +1 -0
- package/dist/chunk-QUMTBLNE.js +76 -0
- package/dist/chunk-QUMTBLNE.js.map +1 -0
- package/dist/chunk-R5Z7NYLH.js +126 -0
- package/dist/chunk-R5Z7NYLH.js.map +1 -0
- package/dist/chunk-SZYWG5IB.js +75 -0
- package/dist/chunk-SZYWG5IB.js.map +1 -0
- package/dist/chunk-U3XT35GZ.js +202 -0
- package/dist/chunk-U3XT35GZ.js.map +1 -0
- package/dist/chunk-UGELTUIZ.js +830 -0
- package/dist/chunk-UGELTUIZ.js.map +1 -0
- package/dist/chunk-VR36QVX2.js +122 -0
- package/dist/chunk-VR36QVX2.js.map +1 -0
- package/dist/chunk-WUOQK7BO.js +13 -0
- package/dist/chunk-WUOQK7BO.js.map +1 -0
- package/dist/chunk-X6PV5MHG.js +582 -0
- package/dist/chunk-X6PV5MHG.js.map +1 -0
- package/dist/chunk-ZWLMFLLH.js +534 -0
- package/dist/chunk-ZWLMFLLH.js.map +1 -0
- package/dist/content/index.d.ts +309 -0
- package/dist/content/index.js +6 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.d.ts +107 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/react.d.ts +107 -0
- package/dist/core/react.js +5 -0
- package/dist/core/react.js.map +1 -0
- package/dist/coupon-CHFcw7cd.d.ts +632 -0
- package/dist/coupon-zGkvO-Xx.d.ts +129 -0
- package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
- package/dist/finance/index.d.ts +81 -0
- package/dist/finance/index.js +5 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance-BJdfKRw0.d.ts +135 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory/index.d.ts +512 -0
- package/dist/inventory/index.js +16 -0
- package/dist/inventory/index.js.map +1 -0
- package/dist/inventory-DCiIZh8P.d.ts +742 -0
- package/dist/logistics/index.d.ts +226 -0
- package/dist/logistics/index.js +7 -0
- package/dist/logistics/index.js.map +1 -0
- package/dist/logistics-V8a9lUN3.d.ts +428 -0
- package/dist/media-CNLJK93J.d.ts +721 -0
- package/dist/movement-7MV3ADY5.js +5 -0
- package/dist/movement-7MV3ADY5.js.map +1 -0
- package/dist/payment-BRboLqvU.d.ts +127 -0
- package/dist/payments/index.d.ts +55 -0
- package/dist/payments/index.js +6 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/platform/index.d.ts +645 -0
- package/dist/platform/index.js +8 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/pos-D1jkkFl0.d.ts +885 -0
- package/dist/product-p09zXkXB.d.ts +260 -0
- package/dist/purchase-24BGT2HA.js +5 -0
- package/dist/purchase-24BGT2HA.js.map +1 -0
- package/dist/request-652PS6VR.js +5 -0
- package/dist/request-652PS6VR.js.map +1 -0
- package/dist/sales/index.d.ts +585 -0
- package/dist/sales/index.js +9 -0
- package/dist/sales/index.js.map +1 -0
- package/dist/server.d.ts +120 -0
- package/dist/server.js +27 -0
- package/dist/server.js.map +1 -0
- package/dist/size-guide-DgjzjM5P.d.ts +554 -0
- package/dist/stock-DEApGC-w.d.ts +632 -0
- package/dist/stock-OOUW57VQ.js +5 -0
- package/dist/stock-OOUW57VQ.js.map +1 -0
- package/dist/supplier-OC6JAWV6.js +5 -0
- package/dist/supplier-OC6JAWV6.js.map +1 -0
- package/dist/transaction/index.d.ts +104 -0
- package/dist/transaction/index.js +8 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction-BTmoHpWh.d.ts +428 -0
- package/dist/transaction-u5oaNuav.d.ts +84 -0
- package/dist/transfer-7SYSH3RG.js +5 -0
- package/dist/transfer-7SYSH3RG.js.map +1 -0
- package/dist/user-data-DdLjAGwO.d.ts +132 -0
- package/package.json +146 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) Classytic. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the
|
|
4
|
+
proprietary and confidential property of Classytic. No part of the Software
|
|
5
|
+
may be used, copied, modified, merged, published, distributed, sublicensed,
|
|
6
|
+
or sold without prior written permission from Classytic.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
9
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
10
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
11
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
12
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
13
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
14
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @classytic/commerce-sdk
|
|
2
|
+
|
|
3
|
+
Modular API client and React hooks for the Classytic commerce platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @classytic/commerce-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- React 19+
|
|
14
|
+
- Optional: Next.js 14+ for app/router usage
|
|
15
|
+
- Optional: @tanstack/react-query 5+ for hooks
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { initCommerceSDK } from '@classytic/commerce-sdk';
|
|
21
|
+
|
|
22
|
+
// Initialize once at app startup
|
|
23
|
+
initCommerceSDK({ baseUrl: process.env.NEXT_PUBLIC_API_URL! });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Modules
|
|
27
|
+
|
|
28
|
+
Import what you need from domain-specific modules:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// Catalog (products, categories, size guides)
|
|
32
|
+
import { productApi, useProducts, useProductDetail } from '@classytic/commerce-sdk/catalog';
|
|
33
|
+
|
|
34
|
+
// Sales (orders, customers, cart, POS, transactions)
|
|
35
|
+
import { orderApi, useOrders, useCart } from '@classytic/commerce-sdk/sales';
|
|
36
|
+
|
|
37
|
+
// Inventory (stock, purchases, transfers, suppliers)
|
|
38
|
+
import { stockApi, useInventory, useTransfers } from '@classytic/commerce-sdk/inventory';
|
|
39
|
+
|
|
40
|
+
// Platform (branches, users, coupons, config)
|
|
41
|
+
import { branchApi, useBranches, usePlatformConfig } from '@classytic/commerce-sdk/platform';
|
|
42
|
+
|
|
43
|
+
// Auth (login, register, password reset)
|
|
44
|
+
import { loginApi, UserRole, verifyManagerAuth } from '@classytic/commerce-sdk/auth';
|
|
45
|
+
|
|
46
|
+
// Finance, Logistics, Content, Payments, Analytics
|
|
47
|
+
import { useFinanceSummary } from '@classytic/commerce-sdk/finance';
|
|
48
|
+
import { useDeliveryCharge } from '@classytic/commerce-sdk/logistics';
|
|
49
|
+
import { mediaApi, useCMSPage } from '@classytic/commerce-sdk/content';
|
|
50
|
+
import { usePaymentActions } from '@classytic/commerce-sdk/payments';
|
|
51
|
+
import { useAnalyticsDashboard } from '@classytic/commerce-sdk/analytics';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage Patterns
|
|
55
|
+
|
|
56
|
+
### Server Components / API Routes
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { productApi } from '@classytic/commerce-sdk/catalog';
|
|
60
|
+
|
|
61
|
+
// Fetch data server-side
|
|
62
|
+
const products = await productApi.getAll({ params: { page: 1 } });
|
|
63
|
+
const product = await productApi.getBySlug({ slug: 'my-product' });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Client Components (React Query hooks)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { useProducts, useProductActions } from '@classytic/commerce-sdk/catalog';
|
|
70
|
+
|
|
71
|
+
function ProductList({ token }) {
|
|
72
|
+
const { items, isLoading } = useProducts(token, { page: 1 });
|
|
73
|
+
const { create, update, remove } = useProductActions(token);
|
|
74
|
+
|
|
75
|
+
// ...
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Core Utilities
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { handleApiRequest, BaseApi } from '@classytic/commerce-sdk/core';
|
|
83
|
+
|
|
84
|
+
// Make custom API calls
|
|
85
|
+
const data = await handleApiRequest('POST', '/api/v1/custom', {
|
|
86
|
+
token,
|
|
87
|
+
body: { ... }
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Types
|
|
92
|
+
|
|
93
|
+
All types are co-located with their modules:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import type { Product, Category } from '@classytic/commerce-sdk/catalog';
|
|
97
|
+
import type { Order, Customer } from '@classytic/commerce-sdk/sales';
|
|
98
|
+
import type { StockEntry, Transfer } from '@classytic/commerce-sdk/inventory';
|
|
99
|
+
import type { User, UserRoleType } from '@classytic/commerce-sdk/auth';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
Proprietary - see `LICENSE`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"adjustment-DTSLM7AN.js"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { g as AnalyticsDashboardParams, f as AnalyticsDashboard } from '../analytics-DMcD-o8w.js';
|
|
2
|
+
export { A as AnalyticsApi, b as AnalyticsPeriod, c as AnalyticsSummary, d as AnalyticsTrend, e as TopCategory, T as TopProduct, a as analyticsApi } from '../analytics-DMcD-o8w.js';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import '../api-factory-B_h4RKBm.js';
|
|
5
|
+
|
|
6
|
+
declare const ANALYTICS_KEYS: {
|
|
7
|
+
all: readonly ["analytics"];
|
|
8
|
+
dashboard: (period?: string) => readonly ["analytics", "dashboard", string | undefined];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Hook to fetch dashboard analytics data
|
|
12
|
+
*
|
|
13
|
+
* @param token - Auth token (required)
|
|
14
|
+
* @param params.period - Time period: '7d' | '30d' | '90d' | '1y' (default: '30d')
|
|
15
|
+
* @param params.branchId - Optional branch filter
|
|
16
|
+
* @param options.enabled - Enable/disable query (default: true)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { data, isLoading } = useAnalyticsDashboard(token, { period: '30d' });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function useAnalyticsDashboard(token: string, params?: AnalyticsDashboardParams, options?: {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
}): _tanstack_react_query.UseQueryResult<AnalyticsDashboard, Error>;
|
|
26
|
+
|
|
27
|
+
export { ANALYTICS_KEYS, AnalyticsDashboard, AnalyticsDashboardParams, useAnalyticsDashboard };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { R as RequestOptions, A as ApiResponse } from './api-factory-B_h4RKBm.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analytics Types
|
|
5
|
+
*/
|
|
6
|
+
interface AnalyticsPeriod {
|
|
7
|
+
period: "7d" | "30d" | "90d" | "1y";
|
|
8
|
+
}
|
|
9
|
+
interface AnalyticsSummary {
|
|
10
|
+
totalRevenue: number;
|
|
11
|
+
totalOrders: number;
|
|
12
|
+
averageOrderValue: number;
|
|
13
|
+
conversionRate?: number;
|
|
14
|
+
}
|
|
15
|
+
interface AnalyticsTrend {
|
|
16
|
+
date: string;
|
|
17
|
+
revenue: number;
|
|
18
|
+
orders: number;
|
|
19
|
+
}
|
|
20
|
+
interface TopProduct {
|
|
21
|
+
productId: string;
|
|
22
|
+
name: string;
|
|
23
|
+
quantity: number;
|
|
24
|
+
revenue: number;
|
|
25
|
+
}
|
|
26
|
+
interface TopCategory {
|
|
27
|
+
categoryId: string;
|
|
28
|
+
name: string;
|
|
29
|
+
quantity: number;
|
|
30
|
+
revenue: number;
|
|
31
|
+
}
|
|
32
|
+
interface AnalyticsDashboard {
|
|
33
|
+
summary: AnalyticsSummary;
|
|
34
|
+
trends?: AnalyticsTrend[];
|
|
35
|
+
topProducts?: TopProduct[];
|
|
36
|
+
topCategories?: TopCategory[];
|
|
37
|
+
period: string;
|
|
38
|
+
startDate: string;
|
|
39
|
+
endDate: string;
|
|
40
|
+
}
|
|
41
|
+
interface AnalyticsDashboardParams {
|
|
42
|
+
period?: "7d" | "30d" | "90d" | "1y";
|
|
43
|
+
branchId?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Analytics API - Dashboard and reporting
|
|
48
|
+
*
|
|
49
|
+
* Endpoints:
|
|
50
|
+
* - getDashboard({ token, params }) - Get dashboard analytics
|
|
51
|
+
*
|
|
52
|
+
* Roles:
|
|
53
|
+
* - admin, superadmin, finance-admin, finance-manager
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
type FetchOptions = Omit<RequestOptions, "token" | "organizationId">;
|
|
57
|
+
declare class AnalyticsApi {
|
|
58
|
+
private baseUrl;
|
|
59
|
+
constructor();
|
|
60
|
+
/**
|
|
61
|
+
* Get dashboard analytics
|
|
62
|
+
* GET /analytics/dashboard
|
|
63
|
+
*
|
|
64
|
+
* @param token - Auth token (required)
|
|
65
|
+
* @param params.period - Time period: '7d', '30d', '90d', '1y' (default: '30d')
|
|
66
|
+
* @param params.branchId - Optional branch filter
|
|
67
|
+
*/
|
|
68
|
+
getDashboard({ token, params, options, }: {
|
|
69
|
+
token: string;
|
|
70
|
+
params?: AnalyticsDashboardParams;
|
|
71
|
+
options?: FetchOptions;
|
|
72
|
+
}): Promise<ApiResponse<AnalyticsDashboard>>;
|
|
73
|
+
}
|
|
74
|
+
declare const analyticsApi: AnalyticsApi;
|
|
75
|
+
|
|
76
|
+
export { AnalyticsApi as A, type TopProduct as T, analyticsApi as a, type AnalyticsPeriod as b, type AnalyticsSummary as c, type AnalyticsTrend as d, type TopCategory as e, type AnalyticsDashboard as f, type AnalyticsDashboardParams as g };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @classytic/commerce-sdk - API Factory
|
|
3
|
+
*
|
|
4
|
+
* Base API class that provides standardized CRUD operations.
|
|
5
|
+
* Supports direct field queries and bracket syntax: field[operator]=value
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base API response wrapper
|
|
9
|
+
* All endpoints return { success: boolean, ... }
|
|
10
|
+
*/
|
|
11
|
+
interface ApiResponse<T = unknown> {
|
|
12
|
+
success: boolean;
|
|
13
|
+
data?: T;
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Offset pagination response (page-based)
|
|
18
|
+
* Used when: ?page=1&limit=10
|
|
19
|
+
*/
|
|
20
|
+
interface OffsetPaginationResponse<T = unknown> {
|
|
21
|
+
success: boolean;
|
|
22
|
+
method: "offset";
|
|
23
|
+
docs: T[];
|
|
24
|
+
page: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
total: number;
|
|
27
|
+
pages: number;
|
|
28
|
+
hasNext: boolean;
|
|
29
|
+
hasPrev: boolean;
|
|
30
|
+
warning?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Keyset pagination response (cursor-based)
|
|
34
|
+
* Used when: ?after=cursor&limit=10
|
|
35
|
+
*/
|
|
36
|
+
interface KeysetPaginationResponse<T = unknown> {
|
|
37
|
+
success: boolean;
|
|
38
|
+
method: "keyset";
|
|
39
|
+
docs: T[];
|
|
40
|
+
limit: number;
|
|
41
|
+
hasMore: boolean;
|
|
42
|
+
next: string | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Aggregate pagination response
|
|
46
|
+
* Used for complex aggregation queries
|
|
47
|
+
*/
|
|
48
|
+
interface AggregatePaginationResponse<T = unknown> {
|
|
49
|
+
success: boolean;
|
|
50
|
+
method: "aggregate";
|
|
51
|
+
docs: T[];
|
|
52
|
+
page: number;
|
|
53
|
+
limit: number;
|
|
54
|
+
total: number;
|
|
55
|
+
pages: number;
|
|
56
|
+
hasNext: boolean;
|
|
57
|
+
hasPrev: boolean;
|
|
58
|
+
warning?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Union type for all paginated responses
|
|
62
|
+
*/
|
|
63
|
+
type PaginatedResponse<T = unknown> = OffsetPaginationResponse<T> | KeysetPaginationResponse<T> | AggregatePaginationResponse<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Delete operation response
|
|
66
|
+
* Supports both soft delete (default) and hard delete
|
|
67
|
+
*/
|
|
68
|
+
interface DeleteResponse {
|
|
69
|
+
success: boolean;
|
|
70
|
+
deleted: boolean;
|
|
71
|
+
/** ID of the deleted record */
|
|
72
|
+
id?: string;
|
|
73
|
+
/** @deprecated Use `id` instead */
|
|
74
|
+
productId?: string;
|
|
75
|
+
/** True if soft delete was performed (default behavior) */
|
|
76
|
+
soft?: boolean;
|
|
77
|
+
/** Legacy message field */
|
|
78
|
+
message?: string;
|
|
79
|
+
/** Number of records deleted (for bulk operations) */
|
|
80
|
+
count?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sort direction
|
|
84
|
+
*/
|
|
85
|
+
type SortDirection = 1 | -1 | "asc" | "desc";
|
|
86
|
+
/**
|
|
87
|
+
* Sort specification
|
|
88
|
+
*/
|
|
89
|
+
type SortSpec = Record<string, SortDirection> | string;
|
|
90
|
+
/**
|
|
91
|
+
* Filter operators supported by query parser
|
|
92
|
+
* Usage: ?field[operator]=value
|
|
93
|
+
*/
|
|
94
|
+
type FilterOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "nin" | "contains" | "startsWith" | "endsWith" | "regex";
|
|
95
|
+
/**
|
|
96
|
+
* Query parameters for list/search operations
|
|
97
|
+
*/
|
|
98
|
+
interface QueryParams {
|
|
99
|
+
page?: number;
|
|
100
|
+
limit?: number;
|
|
101
|
+
after?: string;
|
|
102
|
+
sort?: SortSpec;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Request options
|
|
107
|
+
*/
|
|
108
|
+
interface RequestOptions {
|
|
109
|
+
token?: string | null;
|
|
110
|
+
organizationId?: string | null;
|
|
111
|
+
cache?: RequestCache;
|
|
112
|
+
revalidate?: number;
|
|
113
|
+
tags?: string[];
|
|
114
|
+
headerOptions?: Record<string, string>;
|
|
115
|
+
responseType?: "json" | "blob" | "text";
|
|
116
|
+
}
|
|
117
|
+
interface BaseApiConfig {
|
|
118
|
+
basePath?: string;
|
|
119
|
+
defaultParams?: {
|
|
120
|
+
limit?: number;
|
|
121
|
+
page?: number;
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
};
|
|
124
|
+
cache?: RequestCache;
|
|
125
|
+
headers?: Record<string, string>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Base API class that provides standardized CRUD operations
|
|
129
|
+
* Supports direct field queries and bracket syntax: field[operator]=value
|
|
130
|
+
*
|
|
131
|
+
* @template TDoc - Document type returned by the API
|
|
132
|
+
* @template TCreate - Type for create payload (defaults to Partial<TDoc>)
|
|
133
|
+
* @template TUpdate - Type for update payload (defaults to Partial<TDoc>)
|
|
134
|
+
*/
|
|
135
|
+
declare class BaseApi<TDoc = Record<string, unknown>, TCreate = Partial<TDoc>, TUpdate = Partial<TDoc>> {
|
|
136
|
+
readonly entity: string;
|
|
137
|
+
readonly config: Required<BaseApiConfig>;
|
|
138
|
+
readonly baseUrl: string;
|
|
139
|
+
constructor(entity: string, config?: BaseApiConfig);
|
|
140
|
+
/**
|
|
141
|
+
* Creates query string from parameters
|
|
142
|
+
* Delegates to shared utility from api-handler.ts
|
|
143
|
+
*/
|
|
144
|
+
createQueryString(params?: Record<string, unknown>): string;
|
|
145
|
+
/**
|
|
146
|
+
* Prepares parameters for API request
|
|
147
|
+
* Handles pagination, sorting, and filters
|
|
148
|
+
* Note: Critical security filters (organizationId, ownerId) are ALWAYS sent, even if null
|
|
149
|
+
*/
|
|
150
|
+
prepareParams(params?: QueryParams): Record<string, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Get all records with pagination and filtering
|
|
153
|
+
* Returns offset or keyset pagination based on params
|
|
154
|
+
*/
|
|
155
|
+
getAll({ token, organizationId, params, options, }?: {
|
|
156
|
+
token?: string | null;
|
|
157
|
+
organizationId?: string | null;
|
|
158
|
+
params?: QueryParams;
|
|
159
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
160
|
+
}): Promise<PaginatedResponse<TDoc>>;
|
|
161
|
+
/**
|
|
162
|
+
* Get a single record by ID
|
|
163
|
+
*/
|
|
164
|
+
getById({ token, organizationId, id, params, options, }: {
|
|
165
|
+
token?: string | null;
|
|
166
|
+
organizationId?: string | null;
|
|
167
|
+
id: string;
|
|
168
|
+
params?: {
|
|
169
|
+
select?: string;
|
|
170
|
+
populate?: string | string[];
|
|
171
|
+
};
|
|
172
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
173
|
+
}): Promise<ApiResponse<TDoc>>;
|
|
174
|
+
/**
|
|
175
|
+
* Create a new record
|
|
176
|
+
*/
|
|
177
|
+
create({ token, organizationId, data, options, }: {
|
|
178
|
+
token: string;
|
|
179
|
+
organizationId?: string | null;
|
|
180
|
+
data: TCreate;
|
|
181
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
182
|
+
}): Promise<ApiResponse<TDoc>>;
|
|
183
|
+
/**
|
|
184
|
+
* Update an existing record
|
|
185
|
+
*/
|
|
186
|
+
update({ token, organizationId, id, data, options, }: {
|
|
187
|
+
token: string;
|
|
188
|
+
organizationId?: string | null;
|
|
189
|
+
id: string;
|
|
190
|
+
data: TUpdate;
|
|
191
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
192
|
+
}): Promise<ApiResponse<TDoc>>;
|
|
193
|
+
/**
|
|
194
|
+
* Delete a record
|
|
195
|
+
*/
|
|
196
|
+
delete({ token, organizationId, id, options, }: {
|
|
197
|
+
token: string;
|
|
198
|
+
organizationId?: string | null;
|
|
199
|
+
id: string;
|
|
200
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
201
|
+
}): Promise<DeleteResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Search with custom parameters
|
|
204
|
+
* @example
|
|
205
|
+
* search({ searchParams: { 'brand[contains]': 'nike' } })
|
|
206
|
+
* search({ searchParams: { upc: '123456789' } })
|
|
207
|
+
*/
|
|
208
|
+
search({ token, organizationId, searchParams, params, options, }?: {
|
|
209
|
+
token?: string | null;
|
|
210
|
+
organizationId?: string | null;
|
|
211
|
+
searchParams?: Record<string, unknown>;
|
|
212
|
+
params?: QueryParams;
|
|
213
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
214
|
+
}): Promise<PaginatedResponse<TDoc>>;
|
|
215
|
+
/**
|
|
216
|
+
* Find records by field with optional operator
|
|
217
|
+
* @example
|
|
218
|
+
* findBy({ field: 'brand', value: 'nike', operator: 'contains' })
|
|
219
|
+
* findBy({ field: 'status', value: ['active', 'pending'], operator: 'in' })
|
|
220
|
+
*/
|
|
221
|
+
findBy({ token, organizationId, field, value, operator, params, options, }: {
|
|
222
|
+
token?: string | null;
|
|
223
|
+
organizationId?: string | null;
|
|
224
|
+
field: string;
|
|
225
|
+
value: unknown;
|
|
226
|
+
operator?: FilterOperator;
|
|
227
|
+
params?: QueryParams;
|
|
228
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
229
|
+
}): Promise<PaginatedResponse<TDoc>>;
|
|
230
|
+
/**
|
|
231
|
+
* Make a custom API request to a sub-endpoint
|
|
232
|
+
* @example
|
|
233
|
+
* request('POST', `${this.baseUrl}/${id}/action`, { token, data: { ... } })
|
|
234
|
+
*/
|
|
235
|
+
request<TResponse = unknown>(method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE", endpoint: string, { token, organizationId, data, params, options, }?: {
|
|
236
|
+
token?: string;
|
|
237
|
+
organizationId?: string | null;
|
|
238
|
+
data?: unknown;
|
|
239
|
+
params?: QueryParams;
|
|
240
|
+
options?: Omit<RequestOptions, "token" | "organizationId">;
|
|
241
|
+
}): Promise<TResponse>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Factory function to create a typed BaseApi instance
|
|
245
|
+
*
|
|
246
|
+
* @template TDoc - Document type returned by the API
|
|
247
|
+
* @template TCreate - Type for create payload
|
|
248
|
+
* @template TUpdate - Type for update payload
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Simple usage
|
|
252
|
+
* const productApi = createCrudApi('products');
|
|
253
|
+
*
|
|
254
|
+
* // With types
|
|
255
|
+
* interface Product { _id: string; name: string; price: number; }
|
|
256
|
+
* interface CreateProduct { name: string; price: number; }
|
|
257
|
+
* const productApi = createCrudApi<Product, CreateProduct>('products');
|
|
258
|
+
*
|
|
259
|
+
* // With custom config
|
|
260
|
+
* const productApi = createCrudApi('products', { basePath: '/api/v2' });
|
|
261
|
+
*/
|
|
262
|
+
declare function createCrudApi<TDoc = Record<string, unknown>, TCreate = Partial<TDoc>, TUpdate = Partial<TDoc>>(entity: string, config?: BaseApiConfig): BaseApi<TDoc, TCreate, TUpdate>;
|
|
263
|
+
/**
|
|
264
|
+
* Extract document type from paginated response
|
|
265
|
+
*/
|
|
266
|
+
type ExtractDoc<T> = T extends PaginatedResponse<infer D> ? D : never;
|
|
267
|
+
/**
|
|
268
|
+
* Helper to check if response is offset pagination
|
|
269
|
+
*/
|
|
270
|
+
declare function isOffsetPagination<T>(response: PaginatedResponse<T>): response is OffsetPaginationResponse<T>;
|
|
271
|
+
/**
|
|
272
|
+
* Helper to check if response is keyset pagination
|
|
273
|
+
*/
|
|
274
|
+
declare function isKeysetPagination<T>(response: PaginatedResponse<T>): response is KeysetPaginationResponse<T>;
|
|
275
|
+
/**
|
|
276
|
+
* Helper to check if response is aggregate pagination
|
|
277
|
+
*/
|
|
278
|
+
declare function isAggregatePagination<T>(response: PaginatedResponse<T>): response is AggregatePaginationResponse<T>;
|
|
279
|
+
|
|
280
|
+
export { type ApiResponse as A, BaseApi as B, type DeleteResponse as D, type ExtractDoc as E, type FilterOperator as F, type KeysetPaginationResponse as K, type OffsetPaginationResponse as O, type PaginatedResponse as P, type QueryParams as Q, type RequestOptions as R, type SortDirection as S, isKeysetPagination as a, isAggregatePagination as b, createCrudApi as c, type AggregatePaginationResponse as d, type SortSpec as e, type BaseApiConfig as f, isOffsetPagination as i };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { i as User } from '../user-data-DdLjAGwO.js';
|
|
2
|
+
export { j as AuthApiResponse, A as AuthResponse, D as DISCOUNT_ALLOWED_ROLES, F as ForgotPasswordData, L as LoginCredentials, O as OAuthLoginData, R as RefreshResponse, n as RefreshTokenData, k as RegisterData, m as ResetPasswordData, U as UserRole, h as UserRoleType, V as VerifyManagerData, p as VerifyManagerResponse, a as authApi, a as authApiDefault, d as createUser, f as forgetPassApi, e as getProfile, g as getUser, c as getUserByPhone, l as loginApi, o as oauthLoginApi, r as registerApi, b as resetPassApi, t as tokenRefreshApi, u as updateUser, v as verifyManagerAuth } from '../user-data-DdLjAGwO.js';
|
|
3
|
+
|
|
4
|
+
interface UseUserSearchOptions {
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
interface UseUserSearchReturn {
|
|
8
|
+
/** Search for user by email or phone */
|
|
9
|
+
searchUser: (value: string, by?: "email" | "phone") => void;
|
|
10
|
+
/** Found user (first match) */
|
|
11
|
+
user: User | undefined;
|
|
12
|
+
/** No user found for the search */
|
|
13
|
+
notFound: boolean;
|
|
14
|
+
/** Search in progress */
|
|
15
|
+
isSearching: boolean;
|
|
16
|
+
/** Search error */
|
|
17
|
+
error: Error | null;
|
|
18
|
+
/** Reset search state */
|
|
19
|
+
reset: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook for searching users by email or phone number
|
|
23
|
+
*
|
|
24
|
+
* @param options.token - Auth token (required)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { searchUser, user, isSearching, notFound } = useUserSearch({ token });
|
|
29
|
+
*
|
|
30
|
+
* // Search by email
|
|
31
|
+
* searchUser("user@example.com");
|
|
32
|
+
*
|
|
33
|
+
* // Search by phone
|
|
34
|
+
* searchUser("01712345678", "phone");
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function useUserSearch({ token }: UseUserSearchOptions): UseUserSearchReturn;
|
|
38
|
+
|
|
39
|
+
export { User, useUserSearch };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { DISCOUNT_ALLOWED_ROLES, UserRole, authApi, user_data_default as authApiDefault, createUser, forgetPassApi, getProfile, getUser, getUserByPhone, loginApi, oauthLoginApi, registerApi, resetPassApi, tokenRefreshApi, updateUser, useUserSearch, verifyManagerAuth } from '../chunk-BDA2WSJA.js';
|
|
3
|
+
import '../chunk-VR36QVX2.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|