@applite/js-sdk 0.0.12 → 0.0.13

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # @applite/js-sdk
2
2
 
3
- A comprehensive JavaScript/TypeScript SDK for interacting with the Applite Customer API. This library provides a structured, typed interface to manage application data, e-commerce operations, and service bookings.
3
+ A comprehensive JavaScript/TypeScript SDK for interacting with the Applite API. This library provides a typed interface to manage application data, e-commerce operations, service bookings, and more.
4
4
 
5
- > **Full Documentation**: For detailed API references and guides, visit [docs.appliteui.com/sdk](https://docs.appliteui.com/sdk).
5
+ > **Full Documentation**: For detailed API references and guides, visit [docs.appliteui.com](https://docs.appliteui.com).
6
6
 
7
7
  ## Installation
8
8
 
@@ -16,239 +16,487 @@ yarn add @applite/js-sdk
16
16
 
17
17
  ## Quick Start
18
18
 
19
- Initialize the client with your API base URL (optional if using relative paths in a same-origin environment).
20
-
21
19
  ```ts
22
20
  import { AppliteUI } from "@applite/js-sdk";
23
21
 
24
22
  const client = new AppliteUI({
25
23
  baseUrl: "https://api.applite.com", // Optional: Defaults to relative path
26
24
  });
25
+
26
+ // Authenticate a customer
27
+ const user = await client.app.customer.auth({
28
+ appId: "app_123",
29
+ apiKey: "your_api_key",
30
+ fullname: "John Doe",
31
+ telephone: "+2250700000000",
32
+ });
27
33
  ```
28
34
 
29
35
  ## Core Concepts
30
36
 
31
- ### Authentication & Context
37
+ ### Authentication
32
38
 
33
- Every request requires two key parameters to identify the context and authorize the user:
39
+ Every request requires two key parameters:
34
40
 
35
- - **`appId`**: The unique identifier of your application (e.g., used in URL paths).
36
- - **`apiKey`**: The secret key used to authenticate requests.
41
+ - **`appId`**: The unique identifier of your application
42
+ - **`apiKey`**: The secret key used to authenticate requests
37
43
 
38
44
  ### Method Signature
39
45
 
40
- All SDK methods accept a **single object** containing all parameters. This ensures better type safety and extensibility.
46
+ All SDK methods accept a single object containing all parameters:
41
47
 
42
48
  ```ts
43
- // Example signature
44
- await client.module.resource.action({
49
+ await client.module.method({
45
50
  appId: "...",
46
51
  apiKey: "...",
47
52
  ...specificParams,
48
53
  });
49
54
  ```
50
55
 
51
- ## Architecture
56
+ ### Response Structure
52
57
 
53
- The SDK is organized into three main modules:
58
+ ```ts
59
+ // Success
60
+ { success: true, data: {...} }
54
61
 
55
- 1. **App Module (`client.app`)**: Core application logic (Customers, Stats, Finance).
56
- 2. **Store Module (`client.app.store`)**: E-commerce functionality (Products, Orders, Sellers).
57
- 3. **Multi-Service Module (`client.app.multiService`)**: Service booking and appointments.
62
+ // Error
63
+ { success: false, error: "message" }
64
+ ```
58
65
 
59
66
  ---
60
67
 
61
- ## App Management (`client.app`)
68
+ ## API Reference
69
+
70
+ ### Common Module (`client.app`)
71
+
72
+ #### Customer API (`client.app.customer`)
73
+
74
+ | Method | Description |
75
+ |--------|-------------|
76
+ | `auth(params)` | Authenticate or register a customer |
77
+ | `check(params)` | Check if a customer exists by phone |
78
+ | `list(params)` | List customers with optional filtering |
79
+ | `get(params)` | Get customer details by ID |
80
+ | `update(params)` | Update customer profile |
81
+ | `block(params)` | Block or unblock a customer |
82
+ | `delete(params)` | Delete a customer |
83
+ | `selfDelete(params)` | Customer self-deletion |
84
+
85
+ #### Info API (`client.app.info`)
86
+
87
+ | Method | Description |
88
+ |--------|-------------|
89
+ | `list(params)` | List all apps |
90
+ | `create(params)` | Create a new app |
91
+ | `getBySlug(params)` | Get app by slug |
92
+ | `getById(params)` | Get app by ID |
93
+ | `update(params)` | Update app details |
94
+ | `updateModules(params)` | Update app modules |
95
+ | `toggleModule(params)` | Toggle a module on/off |
96
+
97
+ #### Address API (`client.app.address`)
98
+
99
+ | Method | Description |
100
+ |--------|-------------|
101
+ | `list(params)` | List addresses |
102
+ | `create(params)` | Create an address |
103
+ | `update(params)` | Update an address |
104
+ | `delete(params)` | Delete an address |
105
+ | `getById(params)` | Get address by ID |
106
+
107
+ #### Stats API (`client.app.stats`)
108
+
109
+ | Method | Description |
110
+ |--------|-------------|
111
+ | `create(params)` | Create a statistic entry |
112
+ | `get(params)` | Get statistic value |
113
+
114
+ #### Finance API (`client.app.finance`)
115
+
116
+ | Method | Description |
117
+ |--------|-------------|
118
+ | `balance(params)` | Get account balance |
119
+ | `listTransactions(params)` | List transactions |
120
+
121
+ #### Welcome Item API (`client.app.welcomeItem`)
122
+
123
+ | Method | Description |
124
+ |--------|-------------|
125
+ | `list(params)` | List welcome items |
126
+ | `create(params)` | Create a welcome item |
127
+ | `update(params)` | Update a welcome item |
128
+ | `delete(params)` | Delete a welcome item |
129
+
130
+ #### User API (`client.user`)
131
+
132
+ | Method | Description |
133
+ |--------|-------------|
134
+ | `signup(params)` | Register a new user |
135
+ | `signin(params)` | Sign in a user |
136
+ | `get(params)` | Get user by ID |
137
+ | `update(params)` | Update user profile |
138
+ | `delete(params)` | Delete a user |
139
+ | `editCredentials(params)` | Edit user credentials |
140
+ | `verifyPassword(params)` | Verify user password |
141
+ | `setNotification(params)` | Set notification preferences |
142
+
143
+ #### Notification Token API (`client.app.notificationToken`)
144
+
145
+ | Method | Description |
146
+ |--------|-------------|
147
+ | `register(params)` | Register a push token |
148
+ | `unregister(params)` | Unregister a push token |
149
+
150
+ #### Notification API (`client.notification`)
151
+
152
+ | Method | Description |
153
+ |--------|-------------|
154
+ | `getFirebaseConfig(params)` | Get Firebase config |
155
+ | `setFirebaseConfig(params)` | Set Firebase config |
156
+ | `deleteFirebaseConfig(params)` | Delete Firebase config |
157
+ | `getTemplates(params)` | Get notification templates |
158
+ | `setTemplate(params)` | Set a notification template |
159
+ | `deleteTemplate(params)` | Delete a notification template |
160
+ | `getLogs(params)` | Get notification logs |
161
+
162
+ #### Webhook API (`client.webhook`)
163
+
164
+ | Method | Description |
165
+ |--------|-------------|
166
+ | `list(params)` | List webhooks |
167
+ | `set(params)` | Create or update a webhook |
168
+ | `delete(params)` | Delete a webhook |
169
+ | `getLogs(params)` | Get webhook logs |
62
170
 
63
- Manage your application's users and core settings.
171
+ ---
64
172
 
65
- ### Customers
173
+ ### Store Module (`client.app.store`)
174
+
175
+ #### Product API (`client.app.store.product`)
176
+
177
+ | Method | Description |
178
+ |--------|-------------|
179
+ | `list(params)` | List products |
180
+ | `create(params)` | Create a product |
181
+ | `get(params)` | Get product by ID |
182
+ | `update(params)` | Update a product |
183
+ | `delete(params)` | Delete a product |
184
+
185
+ #### Order API (`client.app.store.order`)
186
+
187
+ | Method | Description |
188
+ |--------|-------------|
189
+ | `list(params)` | List orders |
190
+ | `create(params)` | Create an order |
191
+ | `get(params)` | Get order by ID |
192
+ | `update(params)` | Update an order |
193
+
194
+ #### Category API (`client.app.store.category`)
195
+
196
+ | Method | Description |
197
+ |--------|-------------|
198
+ | `list(params)` | List categories |
199
+ | `create(params)` | Create a category |
200
+ | `get(params)` | Get category by ID |
201
+ | `update(params)` | Update a category |
202
+ | `delete(params)` | Delete a category |
203
+
204
+ #### Badge API (`client.app.store.badge`)
205
+
206
+ | Method | Description |
207
+ |--------|-------------|
208
+ | `list(params)` | List badges |
209
+ | `create(params)` | Create a badge |
210
+ | `update(params)` | Update a badge |
211
+ | `delete(params)` | Delete a badge |
212
+
213
+ #### Collection API (`client.app.store.collection`)
214
+
215
+ | Method | Description |
216
+ |--------|-------------|
217
+ | `list(params)` | List collections |
218
+ | `create(params)` | Create a collection |
219
+ | `get(params)` | Get collection by ID |
220
+ | `update(params)` | Update a collection |
221
+ | `delete(params)` | Delete a collection |
222
+
223
+ #### Discount API (`client.app.store.discount`)
224
+
225
+ | Method | Description |
226
+ |--------|-------------|
227
+ | `list(params)` | List discounts |
228
+ | `create(params)` | Create a discount |
229
+ | `get(params)` | Get discount by ID |
230
+ | `update(params)` | Update a discount |
231
+ | `delete(params)` | Delete a discount |
232
+ | `check(params)` | Check discount validity |
233
+
234
+ #### Option API (`client.app.store.option`)
235
+
236
+ | Method | Description |
237
+ |--------|-------------|
238
+ | `list(params)` | List options |
239
+ | `create(params)` | Create an option |
240
+ | `update(params)` | Update an option |
241
+ | `delete(params)` | Delete an option |
242
+
243
+ #### Seller API (`client.app.store.seller`)
244
+
245
+ | Method | Description |
246
+ |--------|-------------|
247
+ | `list(params)` | List sellers |
248
+ | `create(params)` | Create a seller |
249
+ | `get(params)` | Get seller by ID |
250
+ | `update(params)` | Update a seller |
251
+ | `delete(params)` | Delete a seller |
252
+
253
+ #### Shipping API (`client.app.store.shipping`)
254
+
255
+ | Method | Description |
256
+ |--------|-------------|
257
+ | `list(params)` | List shipping profiles |
258
+ | `create(params)` | Create a shipping profile |
259
+ | `update(params)` | Update a shipping profile |
260
+ | `delete(params)` | Delete a shipping profile |
261
+
262
+ #### Tag API (`client.app.store.tag`)
263
+
264
+ | Method | Description |
265
+ |--------|-------------|
266
+ | `list(params)` | List tags |
267
+ | `create(params)` | Create a tag |
268
+ | `update(params)` | Update a tag |
269
+ | `delete(params)` | Delete a tag |
270
+
271
+ #### Tax API (`client.app.store.tax`)
272
+
273
+ | Method | Description |
274
+ |--------|-------------|
275
+ | `list(params)` | List tax configurations |
276
+ | `create(params)` | Create a tax configuration |
277
+ | `update(params)` | Update a tax configuration |
278
+ | `delete(params)` | Delete a tax configuration |
66
279
 
67
- Manage end-users of your application.
280
+ ---
68
281
 
69
- #### Authenticate / Register a Customer
282
+ ### Multi-Service Module (`client.app.multiService`)
283
+
284
+ #### Company API (`client.app.multiService.company`)
285
+
286
+ | Method | Description |
287
+ |--------|-------------|
288
+ | `list(params)` | List companies |
289
+ | `create(params)` | Create a company |
290
+ | `get(params)` | Get company by ID |
291
+ | `update(params)` | Update a company |
292
+ | `delete(params)` | Delete a company |
293
+
294
+ #### Service API (`client.app.multiService.service`)
295
+
296
+ | Method | Description |
297
+ |--------|-------------|
298
+ | `list(params)` | List services |
299
+ | `create(params)` | Create a service |
300
+ | `get(params)` | Get service by ID |
301
+ | `update(params)` | Update a service |
302
+ | `delete(params)` | Delete a service |
303
+
304
+ #### Agent API (`client.app.multiService.agent`)
305
+
306
+ | Method | Description |
307
+ |--------|-------------|
308
+ | `list(params)` | List agents |
309
+ | `create(params)` | Create an agent |
310
+ | `get(params)` | Get agent by ID |
311
+ | `update(params)` | Update an agent |
312
+ | `delete(params)` | Delete an agent |
313
+
314
+ #### Appointment API (`client.app.multiService.appointment`)
315
+
316
+ | Method | Description |
317
+ |--------|-------------|
318
+ | `list(params)` | List appointments |
319
+ | `create(params)` | Create an appointment |
320
+ | `get(params)` | Get appointment by ID |
321
+ | `updateStatus(params)` | Update appointment status |
322
+ | `assignAgent(params)` | Assign an agent to appointment |
323
+
324
+ #### Field Template API (`client.app.multiService.fieldTemplate`)
325
+
326
+ | Method | Description |
327
+ |--------|-------------|
328
+ | `list(params)` | List field templates |
329
+ | `create(params)` | Create a field template |
330
+ | `update(params)` | Update a field template |
331
+ | `delete(params)` | Delete a field template |
70
332
 
71
- Checks if a user exists; if not, creates a new one.
333
+ ---
72
334
 
73
- ```ts
74
- const user = await client.app.customer.auth({
75
- appId: "app_123",
76
- apiKey: "your_api_key",
77
- fullname: "John Doe",
78
- telephone: "+2250700000000",
79
- email: "john@example.com", // Optional
80
- plateform: "STORE", // Optional: "STORE", "MULTI_SERVICE", etc.
81
- });
82
- ```
335
+ ### Duticotac Module (`client.duticotac`)
83
336
 
84
- #### Check Customer Existence
337
+ #### Balance API (`client.duticotac.balance`)
85
338
 
86
- Verify if a phone number is already registered.
339
+ | Method | Description |
340
+ |--------|-------------|
341
+ | `get(params)` | Get account balance |
87
342
 
88
- ```ts
89
- const user = await client.app.customer.check({
90
- appId: "app_123",
91
- apiKey: "your_api_key",
92
- telephone: "+2250700000000",
93
- });
94
- ```
343
+ #### Offer API (`client.duticotac.offer`)
95
344
 
96
- #### List Customers
345
+ | Method | Description |
346
+ |--------|-------------|
347
+ | `list(params)` | List offers |
348
+ | `create(params)` | Create an offer |
349
+ | `get(params)` | Get offer by ID |
350
+ | `update(params)` | Update an offer |
351
+ | `delete(params)` | Delete an offer |
97
352
 
98
- Retrieve a list of customers with optional filtering.
353
+ #### Payment API (`client.duticotac.payment`)
99
354
 
100
- ```ts
101
- const customers = await client.app.customer.list({
102
- appId: "app_123",
103
- apiKey: "your_api_key",
104
- plateformType: ["STORE"], // Optional filter
105
- });
106
- ```
355
+ | Method | Description |
356
+ |--------|-------------|
357
+ | `initiate(params)` | Initiate a payment |
358
+ | `verify(params)` | Verify a payment |
107
359
 
108
- #### Get & Update Customer
360
+ #### Transaction API (`client.duticotac.transaction`)
109
361
 
110
- Retrieve details or update profile information.
362
+ | Method | Description |
363
+ |--------|-------------|
364
+ | `list(params)` | List transactions |
365
+ | `get(params)` | Get transaction by ID |
111
366
 
112
- ```ts
113
- // Get details
114
- const detail = await client.app.customer.get({
115
- appId: "app_123",
116
- apiKey: "your_api_key",
117
- id: "customer_id",
118
- });
367
+ ---
119
368
 
120
- // Update profile
121
- await client.app.customer.update({
122
- appId: "app_123",
123
- apiKey: "your_api_key",
124
- id: "customer_id",
125
- fullname: "Jane Doe",
126
- email: "jane@example.com",
127
- });
128
- ```
369
+ ### Kolabo Module (`client.kolabo`)
370
+
371
+ #### App API (`client.kolabo.app`)
372
+
373
+ | Method | Description |
374
+ |--------|-------------|
375
+ | `list(params)` | List Kolabo apps |
376
+ | `getBySlug(slug, params)` | Get app by slug |
377
+ | `get(slug, params)` | Get app details |
378
+ | `configure(slug, params)` | Configure a Kolabo app |
379
+ | `join(slug, params)` | Join a Kolabo app |
380
+
381
+ #### Customer API (`client.kolabo.customer`)
382
+
383
+ | Method | Description |
384
+ |--------|-------------|
385
+ | `list(params)` | List customers |
386
+ | `get(params)` | Get customer by ID |
129
387
 
130
- ### Other App Resources
388
+ #### Partner API (`client.kolabo.partner`)
131
389
 
132
- - **Stats**: `client.app.stats.create(...)`
133
- - **Finance**: `client.app.finance.balance(...)`
134
- - **Info**: `client.app.info.list(...)`
390
+ | Method | Description |
391
+ |--------|-------------|
392
+ | `list(params)` | List partners |
393
+ | `create(params)` | Create a partner |
394
+ | `get(params)` | Get partner by ID |
395
+ | `update(params)` | Update a partner |
135
396
 
136
397
  ---
137
398
 
138
- ## E-Commerce (`client.app.store`)
399
+ ### Super Admin Module (`client.superAdmin`)
139
400
 
140
- Full-featured e-commerce management.
401
+ #### Auth API (`client.superAdmin.auth`)
141
402
 
142
- ### Products
403
+ | Method | Description |
404
+ |--------|-------------|
405
+ | `init(params)` | Initialize super admin |
406
+ | `signin(params)` | Sign in as super admin |
407
+ | `me(params)` | Get current admin info |
143
408
 
144
- Create and manage products.
409
+ #### Apps API (`client.superAdmin.apps`)
145
410
 
146
- ```ts
147
- // Create a product
148
- await client.app.store.product.create({
149
- appId: "app_123",
150
- apiKey: "your_api_key",
151
- name: "Premium T-Shirt",
152
- price: 2500,
153
- sellerId: "seller_123",
154
- categoryId: "category_123",
155
- variants: [], // Array of product variants
156
- });
411
+ | Method | Description |
412
+ |--------|-------------|
413
+ | `list(params)` | List all apps |
414
+ | `get(params)` | Get app by ID |
415
+ | `update(params)` | Update an app |
157
416
 
158
- // List products
159
- await client.app.store.product.list({
160
- appId: "app_123",
161
- apiKey: "your_api_key",
162
- });
163
- ```
417
+ #### Modules API (`client.superAdmin.modules`)
164
418
 
165
- ### Orders
419
+ | Method | Description |
420
+ |--------|-------------|
421
+ | `list(params)` | List all modules |
422
+ | `update(params)` | Update module settings |
166
423
 
167
- Handle customer orders.
424
+ #### Stats API (`client.superAdmin.stats`)
168
425
 
169
- ```ts
170
- // Create an order
171
- await client.app.store.order.create({
172
- appId: "app_123",
173
- apiKey: "your_api_key",
174
- items: [
175
- { productId: "prod_1", quantity: 2 }
176
- ],
177
- customerId: "cust_1",
178
- totalAmount: 5000,
179
- shippingAddress: { ... }
180
- });
426
+ | Method | Description |
427
+ |--------|-------------|
428
+ | `get(params)` | Get platform statistics |
181
429
 
182
- // List orders
183
- await client.app.store.order.list({
184
- appId: "app_123",
185
- apiKey: "your_api_key",
186
- });
187
- ```
430
+ #### Finance API (`client.superAdmin.finance`)
431
+
432
+ | Method | Description |
433
+ |--------|-------------|
434
+ | `balance(params)` | Get platform balance |
435
+ | `listTransactions(params)` | List platform transactions |
188
436
 
189
- ### Available Store Modules
437
+ #### Notification API (`client.superAdmin.notification`)
190
438
 
191
- - `badge`
192
- - `category`
193
- - `collection`
194
- - `discount`
195
- - `option`
196
- - `seller`
197
- - `shipping`
198
- - `tag`
199
- - `tax`
439
+ | Method | Description |
440
+ |--------|-------------|
441
+ | `send(params)` | Send a notification |
442
+ | `broadcast(params)` | Broadcast to all users |
200
443
 
201
444
  ---
202
445
 
203
- ## Multi-Service (`client.app.multiService`)
446
+ ### Maintenance Module (`client.maintenance`)
204
447
 
205
- Booking system for service-based applications.
448
+ | Method | Description |
449
+ |--------|-------------|
450
+ | `cronNotification(params)` | Run notification cron job |
451
+ | `cronBilling(params)` | Run billing cron job |
452
+ | `cleanupTransactions(params)` | Cleanup old transactions |
206
453
 
207
- ### Appointments
454
+ ---
208
455
 
209
- Manage bookings between customers and agents/companies.
456
+ ## Error Handling
210
457
 
211
- ```ts
212
- // Create an appointment
213
- await client.app.multiService.appointment.create({
214
- appId: "app_123",
215
- apiKey: "your_api_key",
216
- serviceId: "srv_123",
217
- customerId: "cust_123",
218
- date: "2024-12-25T10:00:00Z",
219
- status: "PENDING",
220
- });
458
+ All API methods return a promise that resolves to a response object:
221
459
 
222
- // Update status
223
- await client.app.multiService.appointment.updateStatus({
224
- appId: "app_123",
225
- apiKey: "your_api_key",
226
- id: "apt_123",
227
- status: "CONFIRMED",
228
- });
460
+ ```ts
461
+ try {
462
+ const response = await client.app.customer.auth({
463
+ appId: "app_123",
464
+ apiKey: "your_api_key",
465
+ fullname: "John Doe",
466
+ telephone: "+2250700000000",
467
+ });
468
+
469
+ if (response.success) {
470
+ console.log("User:", response.data);
471
+ }
472
+ } catch (error) {
473
+ console.error("Request failed:", error);
474
+ }
229
475
  ```
230
476
 
231
- ### Available Service Modules
232
-
233
- - `company`: Manage service providers.
234
- - `service`: Define services offered.
235
- - `agent`: Manage individual staff members.
236
-
237
477
  ---
238
478
 
239
479
  ## TypeScript Support
240
480
 
241
- The SDK is written in TypeScript and ships with full type definitions. You can import types directly to type your application logic.
481
+ The SDK is written in TypeScript and ships with full type definitions:
242
482
 
243
483
  ```ts
244
484
  import {
245
485
  Customer,
246
- CreateProductParams,
486
+ CustomerListItem,
247
487
  CustomerAuthParams,
488
+ CreateProductParams,
489
+ OrderStatus,
490
+ PaymentStatus,
491
+ // ... and many more
248
492
  } from "@applite/js-sdk";
249
493
  ```
250
494
 
495
+ ---
496
+
251
497
  ## Scripts
252
498
 
253
- - `pnpm build`: Build the SDK (ESM/CJS).
254
- - `pnpm test`: Run type checks.
499
+ ```bash
500
+ pnpm build # Build the SDK (ESM/CJS)
501
+ pnpm test # Run type checks
502
+ ```