woodsportal-client-sdk 1.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.
- package/CHANGELOG.md +44 -0
- package/LICENSE +15 -0
- package/README.md +540 -0
- package/dist/apis/authentication.d.ts +36 -0
- package/dist/apis/authentication.js +105 -0
- package/dist/apis/authentication.js.map +1 -0
- package/dist/apis/object.d.ts +6 -0
- package/dist/apis/object.js +14 -0
- package/dist/apis/object.js.map +1 -0
- package/dist/apis/pipeline.d.ts +6 -0
- package/dist/apis/pipeline.js +14 -0
- package/dist/apis/pipeline.js.map +1 -0
- package/dist/apis/users.d.ts +16 -0
- package/dist/apis/users.js +36 -0
- package/dist/apis/users.js.map +1 -0
- package/dist/breadcrumb/breadcrumbs.d.ts +11 -0
- package/dist/breadcrumb/breadcrumbs.js +105 -0
- package/dist/breadcrumb/breadcrumbs.js.map +1 -0
- package/dist/breadcrumb/generate-url.d.ts +3 -0
- package/dist/breadcrumb/generate-url.js +125 -0
- package/dist/breadcrumb/generate-url.js.map +1 -0
- package/dist/breadcrumb/key-map.d.ts +1 -0
- package/dist/breadcrumb/key-map.js +24 -0
- package/dist/breadcrumb/key-map.js.map +1 -0
- package/dist/breadcrumb/param.d.ts +10 -0
- package/dist/breadcrumb/param.js +100 -0
- package/dist/breadcrumb/param.js.map +1 -0
- package/dist/breadcrumb/url-utils.d.ts +10 -0
- package/dist/breadcrumb/url-utils.js +87 -0
- package/dist/breadcrumb/url-utils.js.map +1 -0
- package/dist/breadcrumb/url.d.ts +9 -0
- package/dist/breadcrumb/url.js +101 -0
- package/dist/breadcrumb/url.js.map +1 -0
- package/dist/clint/api-endpoints.d.ts +1 -0
- package/dist/clint/api-endpoints.js +16 -0
- package/dist/clint/api-endpoints.js.map +1 -0
- package/dist/clint/auth-utils.d.ts +9 -0
- package/dist/clint/auth-utils.js +46 -0
- package/dist/clint/auth-utils.js.map +1 -0
- package/dist/clint/config.d.ts +4 -0
- package/dist/clint/config.js +4 -0
- package/dist/clint/config.js.map +1 -0
- package/dist/clint/http-clint.d.ts +34 -0
- package/dist/clint/http-clint.js +144 -0
- package/dist/clint/http-clint.js.map +1 -0
- package/dist/clint/index.d.ts +23 -0
- package/dist/clint/index.js +45 -0
- package/dist/clint/index.js.map +1 -0
- package/dist/clint/token-store.d.ts +10 -0
- package/dist/clint/token-store.js +45 -0
- package/dist/clint/token-store.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/mutation/createMutation.d.ts +5 -0
- package/dist/mutation/createMutation.js +29 -0
- package/dist/mutation/createMutation.js.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/compress.d.ts +2 -0
- package/dist/utils/compress.js +30 -0
- package/dist/utils/compress.js.map +1 -0
- package/dist/utils/config.d.ts +4 -0
- package/dist/utils/config.js +11 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +7 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/cookie.d.ts +5 -0
- package/dist/utils/cookie.js +30 -0
- package/dist/utils/cookie.js.map +1 -0
- package/dist/utils/cookie.test.d.ts +1 -0
- package/dist/utils/cookie.test.js +17 -0
- package/dist/utils/cookie.test.js.map +1 -0
- package/dist/utils/createApiAction.d.ts +9 -0
- package/dist/utils/createApiAction.js +23 -0
- package/dist/utils/createApiAction.js.map +1 -0
- package/dist/utils/generateApiUrl.d.ts +5 -0
- package/dist/utils/generateApiUrl.js +22 -0
- package/dist/utils/generateApiUrl.js.map +1 -0
- package/dist/utils/param.d.ts +4 -0
- package/dist/utils/param.js +39 -0
- package/dist/utils/param.js.map +1 -0
- package/dist/utils/url.d.ts +1 -0
- package/dist/utils/url.js +17 -0
- package/dist/utils/url.js.map +1 -0
- package/package.json +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## 1.1.0 (2026-02-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add production-grade npm package setup ([11d1e22](https://github.com/Digital-Woods/digitalwoods.io-woodsportal-client-sdk/commit/11d1e2276b03cd2b0dcfe3d480b77013ec8006eb))
|
|
11
|
+
|
|
12
|
+
# Changelog
|
|
13
|
+
|
|
14
|
+
All notable changes to this project will be documented in this file.
|
|
15
|
+
|
|
16
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
17
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
18
|
+
|
|
19
|
+
## [Unreleased]
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- Initial release of WoodsPortal Client SDK
|
|
23
|
+
- Authentication APIs (login, logout, preLogin, verifyEmail, forgetPassword, resetPassword)
|
|
24
|
+
- User management APIs (me, profile, changePassword)
|
|
25
|
+
- Pipeline and Object listing APIs
|
|
26
|
+
- Breadcrumb utilities
|
|
27
|
+
- URL generation and routing utilities
|
|
28
|
+
- Token management and refresh functionality
|
|
29
|
+
- SDK initialization function
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- N/A
|
|
33
|
+
|
|
34
|
+
### Deprecated
|
|
35
|
+
- N/A
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
- N/A
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
- N/A
|
|
42
|
+
|
|
43
|
+
### Security
|
|
44
|
+
- N/A
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Digital Woods
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
# WoodsPortal Client SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/woodsportal-client-sdk)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
|
|
7
|
+
Official TypeScript/JavaScript SDK for WoodsPortal API. This SDK provides a comprehensive client library for interacting with WoodsPortal services including authentication, user management, pipelines, objects, and more.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔐 **Authentication** - Complete authentication flow including login, logout, password reset, and email verification
|
|
12
|
+
- 👤 **User Management** - User profile management and password changes
|
|
13
|
+
- 📊 **Pipelines & Objects** - List and manage pipelines and objects
|
|
14
|
+
- 🍞 **Breadcrumbs** - Built-in breadcrumb utilities for navigation
|
|
15
|
+
- 🔗 **URL Utilities** - URL generation and routing helpers
|
|
16
|
+
- 🔄 **Token Management** - Automatic token refresh and management
|
|
17
|
+
- 📦 **TypeScript Support** - Full TypeScript definitions included
|
|
18
|
+
- 🌳 **Tree-shakeable** - Optimized for modern bundlers
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install woodsportal-client-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yarn add woodsportal-client-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add woodsportal-client-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### Basic Setup
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { initialize, api } from 'woodsportal-client-sdk';
|
|
44
|
+
|
|
45
|
+
// Initialize the SDK with your configuration
|
|
46
|
+
initialize({
|
|
47
|
+
baseURL: 'https://api.woodsportal.com',
|
|
48
|
+
timeout: 30000,
|
|
49
|
+
hubId: 'your-hub-id', // Optional
|
|
50
|
+
devPortalId: 'your-dev-portal-id', // Optional
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Use the API
|
|
54
|
+
const { login, isLoading } = api.login({
|
|
55
|
+
onSuccess: (data) => {
|
|
56
|
+
console.log('Login successful!', data);
|
|
57
|
+
},
|
|
58
|
+
onError: (error) => {
|
|
59
|
+
console.error('Login failed:', error);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Perform login
|
|
64
|
+
await login({
|
|
65
|
+
username: 'user@example.com',
|
|
66
|
+
password: 'your-password',
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
### Initialize SDK
|
|
73
|
+
|
|
74
|
+
The SDK must be initialized before use. Call `initialize()` with your configuration:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { initialize } from 'woodsportal-client-sdk';
|
|
78
|
+
|
|
79
|
+
initialize({
|
|
80
|
+
baseURL: 'https://api.woodsportal.com', // Required: Your API base URL
|
|
81
|
+
timeout: 30000, // Optional: Request timeout in milliseconds (default: 50000)
|
|
82
|
+
hubId: 'your-hub-id', // Optional: Hub ID for API requests
|
|
83
|
+
devPortalId: 'your-dev-portal-id', // Optional: Dev Portal ID
|
|
84
|
+
headers: { // Optional: Custom headers
|
|
85
|
+
'X-Custom-Header': 'value',
|
|
86
|
+
},
|
|
87
|
+
routes: { // Optional: Route configuration
|
|
88
|
+
unauthorized: '/login',
|
|
89
|
+
login: '/login',
|
|
90
|
+
},
|
|
91
|
+
skipCurrentPublicPath: () => false, // Optional: Function to skip auth error handling
|
|
92
|
+
onLogout: async () => { // Optional: Logout handler
|
|
93
|
+
// Handle logout
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### Authentication
|
|
101
|
+
|
|
102
|
+
#### Login
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { api } from 'woodsportal-client-sdk';
|
|
106
|
+
|
|
107
|
+
const { login, isLoading } = api.login({
|
|
108
|
+
onSuccess: (data) => {
|
|
109
|
+
// Handle successful login
|
|
110
|
+
// Tokens are automatically stored
|
|
111
|
+
},
|
|
112
|
+
onError: (error) => {
|
|
113
|
+
// Handle error
|
|
114
|
+
},
|
|
115
|
+
onLoadingChange: (loading) => {
|
|
116
|
+
// Handle loading state
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await login({
|
|
121
|
+
username: 'user@example.com',
|
|
122
|
+
password: 'password123',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Pre-Login
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const { preLogin, isLoading } = api.preLogin({
|
|
130
|
+
onSuccess: (data) => {
|
|
131
|
+
// Handle pre-login response
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await preLogin({
|
|
136
|
+
username: 'user@example.com',
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Logout
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const { logout, isLoading } = api.logout({
|
|
144
|
+
onSuccess: () => {
|
|
145
|
+
// Handle successful logout
|
|
146
|
+
// Cookies are automatically cleared
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
await logout();
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Verify Email
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const { verifyEmail, isLoading } = api.verifyEmail({
|
|
157
|
+
onSuccess: (data) => {
|
|
158
|
+
// Email verified successfully
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await verifyEmail({
|
|
163
|
+
token: 'verification-token',
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Forget Password
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const { forgetPassword, isLoading } = api.forgetPassword({
|
|
171
|
+
onSuccess: (data) => {
|
|
172
|
+
// Password reset email sent
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await forgetPassword({
|
|
177
|
+
email: 'user@example.com',
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Reset Password
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Step 1: Verify reset token
|
|
185
|
+
const { resetPasswordVerifyToken, isLoading } = api.resetPasswordVerifyToken({
|
|
186
|
+
onSuccess: (data) => {
|
|
187
|
+
// Token verified, proceed to reset
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await resetPasswordVerifyToken({
|
|
192
|
+
token: 'reset-token',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Step 2: Reset password
|
|
196
|
+
const { resetPassword } = api.resetPassword({
|
|
197
|
+
onSuccess: (data) => {
|
|
198
|
+
// Password reset successful
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await resetPassword({
|
|
203
|
+
newPassword: 'newPassword123',
|
|
204
|
+
confirmPassword: 'newPassword123',
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### User Management
|
|
209
|
+
|
|
210
|
+
#### Get Current User
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
const { me, isLoading } = api.me({
|
|
214
|
+
onSuccess: (user) => {
|
|
215
|
+
console.log('Current user:', user);
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
await me();
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### Get User Profile
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const { profile, isLoading } = api.profile({
|
|
226
|
+
onSuccess: (profile) => {
|
|
227
|
+
console.log('User profile:', profile);
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
await profile();
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Change Password
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const { changePassword, isLoading } = api.changePassword({
|
|
238
|
+
onSuccess: () => {
|
|
239
|
+
// Password changed successfully
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
await changePassword({
|
|
244
|
+
currentPassword: 'oldPassword123',
|
|
245
|
+
newPassword: 'newPassword123',
|
|
246
|
+
confirmPassword: 'newPassword123',
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Pipelines
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
const { pipelines, isLoading } = api.pipelines({
|
|
254
|
+
onSuccess: (data) => {
|
|
255
|
+
console.log('Pipelines:', data);
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await pipelines({
|
|
260
|
+
// Optional query parameters
|
|
261
|
+
queryParams: {
|
|
262
|
+
page: 1,
|
|
263
|
+
limit: 10,
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Objects
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
const { objects, isLoading } = api.objects({
|
|
272
|
+
onSuccess: (data) => {
|
|
273
|
+
console.log('Objects:', data);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
await objects({
|
|
278
|
+
// Optional query parameters
|
|
279
|
+
queryParams: {
|
|
280
|
+
page: 1,
|
|
281
|
+
limit: 10,
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Token Management
|
|
287
|
+
|
|
288
|
+
The SDK automatically handles token refresh. You can also manually check token status:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { api } from 'woodsportal-client-sdk';
|
|
292
|
+
|
|
293
|
+
// Check if user is authenticated
|
|
294
|
+
const isAuthenticated = api.isAuthenticateApp();
|
|
295
|
+
|
|
296
|
+
// Check if access token is expired
|
|
297
|
+
const isExpired = api.isExpiresAccessToken();
|
|
298
|
+
|
|
299
|
+
// Get current access token
|
|
300
|
+
const token = api.getAccessToken();
|
|
301
|
+
|
|
302
|
+
// Get refresh token
|
|
303
|
+
const refreshToken = api.getRefreshToken();
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Breadcrumbs
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import { breadcrumbsDetails } from 'woodsportal-client-sdk';
|
|
310
|
+
|
|
311
|
+
// Get breadcrumbs from URL
|
|
312
|
+
const breadcrumbs = breadcrumbsDetails.getBreadcrumbs();
|
|
313
|
+
|
|
314
|
+
// Get table title
|
|
315
|
+
const { tableTitle, singularTableTitle } = breadcrumbsDetails.getTableTitle(
|
|
316
|
+
'component-name',
|
|
317
|
+
'Title',
|
|
318
|
+
'Tickets'
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
// Get form title
|
|
322
|
+
const { dialogTitle } = breadcrumbsDetails.getFormTitle(
|
|
323
|
+
'type',
|
|
324
|
+
'Title',
|
|
325
|
+
'addNew'
|
|
326
|
+
);
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### URL Utilities
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
import { url } from 'woodsportal-client-sdk';
|
|
333
|
+
|
|
334
|
+
// Generate link
|
|
335
|
+
const link = url.useMakeLink('/path', { param: 'value' });
|
|
336
|
+
|
|
337
|
+
// Update link
|
|
338
|
+
const updatedLink = url.useUpdateLink('/path', { param: 'new-value' });
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Route Parameters
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
import { routeParam } from 'woodsportal-client-sdk';
|
|
345
|
+
|
|
346
|
+
// Get route details
|
|
347
|
+
const routeDetails = routeParam.getRouteDetails();
|
|
348
|
+
|
|
349
|
+
// Get parameter details
|
|
350
|
+
const paramDetails = routeParam.getParamDetails('param-name');
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## TypeScript Support
|
|
354
|
+
|
|
355
|
+
The SDK is written in TypeScript and includes full type definitions. All types are exported for your convenience:
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import type {
|
|
359
|
+
HttpClientConfig,
|
|
360
|
+
LoginPayload,
|
|
361
|
+
PreLoginPayload,
|
|
362
|
+
VerifyEmailPayload,
|
|
363
|
+
ResetPasswordPayload,
|
|
364
|
+
ForgetPasswordPayload,
|
|
365
|
+
ChangePasswordPayload,
|
|
366
|
+
MutationOptions,
|
|
367
|
+
} from 'woodsportal-client-sdk';
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Error Handling
|
|
371
|
+
|
|
372
|
+
All API methods support error handling through the `onError` callback:
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
const { login } = api.login({
|
|
376
|
+
onSuccess: (data) => {
|
|
377
|
+
// Success handler
|
|
378
|
+
},
|
|
379
|
+
onError: (error) => {
|
|
380
|
+
// Error handler
|
|
381
|
+
console.error('Error:', error);
|
|
382
|
+
|
|
383
|
+
// Access error details
|
|
384
|
+
if (error.response) {
|
|
385
|
+
console.error('Status:', error.response.status);
|
|
386
|
+
console.error('Data:', error.response.data);
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Loading States
|
|
393
|
+
|
|
394
|
+
All mutation methods return an `isLoading` state:
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
const { login, isLoading } = api.login();
|
|
398
|
+
|
|
399
|
+
// isLoading is a boolean that indicates if the request is in progress
|
|
400
|
+
console.log('Loading:', isLoading);
|
|
401
|
+
|
|
402
|
+
await login({ username: 'user', password: 'pass' });
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Examples
|
|
406
|
+
|
|
407
|
+
### React Example
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
import { useState, useEffect } from 'react';
|
|
411
|
+
import { initialize, api } from 'woodsportal-client-sdk';
|
|
412
|
+
|
|
413
|
+
function App() {
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
// Initialize SDK
|
|
416
|
+
initialize({
|
|
417
|
+
baseURL: 'https://api.woodsportal.com',
|
|
418
|
+
});
|
|
419
|
+
}, []);
|
|
420
|
+
|
|
421
|
+
const handleLogin = async () => {
|
|
422
|
+
const { login } = api.login({
|
|
423
|
+
onSuccess: (data) => {
|
|
424
|
+
console.log('Logged in!', data);
|
|
425
|
+
},
|
|
426
|
+
onError: (error) => {
|
|
427
|
+
console.error('Login error:', error);
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
await login({
|
|
432
|
+
username: 'user@example.com',
|
|
433
|
+
password: 'password',
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
return (
|
|
438
|
+
<button onClick={handleLogin}>
|
|
439
|
+
Login
|
|
440
|
+
</button>
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Node.js Example
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
import { initialize, api } from 'woodsportal-client-sdk';
|
|
449
|
+
|
|
450
|
+
// Initialize SDK
|
|
451
|
+
initialize({
|
|
452
|
+
baseURL: 'https://api.woodsportal.com',
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Login
|
|
456
|
+
const { login } = api.login({
|
|
457
|
+
onSuccess: async (data) => {
|
|
458
|
+
console.log('Login successful');
|
|
459
|
+
|
|
460
|
+
// Fetch user profile
|
|
461
|
+
const { me } = api.me({
|
|
462
|
+
onSuccess: (user) => {
|
|
463
|
+
console.log('User:', user);
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
await me();
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
await login({
|
|
472
|
+
username: 'user@example.com',
|
|
473
|
+
password: 'password',
|
|
474
|
+
});
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Building from Source
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
# Clone the repository
|
|
481
|
+
git clone https://github.com/Digital-Woods/digitalwoods.io-woodsportal-client-sdk.git
|
|
482
|
+
cd digitalwoods.io-woodsportal-client-sdk
|
|
483
|
+
|
|
484
|
+
# Install dependencies
|
|
485
|
+
npm install
|
|
486
|
+
|
|
487
|
+
# Build the project
|
|
488
|
+
npm run build
|
|
489
|
+
|
|
490
|
+
# Run tests
|
|
491
|
+
npm test
|
|
492
|
+
|
|
493
|
+
# Run linting
|
|
494
|
+
npm run lint
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## Development
|
|
498
|
+
|
|
499
|
+
```bash
|
|
500
|
+
# Development mode with watch
|
|
501
|
+
npm run dev
|
|
502
|
+
|
|
503
|
+
# Run tests in watch mode
|
|
504
|
+
npm run test:watch
|
|
505
|
+
|
|
506
|
+
# Check code formatting
|
|
507
|
+
npm run format:check
|
|
508
|
+
|
|
509
|
+
# Fix code formatting
|
|
510
|
+
npm run format
|
|
511
|
+
|
|
512
|
+
# Type checking
|
|
513
|
+
npm run type-check
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Contributing
|
|
517
|
+
|
|
518
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
519
|
+
|
|
520
|
+
1. Fork the repository
|
|
521
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
522
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
523
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
524
|
+
5. Open a Pull Request
|
|
525
|
+
|
|
526
|
+
## License
|
|
527
|
+
|
|
528
|
+
ISC License
|
|
529
|
+
|
|
530
|
+
Copyright (c) 2025, Digital Woods
|
|
531
|
+
|
|
532
|
+
See [LICENSE](LICENSE) file for details.
|
|
533
|
+
|
|
534
|
+
## Support
|
|
535
|
+
|
|
536
|
+
For issues, questions, or contributions, please visit our [GitHub repository](https://github.com/Digital-Woods/digitalwoods.io-woodsportal-client-sdk/issues).
|
|
537
|
+
|
|
538
|
+
## Changelog
|
|
539
|
+
|
|
540
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LoginPayload, MutationOptions, PreLoginPayload, ForgetPasswordPayload, VerifyEmailPayload, ResetPasswordVerifyTokenPayload, ResetPasswordPayload } from '../types';
|
|
2
|
+
export declare function preLogin(options?: MutationOptions<any, any>): {
|
|
3
|
+
mutate: (payload?: PreLoginPayload | undefined) => Promise<any>;
|
|
4
|
+
login: (payload?: PreLoginPayload | undefined) => Promise<any>;
|
|
5
|
+
isLoading: () => boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function login(options?: MutationOptions<any, any>): {
|
|
8
|
+
mutate: (payload?: LoginPayload | undefined) => Promise<any>;
|
|
9
|
+
login: (payload?: LoginPayload | undefined) => Promise<any>;
|
|
10
|
+
isLoading: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function verifyEmail(options?: MutationOptions<any, any>): {
|
|
13
|
+
mutate: (payload?: VerifyEmailPayload | undefined) => Promise<any>;
|
|
14
|
+
verifyEmail: (payload?: VerifyEmailPayload | undefined) => Promise<any>;
|
|
15
|
+
isLoading: () => boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function resetPasswordVerifyToken(options?: MutationOptions<any, any>): {
|
|
18
|
+
mutate: (payload?: ResetPasswordVerifyTokenPayload | undefined) => Promise<any>;
|
|
19
|
+
resetPasswordVerifyToken: (payload?: ResetPasswordVerifyTokenPayload | undefined) => Promise<any>;
|
|
20
|
+
isLoading: () => boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function resetPassword(options?: MutationOptions<any, any>): {
|
|
23
|
+
mutate: (payload?: ResetPasswordPayload | undefined) => Promise<any>;
|
|
24
|
+
resetPassword: (payload?: ResetPasswordPayload | undefined) => Promise<any>;
|
|
25
|
+
isLoading: () => boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function forgetPassword(options?: MutationOptions<any, any>): {
|
|
28
|
+
mutate: (payload?: ForgetPasswordPayload | undefined) => Promise<any>;
|
|
29
|
+
forgetPassword: (payload?: ForgetPasswordPayload | undefined) => Promise<any>;
|
|
30
|
+
isLoading: () => boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare function logout(options?: MutationOptions<any, any>): {
|
|
33
|
+
mutate: (payload?: unknown) => Promise<any>;
|
|
34
|
+
logout: (payload?: unknown) => Promise<any>;
|
|
35
|
+
isLoading: () => boolean;
|
|
36
|
+
};
|