zone4code-sdk 1.0.10 → 1.0.11
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/dist/index.cjs +543 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +407 -6
- package/dist/index.d.ts +407 -6
- package/dist/index.js +540 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ interface StorageAdapter {
|
|
|
5
5
|
}
|
|
6
6
|
interface Zone4CodeConfig {
|
|
7
7
|
/**
|
|
8
|
-
* The base URL of the API Gateway (
|
|
8
|
+
* The base URL of the API Gateway (defaults to ZONE4BUILD_GATEWAY_URL, VITE_ZONE4BUILD_GATEWAY_URL, or https://api.zone4build.com)
|
|
9
9
|
*/
|
|
10
|
-
gatewayUrl
|
|
10
|
+
gatewayUrl?: string;
|
|
11
11
|
/**
|
|
12
|
-
* Default tenant identifier (
|
|
12
|
+
* Default tenant identifier (defaults to ZONE4BUILD_WORKSPACE_ID, VITE_ZONE4BUILD_WORKSPACE_ID, or 'default')
|
|
13
13
|
*/
|
|
14
|
-
tenantId
|
|
14
|
+
tenantId?: string;
|
|
15
15
|
/**
|
|
16
16
|
* Optional initial JWT authorization token
|
|
17
17
|
*/
|
|
@@ -295,6 +295,398 @@ declare class AuthClient {
|
|
|
295
295
|
logout(): void;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
interface ProductItem {
|
|
299
|
+
id: string | number;
|
|
300
|
+
name: string;
|
|
301
|
+
slug: string;
|
|
302
|
+
description?: string;
|
|
303
|
+
price: number;
|
|
304
|
+
sale_price?: number | null;
|
|
305
|
+
min_price?: number;
|
|
306
|
+
max_price?: number;
|
|
307
|
+
sku?: string;
|
|
308
|
+
quantity?: number;
|
|
309
|
+
in_stock?: boolean;
|
|
310
|
+
is_taxable?: boolean;
|
|
311
|
+
status?: string;
|
|
312
|
+
product_type?: string;
|
|
313
|
+
image?: {
|
|
314
|
+
id: string;
|
|
315
|
+
original: string;
|
|
316
|
+
thumbnail?: string;
|
|
317
|
+
};
|
|
318
|
+
gallery?: Array<{
|
|
319
|
+
id: string;
|
|
320
|
+
original: string;
|
|
321
|
+
thumbnail?: string;
|
|
322
|
+
}>;
|
|
323
|
+
categories?: Array<{
|
|
324
|
+
id: string | number;
|
|
325
|
+
name: string;
|
|
326
|
+
slug: string;
|
|
327
|
+
}>;
|
|
328
|
+
shop_id?: string | number;
|
|
329
|
+
created_at?: string;
|
|
330
|
+
updated_at?: string;
|
|
331
|
+
[key: string]: any;
|
|
332
|
+
}
|
|
333
|
+
interface ProductPaginator {
|
|
334
|
+
data: ProductItem[];
|
|
335
|
+
count?: number;
|
|
336
|
+
total?: number;
|
|
337
|
+
currentPage?: number;
|
|
338
|
+
lastPage?: number;
|
|
339
|
+
perPage?: number;
|
|
340
|
+
first_page_url?: string;
|
|
341
|
+
last_page_url?: string;
|
|
342
|
+
next_page_url?: string;
|
|
343
|
+
prev_page_url?: string;
|
|
344
|
+
}
|
|
345
|
+
interface CategoryItem {
|
|
346
|
+
id: string | number;
|
|
347
|
+
name: string;
|
|
348
|
+
slug: string;
|
|
349
|
+
icon?: string;
|
|
350
|
+
image?: {
|
|
351
|
+
id: string;
|
|
352
|
+
original: string;
|
|
353
|
+
thumbnail?: string;
|
|
354
|
+
};
|
|
355
|
+
details?: string;
|
|
356
|
+
parent_id?: string | number | null;
|
|
357
|
+
children?: CategoryItem[];
|
|
358
|
+
products_count?: number;
|
|
359
|
+
[key: string]: any;
|
|
360
|
+
}
|
|
361
|
+
interface OrderItem {
|
|
362
|
+
id: string | number;
|
|
363
|
+
tracking_number: string;
|
|
364
|
+
customer_id?: string;
|
|
365
|
+
customer_contact?: string;
|
|
366
|
+
customer_name?: string;
|
|
367
|
+
amount: number;
|
|
368
|
+
total: number;
|
|
369
|
+
paid_total?: number;
|
|
370
|
+
payment_id?: string;
|
|
371
|
+
payment_gateway?: string;
|
|
372
|
+
payment_status?: string;
|
|
373
|
+
delivery_fee?: number;
|
|
374
|
+
sales_tax?: number;
|
|
375
|
+
discount?: number;
|
|
376
|
+
coupon_id?: string | number | null;
|
|
377
|
+
status?: {
|
|
378
|
+
id: string | number;
|
|
379
|
+
name: string;
|
|
380
|
+
serial?: number;
|
|
381
|
+
color?: string;
|
|
382
|
+
};
|
|
383
|
+
products?: Array<{
|
|
384
|
+
id: string | number;
|
|
385
|
+
name: string;
|
|
386
|
+
pivot?: {
|
|
387
|
+
order_quantity: number;
|
|
388
|
+
unit_price: number;
|
|
389
|
+
subtotal: number;
|
|
390
|
+
};
|
|
391
|
+
}>;
|
|
392
|
+
shipping_address?: Record<string, any>;
|
|
393
|
+
billing_address?: Record<string, any>;
|
|
394
|
+
created_at?: string;
|
|
395
|
+
updated_at?: string;
|
|
396
|
+
[key: string]: any;
|
|
397
|
+
}
|
|
398
|
+
interface CreateOrderPayload {
|
|
399
|
+
products: Array<{
|
|
400
|
+
product_id: string | number;
|
|
401
|
+
order_quantity: number;
|
|
402
|
+
unit_price?: number;
|
|
403
|
+
subtotal?: number;
|
|
404
|
+
}>;
|
|
405
|
+
amount?: number;
|
|
406
|
+
total?: number;
|
|
407
|
+
coupon_id?: string | number;
|
|
408
|
+
discount?: number;
|
|
409
|
+
sales_tax?: number;
|
|
410
|
+
delivery_fee?: number;
|
|
411
|
+
customer_contact?: string;
|
|
412
|
+
customer_name?: string;
|
|
413
|
+
payment_gateway?: string;
|
|
414
|
+
use_wallet_points?: boolean;
|
|
415
|
+
shipping_address?: Record<string, any>;
|
|
416
|
+
billing_address?: Record<string, any>;
|
|
417
|
+
note?: string;
|
|
418
|
+
[key: string]: any;
|
|
419
|
+
}
|
|
420
|
+
interface VerifyCheckoutPayload {
|
|
421
|
+
amount: number;
|
|
422
|
+
products: Array<{
|
|
423
|
+
product_id: string | number;
|
|
424
|
+
order_quantity: number;
|
|
425
|
+
unit_price?: number;
|
|
426
|
+
}>;
|
|
427
|
+
billing_address?: Record<string, any>;
|
|
428
|
+
shipping_address?: Record<string, any>;
|
|
429
|
+
}
|
|
430
|
+
interface VerifyCheckoutResponse {
|
|
431
|
+
total_tax: number;
|
|
432
|
+
shipping_charge: number;
|
|
433
|
+
unavailable_products: Array<string | number>;
|
|
434
|
+
wallet_amount?: number;
|
|
435
|
+
wallet_currency?: number;
|
|
436
|
+
}
|
|
437
|
+
interface VerifyCouponPayload {
|
|
438
|
+
code: string;
|
|
439
|
+
sub_total: number;
|
|
440
|
+
}
|
|
441
|
+
interface CouponItem {
|
|
442
|
+
id: string | number;
|
|
443
|
+
code: string;
|
|
444
|
+
description?: string;
|
|
445
|
+
amount: number;
|
|
446
|
+
type?: 'fixed' | 'percentage' | 'free_shipping';
|
|
447
|
+
is_valid: boolean;
|
|
448
|
+
}
|
|
449
|
+
declare class CommerceClient {
|
|
450
|
+
private gatewayUrl;
|
|
451
|
+
private tenantId;
|
|
452
|
+
private fetchWithAuth;
|
|
453
|
+
private fetchFn;
|
|
454
|
+
constructor(options: {
|
|
455
|
+
gatewayUrl: string;
|
|
456
|
+
tenantId: string;
|
|
457
|
+
fetchWithAuth: (url: string, init?: RequestInit) => Promise<Response>;
|
|
458
|
+
fetchFn: typeof fetch;
|
|
459
|
+
});
|
|
460
|
+
/**
|
|
461
|
+
* List catalog products with search, category filtering, and pagination
|
|
462
|
+
*/
|
|
463
|
+
getProducts(params?: {
|
|
464
|
+
search?: string;
|
|
465
|
+
category?: string;
|
|
466
|
+
status?: string;
|
|
467
|
+
limit?: number;
|
|
468
|
+
page?: number;
|
|
469
|
+
orderBy?: string;
|
|
470
|
+
sortedBy?: 'ASC' | 'DESC' | 'asc' | 'desc';
|
|
471
|
+
language?: string;
|
|
472
|
+
type?: string;
|
|
473
|
+
}): Promise<ProductPaginator>;
|
|
474
|
+
/**
|
|
475
|
+
* Get a single product by slug or ID
|
|
476
|
+
*/
|
|
477
|
+
getProductBySlug(slug: string, language?: string): Promise<ProductItem>;
|
|
478
|
+
/**
|
|
479
|
+
* Create a new product (requires merchant/admin authentication)
|
|
480
|
+
*/
|
|
481
|
+
createProduct(product: Partial<ProductItem>): Promise<ProductItem>;
|
|
482
|
+
/**
|
|
483
|
+
* List store categories
|
|
484
|
+
*/
|
|
485
|
+
getCategories(params?: {
|
|
486
|
+
parent?: string | number;
|
|
487
|
+
limit?: number;
|
|
488
|
+
page?: number;
|
|
489
|
+
}): Promise<CategoryItem[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Create a new customer checkout order
|
|
492
|
+
*/
|
|
493
|
+
createOrder(payload: CreateOrderPayload): Promise<OrderItem>;
|
|
494
|
+
/**
|
|
495
|
+
* Verify checkout taxes, shipping fees, and product availability
|
|
496
|
+
*/
|
|
497
|
+
verifyCheckout(payload: VerifyCheckoutPayload): Promise<VerifyCheckoutResponse>;
|
|
498
|
+
/**
|
|
499
|
+
* Track order by tracking number
|
|
500
|
+
*/
|
|
501
|
+
trackOrder(trackingNumber: string): Promise<OrderItem>;
|
|
502
|
+
/**
|
|
503
|
+
* List customer orders (authenticated)
|
|
504
|
+
*/
|
|
505
|
+
getOrders(params?: {
|
|
506
|
+
limit?: number;
|
|
507
|
+
page?: number;
|
|
508
|
+
tracking_number?: string;
|
|
509
|
+
}): Promise<{
|
|
510
|
+
data: OrderItem[];
|
|
511
|
+
}>;
|
|
512
|
+
/**
|
|
513
|
+
* Verify and calculate discount for a promo coupon code
|
|
514
|
+
*/
|
|
515
|
+
verifyCoupon(payload: VerifyCouponPayload): Promise<{
|
|
516
|
+
is_valid: boolean;
|
|
517
|
+
coupon?: CouponItem;
|
|
518
|
+
}>;
|
|
519
|
+
/**
|
|
520
|
+
* Get store and commerce configuration settings
|
|
521
|
+
*/
|
|
522
|
+
getSettings(): Promise<Record<string, any>>;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
interface UploadResult {
|
|
526
|
+
id: string;
|
|
527
|
+
original: string;
|
|
528
|
+
thumbnail?: string;
|
|
529
|
+
filename: string;
|
|
530
|
+
size: number;
|
|
531
|
+
mimetype: string;
|
|
532
|
+
}
|
|
533
|
+
interface DocumentItem {
|
|
534
|
+
id: string;
|
|
535
|
+
name: string;
|
|
536
|
+
url: string;
|
|
537
|
+
size?: number;
|
|
538
|
+
mimeType?: string;
|
|
539
|
+
folderId?: string | null;
|
|
540
|
+
tenantId?: string;
|
|
541
|
+
createdAt?: string;
|
|
542
|
+
updatedAt?: string;
|
|
543
|
+
}
|
|
544
|
+
interface FolderItem {
|
|
545
|
+
id: string;
|
|
546
|
+
name: string;
|
|
547
|
+
parentId?: string | null;
|
|
548
|
+
tenantId?: string;
|
|
549
|
+
createdAt?: string;
|
|
550
|
+
}
|
|
551
|
+
declare class DocClient {
|
|
552
|
+
private gatewayUrl;
|
|
553
|
+
private tenantId;
|
|
554
|
+
private fetchWithAuth;
|
|
555
|
+
private fetchFn;
|
|
556
|
+
constructor(options: {
|
|
557
|
+
gatewayUrl: string;
|
|
558
|
+
tenantId: string;
|
|
559
|
+
fetchWithAuth: (url: string, init?: RequestInit) => Promise<Response>;
|
|
560
|
+
fetchFn: typeof fetch;
|
|
561
|
+
});
|
|
562
|
+
/**
|
|
563
|
+
* Upload one or more files to object storage (S3/MinIO) with automated thumbnailing
|
|
564
|
+
*/
|
|
565
|
+
upload(files: FormData | File | File[] | Blob | Blob[]): Promise<UploadResult[]>;
|
|
566
|
+
/**
|
|
567
|
+
* List documents with optional folder filtering and pagination
|
|
568
|
+
*/
|
|
569
|
+
list(params?: {
|
|
570
|
+
folderId?: string;
|
|
571
|
+
page?: number;
|
|
572
|
+
limit?: number;
|
|
573
|
+
}): Promise<DocumentItem[]>;
|
|
574
|
+
/**
|
|
575
|
+
* Get a single document record by ID
|
|
576
|
+
*/
|
|
577
|
+
get(id: string): Promise<DocumentItem>;
|
|
578
|
+
/**
|
|
579
|
+
* Delete a document by ID
|
|
580
|
+
*/
|
|
581
|
+
delete(id: string): Promise<{
|
|
582
|
+
success: boolean;
|
|
583
|
+
}>;
|
|
584
|
+
/**
|
|
585
|
+
* List document folders
|
|
586
|
+
*/
|
|
587
|
+
listFolders(): Promise<FolderItem[]>;
|
|
588
|
+
/**
|
|
589
|
+
* Create a new folder for organizing documents
|
|
590
|
+
*/
|
|
591
|
+
createFolder(name: string, parentId?: string): Promise<FolderItem>;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
interface SendSmsPayload {
|
|
595
|
+
to: string;
|
|
596
|
+
message: string;
|
|
597
|
+
from?: string;
|
|
598
|
+
provider?: string;
|
|
599
|
+
}
|
|
600
|
+
interface SmsResponse {
|
|
601
|
+
success: boolean;
|
|
602
|
+
messageId?: string;
|
|
603
|
+
status?: string;
|
|
604
|
+
error?: string;
|
|
605
|
+
}
|
|
606
|
+
interface SendEmailPayload {
|
|
607
|
+
to: string | string[];
|
|
608
|
+
subject: string;
|
|
609
|
+
html?: string;
|
|
610
|
+
text?: string;
|
|
611
|
+
templateId?: string;
|
|
612
|
+
templateData?: Record<string, any>;
|
|
613
|
+
localeCode?: string;
|
|
614
|
+
shopSlug?: string;
|
|
615
|
+
}
|
|
616
|
+
interface EmailResponse {
|
|
617
|
+
success: boolean;
|
|
618
|
+
messageId?: string;
|
|
619
|
+
status?: string;
|
|
620
|
+
error?: string;
|
|
621
|
+
}
|
|
622
|
+
interface SendPushPayload {
|
|
623
|
+
token?: string;
|
|
624
|
+
tokens?: string[];
|
|
625
|
+
topic?: string;
|
|
626
|
+
title: string;
|
|
627
|
+
body: string;
|
|
628
|
+
data?: Record<string, string>;
|
|
629
|
+
}
|
|
630
|
+
interface PushResponse {
|
|
631
|
+
success: boolean;
|
|
632
|
+
messageId?: string;
|
|
633
|
+
status?: string;
|
|
634
|
+
error?: string;
|
|
635
|
+
}
|
|
636
|
+
interface PushRegistrationPayload {
|
|
637
|
+
token: string;
|
|
638
|
+
userId?: string;
|
|
639
|
+
platform?: 'ios' | 'android' | 'web';
|
|
640
|
+
metadata?: Record<string, any>;
|
|
641
|
+
}
|
|
642
|
+
interface NotificationItem {
|
|
643
|
+
id: string;
|
|
644
|
+
userId?: string;
|
|
645
|
+
title: string;
|
|
646
|
+
message: string;
|
|
647
|
+
type?: string;
|
|
648
|
+
read?: boolean;
|
|
649
|
+
createdAt?: string;
|
|
650
|
+
}
|
|
651
|
+
declare class NotificationClient {
|
|
652
|
+
private gatewayUrl;
|
|
653
|
+
private tenantId;
|
|
654
|
+
private fetchWithAuth;
|
|
655
|
+
private fetchFn;
|
|
656
|
+
constructor(options: {
|
|
657
|
+
gatewayUrl: string;
|
|
658
|
+
tenantId: string;
|
|
659
|
+
fetchWithAuth: (url: string, init?: RequestInit) => Promise<Response>;
|
|
660
|
+
fetchFn: typeof fetch;
|
|
661
|
+
});
|
|
662
|
+
/**
|
|
663
|
+
* Send an SMS message via configured SMS gateways (Twilio / SMS API)
|
|
664
|
+
*/
|
|
665
|
+
sendSms(payload: SendSmsPayload): Promise<SmsResponse>;
|
|
666
|
+
/**
|
|
667
|
+
* Send an email or template email
|
|
668
|
+
*/
|
|
669
|
+
sendEmail(payload: SendEmailPayload): Promise<EmailResponse>;
|
|
670
|
+
/**
|
|
671
|
+
* Send Firebase Cloud Messaging (FCM) Push Notification
|
|
672
|
+
*/
|
|
673
|
+
sendPush(payload: SendPushPayload): Promise<PushResponse>;
|
|
674
|
+
/**
|
|
675
|
+
* Register a device push token for push notifications
|
|
676
|
+
*/
|
|
677
|
+
registerPushToken(payload: PushRegistrationPayload): Promise<{
|
|
678
|
+
success: boolean;
|
|
679
|
+
id?: string;
|
|
680
|
+
}>;
|
|
681
|
+
/**
|
|
682
|
+
* Get recent in-app notifications
|
|
683
|
+
*/
|
|
684
|
+
list(params?: {
|
|
685
|
+
page?: number;
|
|
686
|
+
limit?: number;
|
|
687
|
+
}): Promise<NotificationItem[]>;
|
|
688
|
+
}
|
|
689
|
+
|
|
298
690
|
declare class EntityQueryBuilder<T = Record<string, any>> {
|
|
299
691
|
private gatewayUrl;
|
|
300
692
|
private tenantId;
|
|
@@ -468,10 +860,19 @@ declare class Zone4CodeClient {
|
|
|
468
860
|
readonly tenantId: string;
|
|
469
861
|
readonly auth: AuthClient;
|
|
470
862
|
readonly schema: SchemaClient;
|
|
863
|
+
readonly doc: DocClient;
|
|
864
|
+
readonly notification: NotificationClient;
|
|
865
|
+
readonly commerce: CommerceClient;
|
|
471
866
|
private storage;
|
|
472
867
|
private fetchFn;
|
|
473
868
|
private currentLanguage;
|
|
474
|
-
constructor(config
|
|
869
|
+
constructor(config?: Zone4CodeConfig);
|
|
870
|
+
readonly generic: {
|
|
871
|
+
from: <T = Record<string, any>>(typeName: string) => EntityQueryBuilder<T>;
|
|
872
|
+
entities: <T = Record<string, any>>(typeName: string) => EntityQueryBuilder<T>;
|
|
873
|
+
schema: SchemaClient;
|
|
874
|
+
getMe: () => Promise<UserProfileWithWallet>;
|
|
875
|
+
};
|
|
475
876
|
/**
|
|
476
877
|
* Set the active default language for API requests (e.g., 'en', 'fr', 'ar', or '*' for raw)
|
|
477
878
|
*/
|
|
@@ -517,4 +918,4 @@ declare class MemoryStorage implements StorageAdapter {
|
|
|
517
918
|
}
|
|
518
919
|
declare function getDefaultStorage(): StorageAdapter;
|
|
519
920
|
|
|
520
|
-
export { AuthClient, type AuthResponse, type AuthUser, type EntityListResponse, EntityQueryBuilder, type EntityRecord, type EntityRelationPayload, type EntityRelationRecord, type EntityReplaceRelationsPayload, type EntityRevision, type EntitySchemaDefinition, type FilterOperator, type GetEntityOptions, MemoryStorage, SchemaClient, type SchemaProperty, type StorageAdapter, type Translatable, type UserProfileWithWallet, Zone4CodeClient, type Zone4CodeConfig, createClient, createClient as default, getDefaultStorage };
|
|
921
|
+
export { AuthClient, type AuthResponse, type AuthUser, type CategoryItem, CommerceClient, type CouponItem, type CreateOrderPayload, DocClient, type DocumentItem, type EmailResponse, type EntityListResponse, EntityQueryBuilder, type EntityRecord, type EntityRelationPayload, type EntityRelationRecord, type EntityReplaceRelationsPayload, type EntityRevision, type EntitySchemaDefinition, type FilterOperator, type FolderItem, type GetEntityOptions, MemoryStorage, NotificationClient, type NotificationItem, type OrderItem, type ProductItem, type ProductPaginator, type PushRegistrationPayload, type PushResponse, SchemaClient, type SchemaProperty, type SendEmailPayload, type SendPushPayload, type SendSmsPayload, type SmsResponse, type StorageAdapter, type Translatable, type UploadResult, type UserProfileWithWallet, type VerifyCheckoutPayload, type VerifyCheckoutResponse, type VerifyCouponPayload, Zone4CodeClient, type Zone4CodeConfig, createClient, createClient as default, getDefaultStorage };
|