@back23/promptly-sdk 1.1.0 → 1.3.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/dist/index.js CHANGED
@@ -27,6 +27,38 @@ __export(index_exports, {
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/http.ts
30
+ var DEFAULT_META = {
31
+ current_page: 1,
32
+ last_page: 1,
33
+ per_page: 15,
34
+ total: 0,
35
+ from: null,
36
+ to: null
37
+ };
38
+ function normalizeListResponse(response) {
39
+ if (response == null) {
40
+ return { data: [], meta: { ...DEFAULT_META } };
41
+ }
42
+ if (Array.isArray(response)) {
43
+ return {
44
+ data: response,
45
+ meta: { ...DEFAULT_META, total: response.length, from: response.length > 0 ? 1 : null, to: response.length > 0 ? response.length : null }
46
+ };
47
+ }
48
+ if (typeof response === "object") {
49
+ const data = Array.isArray(response.data) ? response.data : [];
50
+ const meta = {
51
+ current_page: response.meta?.current_page ?? response.current_page ?? 1,
52
+ last_page: response.meta?.last_page ?? response.last_page ?? 1,
53
+ per_page: response.meta?.per_page ?? response.per_page ?? 15,
54
+ total: response.meta?.total ?? response.total ?? data.length,
55
+ from: response.meta?.from ?? response.from ?? (data.length > 0 ? 1 : null),
56
+ to: response.meta?.to ?? response.to ?? (data.length > 0 ? data.length : null)
57
+ };
58
+ return { data, meta };
59
+ }
60
+ return { data: [], meta: { ...DEFAULT_META } };
61
+ }
30
62
  var PromptlyError = class extends Error {
31
63
  constructor(message, status, errors) {
32
64
  super(message);
@@ -134,6 +166,14 @@ var HttpClient = class {
134
166
  get(endpoint, params) {
135
167
  return this.request(endpoint, { method: "GET", params });
136
168
  }
169
+ /**
170
+ * GET request for list endpoints - ALWAYS returns normalized ListResponse
171
+ * Guarantees: data is always an array, meta is always present
172
+ */
173
+ async getList(endpoint, params) {
174
+ const response = await this.request(endpoint, { method: "GET", params });
175
+ return normalizeListResponse(response);
176
+ }
137
177
  /**
138
178
  * POST request
139
179
  */
@@ -317,9 +357,10 @@ var BoardsResource = class {
317
357
  // ============================================
318
358
  /**
319
359
  * List all boards
360
+ * @returns ListResponse with data array (always defined) and pagination meta
320
361
  */
321
362
  async list(params) {
322
- return this.http.get("/public/boards", params);
363
+ return this.http.getList("/public/boards", params);
323
364
  }
324
365
  /**
325
366
  * Get board by ID or slug
@@ -332,9 +373,10 @@ var BoardsResource = class {
332
373
  // ============================================
333
374
  /**
334
375
  * List posts in a board
376
+ * @returns ListResponse with data array and pagination meta
335
377
  */
336
378
  async listPosts(boardIdOrSlug, params) {
337
- return this.http.get(`/public/boards/${boardIdOrSlug}/posts`, params);
379
+ return this.http.getList(`/public/boards/${boardIdOrSlug}/posts`, params);
338
380
  }
339
381
  /**
340
382
  * Get post by ID
@@ -368,9 +410,11 @@ var BoardsResource = class {
368
410
  // ============================================
369
411
  /**
370
412
  * List comments for a post
413
+ * @returns Array of comments (always an array, never null/undefined)
371
414
  */
372
415
  async listComments(postId) {
373
- return this.http.get(`/public/posts/${postId}/comments`);
416
+ const response = await this.http.getList(`/public/posts/${postId}/comments`);
417
+ return response.data;
374
418
  }
375
419
  /**
376
420
  * Create comment on a post
@@ -399,9 +443,10 @@ var BlogResource = class {
399
443
  }
400
444
  /**
401
445
  * List blog posts
446
+ * @returns ListResponse with data array (always defined) and pagination meta
402
447
  */
403
448
  async list(params) {
404
- return this.http.get("/public/blog", params);
449
+ return this.http.getList("/public/blog", params);
405
450
  }
406
451
  /**
407
452
  * Get blog post by slug
@@ -417,9 +462,10 @@ var BlogResource = class {
417
462
  }
418
463
  /**
419
464
  * Get featured blog posts
465
+ * @returns Array of featured posts (always an array, never null/undefined)
420
466
  */
421
467
  async featured(limit = 5) {
422
- const response = await this.http.get("/public/blog", {
468
+ const response = await this.http.getList("/public/blog", {
423
469
  per_page: limit,
424
470
  featured: true
425
471
  });
@@ -427,42 +473,49 @@ var BlogResource = class {
427
473
  }
428
474
  /**
429
475
  * Get blog posts by category
476
+ * @returns ListResponse with data array and pagination meta
430
477
  */
431
478
  async byCategory(category, params) {
432
- return this.http.get("/public/blog", {
479
+ return this.http.getList("/public/blog", {
433
480
  ...params,
434
481
  category
435
482
  });
436
483
  }
437
484
  /**
438
485
  * Get blog posts by tag
486
+ * @returns ListResponse with data array and pagination meta
439
487
  */
440
488
  async byTag(tag, params) {
441
- return this.http.get("/public/blog", {
489
+ return this.http.getList("/public/blog", {
442
490
  ...params,
443
491
  tag
444
492
  });
445
493
  }
446
494
  /**
447
495
  * Search blog posts
496
+ * @returns ListResponse with data array and pagination meta
448
497
  */
449
498
  async search(query, params) {
450
- return this.http.get("/public/blog", {
499
+ return this.http.getList("/public/blog", {
451
500
  ...params,
452
501
  search: query
453
502
  });
454
503
  }
455
504
  /**
456
505
  * Get blog categories
506
+ * @returns Array of category names (always an array)
457
507
  */
458
508
  async categories() {
459
- return this.http.get("/public/blog/categories");
509
+ const response = await this.http.get("/public/blog/categories");
510
+ return Array.isArray(response) ? response : response?.data ?? [];
460
511
  }
461
512
  /**
462
513
  * Get blog tags
514
+ * @returns Array of tag names (always an array)
463
515
  */
464
516
  async tags() {
465
- return this.http.get("/public/blog/tags");
517
+ const response = await this.http.get("/public/blog/tags");
518
+ return Array.isArray(response) ? response : response?.data ?? [];
466
519
  }
467
520
  };
468
521
 
@@ -473,9 +526,10 @@ var FormsResource = class {
473
526
  }
474
527
  /**
475
528
  * List all forms
529
+ * @returns ListResponse with data array and pagination meta
476
530
  */
477
531
  async list(params) {
478
- return this.http.get("/public/forms", params);
532
+ return this.http.getList("/public/forms", params);
479
533
  }
480
534
  /**
481
535
  * Get form by ID or slug
@@ -494,9 +548,10 @@ var FormsResource = class {
494
548
  // ============================================
495
549
  /**
496
550
  * Get my form submissions
551
+ * @returns ListResponse with data array and pagination meta
497
552
  */
498
553
  async mySubmissions(params) {
499
- return this.http.get("/form-submissions", params);
554
+ return this.http.getList("/form-submissions", params);
500
555
  }
501
556
  /**
502
557
  * Get specific submission
@@ -516,9 +571,10 @@ var ShopResource = class {
516
571
  // ============================================
517
572
  /**
518
573
  * List products
574
+ * @returns ListResponse with data array and pagination meta
519
575
  */
520
576
  async listProducts(params) {
521
- return this.http.get("/public/products", params);
577
+ return this.http.getList("/public/products", params);
522
578
  }
523
579
  /**
524
580
  * Get product by ID or slug
@@ -528,9 +584,10 @@ var ShopResource = class {
528
584
  }
529
585
  /**
530
586
  * Get featured products
587
+ * @returns Array of featured products (always an array)
531
588
  */
532
589
  async featuredProducts(limit = 8) {
533
- const response = await this.http.get("/public/products", {
590
+ const response = await this.http.getList("/public/products", {
534
591
  per_page: limit,
535
592
  is_featured: true
536
593
  });
@@ -538,9 +595,10 @@ var ShopResource = class {
538
595
  }
539
596
  /**
540
597
  * Search products
598
+ * @returns ListResponse with data array and pagination meta
541
599
  */
542
600
  async searchProducts(query, params) {
543
- return this.http.get("/public/products", {
601
+ return this.http.getList("/public/products", {
544
602
  ...params,
545
603
  search: query
546
604
  });
@@ -550,9 +608,11 @@ var ShopResource = class {
550
608
  // ============================================
551
609
  /**
552
610
  * List product categories
611
+ * @returns Array of categories (always an array)
553
612
  */
554
613
  async listCategories() {
555
- return this.http.get("/public/categories");
614
+ const response = await this.http.getList("/public/categories");
615
+ return response.data;
556
616
  }
557
617
  /**
558
618
  * Get category by ID or slug
@@ -562,9 +622,10 @@ var ShopResource = class {
562
622
  }
563
623
  /**
564
624
  * Get products in category
625
+ * @returns ListResponse with data array and pagination meta
565
626
  */
566
627
  async categoryProducts(categoryIdOrSlug, params) {
567
- return this.http.get(`/public/categories/${categoryIdOrSlug}/products`, params);
628
+ return this.http.getList(`/public/categories/${categoryIdOrSlug}/products`, params);
568
629
  }
569
630
  // ============================================
570
631
  // Cart
@@ -604,9 +665,10 @@ var ShopResource = class {
604
665
  // ============================================
605
666
  /**
606
667
  * List my orders
668
+ * @returns ListResponse with data array and pagination meta
607
669
  */
608
670
  async listOrders(params) {
609
- return this.http.get("/orders", params);
671
+ return this.http.getList("/orders", params);
610
672
  }
611
673
  /**
612
674
  * Get order by ID or order number
@@ -667,9 +729,11 @@ var ShopResource = class {
667
729
  }
668
730
  /**
669
731
  * Get available coupons for current user
732
+ * @returns Array of coupons (always an array)
670
733
  */
671
734
  async myCoupons() {
672
- return this.http.get("/coupons");
735
+ const response = await this.http.getList("/coupons");
736
+ return response.data;
673
737
  }
674
738
  };
675
739
 
@@ -725,6 +789,7 @@ var EntitiesResource = class {
725
789
  // ============================================
726
790
  /**
727
791
  * List all active custom entities
792
+ * @returns Array of entities (always an array)
728
793
  *
729
794
  * @example
730
795
  * ```typescript
@@ -733,7 +798,8 @@ var EntitiesResource = class {
733
798
  * ```
734
799
  */
735
800
  async list() {
736
- return this.http.get("/public/entities");
801
+ const response = await this.http.getList("/public/entities");
802
+ return response.data;
737
803
  }
738
804
  /**
739
805
  * Get entity schema by slug
@@ -752,6 +818,7 @@ var EntitiesResource = class {
752
818
  // ============================================
753
819
  /**
754
820
  * List records for an entity
821
+ * @returns ListResponse with data array and pagination meta
755
822
  *
756
823
  * @example
757
824
  * ```typescript
@@ -772,7 +839,7 @@ var EntitiesResource = class {
772
839
  * ```
773
840
  */
774
841
  async listRecords(slug, params) {
775
- return this.http.get(`/public/entities/${slug}`, params);
842
+ return this.http.getList(`/public/entities/${slug}`, params);
776
843
  }
777
844
  /**
778
845
  * Get a single record by ID
@@ -891,6 +958,110 @@ var EntitiesResource = class {
891
958
  }
892
959
  };
893
960
 
961
+ // src/resources/reservation.ts
962
+ var ReservationResource = class {
963
+ constructor(http) {
964
+ this.http = http;
965
+ }
966
+ // ============================================
967
+ // Public Endpoints
968
+ // ============================================
969
+ /**
970
+ * Get reservation settings
971
+ * @returns Reservation settings for the tenant
972
+ */
973
+ async getSettings() {
974
+ return this.http.get("/public/reservations/settings");
975
+ }
976
+ /**
977
+ * List available services
978
+ * @returns Array of services (always an array)
979
+ */
980
+ async listServices() {
981
+ const response = await this.http.getList("/public/reservations/services");
982
+ return response.data;
983
+ }
984
+ /**
985
+ * List available staff members
986
+ * @param serviceId - Optional: filter staff by service
987
+ * @returns Array of staff members (always an array)
988
+ */
989
+ async listStaff(serviceId) {
990
+ const params = serviceId ? { service_id: serviceId } : void 0;
991
+ const response = await this.http.getList("/public/reservations/staffs", params);
992
+ return response.data;
993
+ }
994
+ /**
995
+ * Get available dates for booking
996
+ * @returns Array of available date strings (YYYY-MM-DD)
997
+ */
998
+ async getAvailableDates(params) {
999
+ const response = await this.http.get("/public/reservations/dates", params);
1000
+ return Array.isArray(response) ? response : response?.data ?? [];
1001
+ }
1002
+ /**
1003
+ * Get available time slots for a specific date
1004
+ * @returns Array of available slots (always an array)
1005
+ */
1006
+ async getAvailableSlots(params) {
1007
+ const response = await this.http.get("/public/reservations/slots", params);
1008
+ return Array.isArray(response) ? response : response?.data ?? [];
1009
+ }
1010
+ // ============================================
1011
+ // Protected Endpoints (requires auth)
1012
+ // ============================================
1013
+ /**
1014
+ * Create a new reservation
1015
+ * @returns Created reservation with payment info
1016
+ */
1017
+ async create(data) {
1018
+ return this.http.post("/reservations", data);
1019
+ }
1020
+ /**
1021
+ * List my reservations
1022
+ * @returns ListResponse with reservations and pagination meta
1023
+ */
1024
+ async list(params) {
1025
+ return this.http.getList("/reservations", params);
1026
+ }
1027
+ /**
1028
+ * Get upcoming reservations
1029
+ * @returns Array of upcoming reservations
1030
+ */
1031
+ async upcoming(limit = 10) {
1032
+ const response = await this.http.getList("/reservations", {
1033
+ upcoming: true,
1034
+ per_page: limit
1035
+ });
1036
+ return response.data;
1037
+ }
1038
+ /**
1039
+ * Get past reservations
1040
+ * @returns Array of past reservations
1041
+ */
1042
+ async past(limit = 10) {
1043
+ const response = await this.http.getList("/reservations", {
1044
+ past: true,
1045
+ per_page: limit
1046
+ });
1047
+ return response.data;
1048
+ }
1049
+ /**
1050
+ * Get reservation by reservation number
1051
+ */
1052
+ async get(reservationNumber) {
1053
+ return this.http.get(`/reservations/${reservationNumber}`);
1054
+ }
1055
+ /**
1056
+ * Cancel a reservation
1057
+ * @param reservationNumber - Reservation number to cancel
1058
+ * @param reason - Optional cancellation reason
1059
+ */
1060
+ async cancel(reservationNumber, reason) {
1061
+ return this.http.post(`/reservations/${reservationNumber}/cancel`, { reason });
1062
+ }
1063
+ };
1064
+
894
1065
  // src/index.ts
895
1066
  var Promptly = class {
896
1067
  constructor(config) {
@@ -902,6 +1073,7 @@ var Promptly = class {
902
1073
  this.shop = new ShopResource(this.http);
903
1074
  this.media = new MediaResource(this.http);
904
1075
  this.entities = new EntitiesResource(this.http);
1076
+ this.reservation = new ReservationResource(this.http);
905
1077
  }
906
1078
  /**
907
1079
  * Get site theme settings