@kasuvia/sdk 0.0.2 → 0.0.4

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.
Files changed (67) hide show
  1. package/dist/hooks/index.d.mts +429 -0
  2. package/dist/hooks/index.d.ts +429 -0
  3. package/dist/hooks/index.js +3073 -0
  4. package/dist/hooks/index.js.map +1 -0
  5. package/dist/hooks/index.mjs +2962 -0
  6. package/dist/hooks/index.mjs.map +1 -0
  7. package/dist/index.d.mts +250 -1161
  8. package/dist/index.d.ts +250 -1161
  9. package/dist/index.js +1544 -2359
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +1527 -2258
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/sdk-context-Cy51kEKT.d.mts +565 -0
  14. package/dist/sdk-context-Cy51kEKT.d.ts +565 -0
  15. package/package.json +6 -2
  16. package/src/config/index.ts +10 -91
  17. package/src/constants.ts +13 -0
  18. package/src/context/sdk-context.tsx +70 -0
  19. package/src/graphql/collections.graphql.ts +2 -10
  20. package/src/graphql/products.graphql.ts +215 -65
  21. package/src/graphql/wishlist.graphql.ts +7 -6
  22. package/src/hooks/index.ts +2 -0
  23. package/src/hooks/use-auth.ts +82 -158
  24. package/src/hooks/use-bespoke-availability.ts +25 -8
  25. package/src/hooks/use-cart.ts +222 -119
  26. package/src/hooks/use-cms.ts +179 -86
  27. package/src/hooks/use-collections.ts +52 -15
  28. package/src/hooks/use-consultation-stream.ts +4 -3
  29. package/src/hooks/use-consultations.ts +120 -51
  30. package/src/hooks/use-countries.ts +35 -13
  31. package/src/hooks/use-currencies.ts +26 -13
  32. package/src/hooks/use-google-translate.ts +22 -8
  33. package/src/hooks/use-languages.ts +40 -20
  34. package/src/hooks/use-mobile.ts +23 -0
  35. package/src/hooks/use-order-stream.ts +9 -5
  36. package/src/hooks/use-orders.ts +99 -44
  37. package/src/hooks/use-payment.ts +108 -40
  38. package/src/hooks/use-products.ts +251 -53
  39. package/src/hooks/use-service-booking.ts +152 -90
  40. package/src/hooks/use-states.ts +35 -15
  41. package/src/hooks/use-wishlist.ts +92 -91
  42. package/src/index.ts +26 -30
  43. package/src/services/auth.service.ts +209 -167
  44. package/src/services/bespoke.service.ts +12 -4
  45. package/src/services/cart.service.ts +172 -70
  46. package/src/services/cms.service.ts +70 -35
  47. package/src/services/collection.service.ts +22 -5
  48. package/src/services/config.service.ts +34 -14
  49. package/src/services/consultation.service.ts +72 -18
  50. package/src/services/logistics.service.ts +35 -11
  51. package/src/services/notifications.service.ts +27 -12
  52. package/src/services/order.service.ts +74 -15
  53. package/src/services/payment.service.ts +86 -31
  54. package/src/services/product.service.ts +279 -39
  55. package/src/services/service-booking.service.ts +98 -26
  56. package/src/services/wishlist.service.ts +69 -25
  57. package/src/types/auth/index.ts +6 -4
  58. package/src/types/business/index.ts +7 -2
  59. package/src/types/payments/index.ts +3 -3
  60. package/src/types/services/index.ts +2 -5
  61. package/src/types/store/index.ts +38 -3
  62. package/src/utils/error-handler.ts +10 -5
  63. package/src/utils/storage.ts +48 -26
  64. package/src/utils/validators.ts +85 -0
  65. package/src/client/authClient.ts +0 -135
  66. package/src/client/graphqlClient.ts +0 -53
  67. package/src/client/httpClient.ts +0 -298
@@ -0,0 +1,13 @@
1
+ /**
2
+ * SDK Constants
3
+ *
4
+ * Centralized constants to avoid hardcoded strings across the codebase.
5
+ */
6
+
7
+ export const STORAGE_KEYS = {
8
+ ACCESS_TOKEN: 'kasuvia_access_token',
9
+ REFRESH_TOKEN: 'kasuvia_refresh_token',
10
+ CHECKOUT_STATE: 'kasuvia_checkout_state',
11
+ ORDERS_LINKED: 'kasuvia_orders_linked',
12
+ STOREFRONT_STATE: 'storefront_state_v3',
13
+ } as const;
@@ -0,0 +1,70 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * SdkContext
5
+ *
6
+ * Provides SdkConfig and the current access token to all SDK hooks
7
+ * in the component tree, so individual hooks do not require explicit
8
+ * config/accessToken parameters when called from client components.
9
+ *
10
+ * Usage in storefront:
11
+ * // In your AuthProvider or root layout:
12
+ * <SdkProvider config={sdkConfig} accessToken={accessToken}>
13
+ * {children}
14
+ * </SdkProvider>
15
+ *
16
+ * // In any client component:
17
+ * const { items, addItem } = useCart() // no args needed
18
+ */
19
+
20
+ import React, { createContext, useContext, type ReactNode } from 'react';
21
+ import type { SdkConfig } from '../config';
22
+
23
+ export interface SdkContextValue {
24
+ config: SdkConfig;
25
+ accessToken: string | null;
26
+ }
27
+
28
+ const SdkContext = createContext<SdkContextValue | null>(null);
29
+
30
+ export interface SdkProviderProps {
31
+ config: SdkConfig;
32
+ accessToken: string | null;
33
+ children: ReactNode;
34
+ }
35
+
36
+ export function SdkProvider({ config, accessToken, children }: SdkProviderProps) {
37
+ return (
38
+ <SdkContext.Provider value={{ config, accessToken }}>
39
+ {children}
40
+ </SdkContext.Provider>
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Returns the SdkContext value, or null if no SdkProvider is present.
46
+ * SDK hooks use this internally to fall back to context when explicit
47
+ * parameters are not provided.
48
+ */
49
+ export function useSdkContext(): SdkContextValue | null {
50
+ return useContext(SdkContext);
51
+ }
52
+
53
+ /**
54
+ * Resolves config and accessToken from explicit arguments or SdkContext.
55
+ * Throws if neither source is available.
56
+ */
57
+ export function resolveHookArgs(
58
+ explicitConfig: SdkConfig | undefined,
59
+ explicitToken: string | null | undefined,
60
+ ctx: SdkContextValue | null
61
+ ): { config: SdkConfig; accessToken: string | null } {
62
+ const config = explicitConfig ?? ctx?.config;
63
+ if (!config) {
64
+ throw new Error(
65
+ '[kasuvia-sdk] No SdkConfig found. Either pass config explicitly or wrap your app with <SdkProvider config={...}>.'
66
+ );
67
+ }
68
+ const accessToken = explicitToken !== undefined ? explicitToken : (ctx?.accessToken ?? null);
69
+ return { config, accessToken };
70
+ }
@@ -14,11 +14,7 @@ export const GET_STOREFRONT_COLLECTIONS = gql`
14
14
  description
15
15
  collection_type
16
16
  rules
17
- image {
18
- id
19
- url
20
- alt
21
- }
17
+ image
22
18
  status
23
19
  sort_order
24
20
  created_at
@@ -42,11 +38,7 @@ export const GET_STOREFRONT_COLLECTION_BY_SLUG = gql`
42
38
  description
43
39
  collection_type
44
40
  rules
45
- image {
46
- id
47
- url
48
- alt
49
- }
41
+ image
50
42
  status
51
43
  sort_order
52
44
  created_at
@@ -29,11 +29,10 @@ export const GET_STOREFRONT_PRODUCTS = gql`
29
29
  is_bespoke
30
30
  base_price
31
31
  currency
32
- images {
33
- id
34
- url
35
- alt
36
- }
32
+ sale_price
33
+ sale_start
34
+ sale_end
35
+ images
37
36
  tags
38
37
  custom_fields {
39
38
  label
@@ -58,11 +57,7 @@ export const GET_STOREFRONT_PRODUCTS = gql`
58
57
  sku
59
58
  attributes
60
59
  price
61
- images {
62
- id
63
- url
64
- alt
65
- }
60
+ images
66
61
  weight_kg
67
62
  is_active
68
63
  inventory {
@@ -156,11 +151,7 @@ export const GET_STOREFRONT_PRODUCT_BY_SLUG = gql`
156
151
  sku
157
152
  attributes
158
153
  price
159
- images {
160
- id
161
- url
162
- alt
163
- }
154
+ images
164
155
  weight_kg
165
156
  is_active
166
157
  inventory {
@@ -189,11 +180,7 @@ export const GET_STOREFRONT_PRODUCT_BY_SLUG = gql`
189
180
  description
190
181
  collection_type
191
182
  rules
192
- image {
193
- id
194
- url
195
- alt
196
- }
183
+ image
197
184
  status
198
185
  sort_order
199
186
  created_at
@@ -221,11 +208,10 @@ export const GET_STOREFRONT_LATEST = gql`
221
208
  is_bespoke
222
209
  base_price
223
210
  currency
224
- images {
225
- id
226
- url
227
- alt
228
- }
211
+ sale_price
212
+ sale_start
213
+ sale_end
214
+ images
229
215
  tags
230
216
  custom_fields {
231
217
  label
@@ -250,11 +236,7 @@ export const GET_STOREFRONT_LATEST = gql`
250
236
  sku
251
237
  attributes
252
238
  price
253
- images {
254
- id
255
- url
256
- alt
257
- }
239
+ images
258
240
  weight_kg
259
241
  is_active
260
242
  inventory {
@@ -320,11 +302,10 @@ export const GET_STOREFRONT_POPULAR = gql`
320
302
  is_bespoke
321
303
  base_price
322
304
  currency
323
- images {
324
- id
325
- url
326
- alt
327
- }
305
+ sale_price
306
+ sale_start
307
+ sale_end
308
+ images
328
309
  tags
329
310
  custom_fields {
330
311
  label
@@ -349,11 +330,7 @@ export const GET_STOREFRONT_POPULAR = gql`
349
330
  sku
350
331
  attributes
351
332
  price
352
- images {
353
- id
354
- url
355
- alt
356
- }
333
+ images
357
334
  weight_kg
358
335
  is_active
359
336
  inventory {
@@ -419,11 +396,10 @@ export const GET_STOREFRONT_FEATURED = gql`
419
396
  is_bespoke
420
397
  base_price
421
398
  currency
422
- images {
423
- id
424
- url
425
- alt
426
- }
399
+ sale_price
400
+ sale_start
401
+ sale_end
402
+ images
427
403
  tags
428
404
  custom_fields {
429
405
  label
@@ -448,11 +424,7 @@ export const GET_STOREFRONT_FEATURED = gql`
448
424
  sku
449
425
  attributes
450
426
  price
451
- images {
452
- id
453
- url
454
- alt
455
- }
427
+ images
456
428
  weight_kg
457
429
  is_active
458
430
  inventory {
@@ -518,11 +490,104 @@ export const GET_STOREFRONT_NEW = gql`
518
490
  is_bespoke
519
491
  base_price
520
492
  currency
521
- images {
493
+ sale_price
494
+ sale_start
495
+ sale_end
496
+ images
497
+ tags
498
+ custom_fields {
499
+ label
500
+ unit
501
+ required
502
+ }
503
+ is_published
504
+ is_featured
505
+ is_popular
506
+ is_new
507
+ is_temporary
508
+ digital_file_key
509
+ download_limit
510
+ download_expires_at
511
+ weight_kg
512
+ length_cm
513
+ width_cm
514
+ height_cm
515
+ variants {
522
516
  id
523
- url
524
- alt
517
+ product_id
518
+ sku
519
+ attributes
520
+ price
521
+ images
522
+ weight_kg
523
+ is_active
524
+ inventory {
525
+ id
526
+ product_id
527
+ variant_id
528
+ quantity
529
+ reserved
530
+ available
531
+ is_in_stock
532
+ is_low_stock
533
+ reorder_point
534
+ reorder_quantity
535
+ track_quantity
536
+ allow_backorder
537
+ updated_at
538
+ }
539
+ created_at
540
+ updated_at
541
+ }
542
+ collections {
543
+ id
544
+ business_id
545
+ name
546
+ slug
547
+ description
548
+ collection_type
549
+ rules
550
+ image {
551
+ id
552
+ url
553
+ alt
554
+ }
555
+ status
556
+ sort_order
557
+ created_at
558
+ updated_at
525
559
  }
560
+ created_at
561
+ updated_at
562
+ }
563
+ total
564
+ page
565
+ page_size
566
+ total_pages
567
+ }
568
+ }
569
+ `
570
+
571
+ export const GET_STOREFRONT_ON_SALE = gql`
572
+ query GetStorefrontOnSale($page: Int = 1, $pageSize: Int = 4) {
573
+ storefront_on_sale(page: $page, pageSize: $pageSize) {
574
+ items {
575
+ id
576
+ business_id
577
+ name
578
+ slug
579
+ description
580
+ brand
581
+ product_type
582
+ requires_shipping
583
+ is_consumable
584
+ is_bespoke
585
+ base_price
586
+ currency
587
+ sale_price
588
+ sale_start
589
+ sale_end
590
+ images
526
591
  tags
527
592
  custom_fields {
528
593
  label
@@ -547,11 +612,101 @@ export const GET_STOREFRONT_NEW = gql`
547
612
  sku
548
613
  attributes
549
614
  price
550
- images {
615
+ images
616
+ weight_kg
617
+ is_active
618
+ inventory {
619
+ id
620
+ product_id
621
+ variant_id
622
+ quantity
623
+ reserved
624
+ available
625
+ is_in_stock
626
+ is_low_stock
627
+ reorder_point
628
+ reorder_quantity
629
+ track_quantity
630
+ allow_backorder
631
+ updated_at
632
+ }
633
+ created_at
634
+ updated_at
635
+ }
636
+ collections {
637
+ id
638
+ business_id
639
+ name
640
+ slug
641
+ description
642
+ collection_type
643
+ rules
644
+ image {
551
645
  id
552
646
  url
553
647
  alt
554
648
  }
649
+ status
650
+ sort_order
651
+ created_at
652
+ updated_at
653
+ }
654
+ created_at
655
+ updated_at
656
+ }
657
+ total
658
+ page
659
+ page_size
660
+ total_pages
661
+ }
662
+ }
663
+ `
664
+
665
+ export const GET_STOREFRONT_LOW_STOCK = gql`
666
+ query GetStorefrontLowStock($page: Int = 1, $pageSize: Int = 4) {
667
+ storefront_low_stock(page: $page, pageSize: $pageSize) {
668
+ items {
669
+ id
670
+ business_id
671
+ name
672
+ slug
673
+ description
674
+ brand
675
+ product_type
676
+ requires_shipping
677
+ is_consumable
678
+ is_bespoke
679
+ base_price
680
+ currency
681
+ sale_price
682
+ sale_start
683
+ sale_end
684
+ images
685
+ tags
686
+ custom_fields {
687
+ label
688
+ unit
689
+ required
690
+ }
691
+ is_published
692
+ is_featured
693
+ is_popular
694
+ is_new
695
+ is_temporary
696
+ digital_file_key
697
+ download_limit
698
+ download_expires_at
699
+ weight_kg
700
+ length_cm
701
+ width_cm
702
+ height_cm
703
+ variants {
704
+ id
705
+ product_id
706
+ sku
707
+ attributes
708
+ price
709
+ images
555
710
  weight_kg
556
711
  is_active
557
712
  inventory {
@@ -625,11 +780,10 @@ export const GET_STOREFRONT_RECOMMENDED = gql`
625
780
  is_bespoke
626
781
  base_price
627
782
  currency
628
- images {
629
- id
630
- url
631
- alt
632
- }
783
+ sale_price
784
+ sale_start
785
+ sale_end
786
+ images
633
787
  tags
634
788
  custom_fields {
635
789
  label
@@ -654,11 +808,7 @@ export const GET_STOREFRONT_RECOMMENDED = gql`
654
808
  sku
655
809
  attributes
656
810
  price
657
- images {
658
- id
659
- url
660
- alt
661
- }
811
+ images
662
812
  weight_kg
663
813
  is_active
664
814
  inventory {
@@ -707,4 +857,4 @@ export const GET_STOREFRONT_RECOMMENDED = gql`
707
857
  }
708
858
  }
709
859
  `
710
-
860
+
@@ -3,9 +3,9 @@
3
3
  */
4
4
  import { gql } from 'graphql-request'
5
5
 
6
- export const GET_WISHLIST = gql`
7
- query GetWishlist($page: Int = 1, $pageSize: Int = 20) {
8
- wishlist(page: $page, pageSize: $pageSize) {
6
+ export const GET_STOREFRONT_WISHLIST = gql`
7
+ query GetStorefrontWishlist($page: Int = 1, $pageSize: Int = 20) {
8
+ storefront_wishlist(page: $page, pageSize: $pageSize) {
9
9
  items {
10
10
  id
11
11
  product_id
@@ -14,6 +14,7 @@ export const GET_WISHLIST = gql`
14
14
  product_name
15
15
  product_slug
16
16
  product_price
17
+ currency
17
18
  product_image
18
19
  }
19
20
  total
@@ -24,9 +25,9 @@ export const GET_WISHLIST = gql`
24
25
  }
25
26
  `
26
27
 
27
- export const CHECK_IN_WISHLIST = gql`
28
- query CheckInWishlist($productId: String!) {
29
- check_in_wishlist(productId: $productId) {
28
+ export const CHECK_IN_STOREFRONT_WISHLIST = gql`
29
+ query CheckInStorefrontWishlist($productId: String!) {
30
+ check_in_storefront_wishlist(productId: $productId) {
30
31
  in_wishlist
31
32
  }
32
33
  }
@@ -20,7 +20,9 @@ export * from './use-consultations'
20
20
  export * from './use-consultation-stream'
21
21
  export * from './use-order-stream'
22
22
  export * from './use-is-mounted'
23
+ export * from './use-mobile'
23
24
  export * from './use-google-translate'
24
25
  export * from './use-payment'
25
26
  export * from './use-cms'
27
+ export * from '../context/sdk-context'
26
28