@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.d.mts +237 -34
- package/dist/index.d.ts +237 -34
- package/dist/index.js +193 -21
- package/dist/index.mjs +193 -21
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
// src/http.ts
|
|
2
|
+
var DEFAULT_META = {
|
|
3
|
+
current_page: 1,
|
|
4
|
+
last_page: 1,
|
|
5
|
+
per_page: 15,
|
|
6
|
+
total: 0,
|
|
7
|
+
from: null,
|
|
8
|
+
to: null
|
|
9
|
+
};
|
|
10
|
+
function normalizeListResponse(response) {
|
|
11
|
+
if (response == null) {
|
|
12
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(response)) {
|
|
15
|
+
return {
|
|
16
|
+
data: response,
|
|
17
|
+
meta: { ...DEFAULT_META, total: response.length, from: response.length > 0 ? 1 : null, to: response.length > 0 ? response.length : null }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (typeof response === "object") {
|
|
21
|
+
const data = Array.isArray(response.data) ? response.data : [];
|
|
22
|
+
const meta = {
|
|
23
|
+
current_page: response.meta?.current_page ?? response.current_page ?? 1,
|
|
24
|
+
last_page: response.meta?.last_page ?? response.last_page ?? 1,
|
|
25
|
+
per_page: response.meta?.per_page ?? response.per_page ?? 15,
|
|
26
|
+
total: response.meta?.total ?? response.total ?? data.length,
|
|
27
|
+
from: response.meta?.from ?? response.from ?? (data.length > 0 ? 1 : null),
|
|
28
|
+
to: response.meta?.to ?? response.to ?? (data.length > 0 ? data.length : null)
|
|
29
|
+
};
|
|
30
|
+
return { data, meta };
|
|
31
|
+
}
|
|
32
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
33
|
+
}
|
|
2
34
|
var PromptlyError = class extends Error {
|
|
3
35
|
constructor(message, status, errors) {
|
|
4
36
|
super(message);
|
|
@@ -106,6 +138,14 @@ var HttpClient = class {
|
|
|
106
138
|
get(endpoint, params) {
|
|
107
139
|
return this.request(endpoint, { method: "GET", params });
|
|
108
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* GET request for list endpoints - ALWAYS returns normalized ListResponse
|
|
143
|
+
* Guarantees: data is always an array, meta is always present
|
|
144
|
+
*/
|
|
145
|
+
async getList(endpoint, params) {
|
|
146
|
+
const response = await this.request(endpoint, { method: "GET", params });
|
|
147
|
+
return normalizeListResponse(response);
|
|
148
|
+
}
|
|
109
149
|
/**
|
|
110
150
|
* POST request
|
|
111
151
|
*/
|
|
@@ -289,9 +329,10 @@ var BoardsResource = class {
|
|
|
289
329
|
// ============================================
|
|
290
330
|
/**
|
|
291
331
|
* List all boards
|
|
332
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
292
333
|
*/
|
|
293
334
|
async list(params) {
|
|
294
|
-
return this.http.
|
|
335
|
+
return this.http.getList("/public/boards", params);
|
|
295
336
|
}
|
|
296
337
|
/**
|
|
297
338
|
* Get board by ID or slug
|
|
@@ -304,9 +345,10 @@ var BoardsResource = class {
|
|
|
304
345
|
// ============================================
|
|
305
346
|
/**
|
|
306
347
|
* List posts in a board
|
|
348
|
+
* @returns ListResponse with data array and pagination meta
|
|
307
349
|
*/
|
|
308
350
|
async listPosts(boardIdOrSlug, params) {
|
|
309
|
-
return this.http.
|
|
351
|
+
return this.http.getList(`/public/boards/${boardIdOrSlug}/posts`, params);
|
|
310
352
|
}
|
|
311
353
|
/**
|
|
312
354
|
* Get post by ID
|
|
@@ -340,9 +382,11 @@ var BoardsResource = class {
|
|
|
340
382
|
// ============================================
|
|
341
383
|
/**
|
|
342
384
|
* List comments for a post
|
|
385
|
+
* @returns Array of comments (always an array, never null/undefined)
|
|
343
386
|
*/
|
|
344
387
|
async listComments(postId) {
|
|
345
|
-
|
|
388
|
+
const response = await this.http.getList(`/public/posts/${postId}/comments`);
|
|
389
|
+
return response.data;
|
|
346
390
|
}
|
|
347
391
|
/**
|
|
348
392
|
* Create comment on a post
|
|
@@ -371,9 +415,10 @@ var BlogResource = class {
|
|
|
371
415
|
}
|
|
372
416
|
/**
|
|
373
417
|
* List blog posts
|
|
418
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
374
419
|
*/
|
|
375
420
|
async list(params) {
|
|
376
|
-
return this.http.
|
|
421
|
+
return this.http.getList("/public/blog", params);
|
|
377
422
|
}
|
|
378
423
|
/**
|
|
379
424
|
* Get blog post by slug
|
|
@@ -389,9 +434,10 @@ var BlogResource = class {
|
|
|
389
434
|
}
|
|
390
435
|
/**
|
|
391
436
|
* Get featured blog posts
|
|
437
|
+
* @returns Array of featured posts (always an array, never null/undefined)
|
|
392
438
|
*/
|
|
393
439
|
async featured(limit = 5) {
|
|
394
|
-
const response = await this.http.
|
|
440
|
+
const response = await this.http.getList("/public/blog", {
|
|
395
441
|
per_page: limit,
|
|
396
442
|
featured: true
|
|
397
443
|
});
|
|
@@ -399,42 +445,49 @@ var BlogResource = class {
|
|
|
399
445
|
}
|
|
400
446
|
/**
|
|
401
447
|
* Get blog posts by category
|
|
448
|
+
* @returns ListResponse with data array and pagination meta
|
|
402
449
|
*/
|
|
403
450
|
async byCategory(category, params) {
|
|
404
|
-
return this.http.
|
|
451
|
+
return this.http.getList("/public/blog", {
|
|
405
452
|
...params,
|
|
406
453
|
category
|
|
407
454
|
});
|
|
408
455
|
}
|
|
409
456
|
/**
|
|
410
457
|
* Get blog posts by tag
|
|
458
|
+
* @returns ListResponse with data array and pagination meta
|
|
411
459
|
*/
|
|
412
460
|
async byTag(tag, params) {
|
|
413
|
-
return this.http.
|
|
461
|
+
return this.http.getList("/public/blog", {
|
|
414
462
|
...params,
|
|
415
463
|
tag
|
|
416
464
|
});
|
|
417
465
|
}
|
|
418
466
|
/**
|
|
419
467
|
* Search blog posts
|
|
468
|
+
* @returns ListResponse with data array and pagination meta
|
|
420
469
|
*/
|
|
421
470
|
async search(query, params) {
|
|
422
|
-
return this.http.
|
|
471
|
+
return this.http.getList("/public/blog", {
|
|
423
472
|
...params,
|
|
424
473
|
search: query
|
|
425
474
|
});
|
|
426
475
|
}
|
|
427
476
|
/**
|
|
428
477
|
* Get blog categories
|
|
478
|
+
* @returns Array of category names (always an array)
|
|
429
479
|
*/
|
|
430
480
|
async categories() {
|
|
431
|
-
|
|
481
|
+
const response = await this.http.get("/public/blog/categories");
|
|
482
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
432
483
|
}
|
|
433
484
|
/**
|
|
434
485
|
* Get blog tags
|
|
486
|
+
* @returns Array of tag names (always an array)
|
|
435
487
|
*/
|
|
436
488
|
async tags() {
|
|
437
|
-
|
|
489
|
+
const response = await this.http.get("/public/blog/tags");
|
|
490
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
438
491
|
}
|
|
439
492
|
};
|
|
440
493
|
|
|
@@ -445,9 +498,10 @@ var FormsResource = class {
|
|
|
445
498
|
}
|
|
446
499
|
/**
|
|
447
500
|
* List all forms
|
|
501
|
+
* @returns ListResponse with data array and pagination meta
|
|
448
502
|
*/
|
|
449
503
|
async list(params) {
|
|
450
|
-
return this.http.
|
|
504
|
+
return this.http.getList("/public/forms", params);
|
|
451
505
|
}
|
|
452
506
|
/**
|
|
453
507
|
* Get form by ID or slug
|
|
@@ -466,9 +520,10 @@ var FormsResource = class {
|
|
|
466
520
|
// ============================================
|
|
467
521
|
/**
|
|
468
522
|
* Get my form submissions
|
|
523
|
+
* @returns ListResponse with data array and pagination meta
|
|
469
524
|
*/
|
|
470
525
|
async mySubmissions(params) {
|
|
471
|
-
return this.http.
|
|
526
|
+
return this.http.getList("/form-submissions", params);
|
|
472
527
|
}
|
|
473
528
|
/**
|
|
474
529
|
* Get specific submission
|
|
@@ -488,9 +543,10 @@ var ShopResource = class {
|
|
|
488
543
|
// ============================================
|
|
489
544
|
/**
|
|
490
545
|
* List products
|
|
546
|
+
* @returns ListResponse with data array and pagination meta
|
|
491
547
|
*/
|
|
492
548
|
async listProducts(params) {
|
|
493
|
-
return this.http.
|
|
549
|
+
return this.http.getList("/public/products", params);
|
|
494
550
|
}
|
|
495
551
|
/**
|
|
496
552
|
* Get product by ID or slug
|
|
@@ -500,9 +556,10 @@ var ShopResource = class {
|
|
|
500
556
|
}
|
|
501
557
|
/**
|
|
502
558
|
* Get featured products
|
|
559
|
+
* @returns Array of featured products (always an array)
|
|
503
560
|
*/
|
|
504
561
|
async featuredProducts(limit = 8) {
|
|
505
|
-
const response = await this.http.
|
|
562
|
+
const response = await this.http.getList("/public/products", {
|
|
506
563
|
per_page: limit,
|
|
507
564
|
is_featured: true
|
|
508
565
|
});
|
|
@@ -510,9 +567,10 @@ var ShopResource = class {
|
|
|
510
567
|
}
|
|
511
568
|
/**
|
|
512
569
|
* Search products
|
|
570
|
+
* @returns ListResponse with data array and pagination meta
|
|
513
571
|
*/
|
|
514
572
|
async searchProducts(query, params) {
|
|
515
|
-
return this.http.
|
|
573
|
+
return this.http.getList("/public/products", {
|
|
516
574
|
...params,
|
|
517
575
|
search: query
|
|
518
576
|
});
|
|
@@ -522,9 +580,11 @@ var ShopResource = class {
|
|
|
522
580
|
// ============================================
|
|
523
581
|
/**
|
|
524
582
|
* List product categories
|
|
583
|
+
* @returns Array of categories (always an array)
|
|
525
584
|
*/
|
|
526
585
|
async listCategories() {
|
|
527
|
-
|
|
586
|
+
const response = await this.http.getList("/public/categories");
|
|
587
|
+
return response.data;
|
|
528
588
|
}
|
|
529
589
|
/**
|
|
530
590
|
* Get category by ID or slug
|
|
@@ -534,9 +594,10 @@ var ShopResource = class {
|
|
|
534
594
|
}
|
|
535
595
|
/**
|
|
536
596
|
* Get products in category
|
|
597
|
+
* @returns ListResponse with data array and pagination meta
|
|
537
598
|
*/
|
|
538
599
|
async categoryProducts(categoryIdOrSlug, params) {
|
|
539
|
-
return this.http.
|
|
600
|
+
return this.http.getList(`/public/categories/${categoryIdOrSlug}/products`, params);
|
|
540
601
|
}
|
|
541
602
|
// ============================================
|
|
542
603
|
// Cart
|
|
@@ -576,9 +637,10 @@ var ShopResource = class {
|
|
|
576
637
|
// ============================================
|
|
577
638
|
/**
|
|
578
639
|
* List my orders
|
|
640
|
+
* @returns ListResponse with data array and pagination meta
|
|
579
641
|
*/
|
|
580
642
|
async listOrders(params) {
|
|
581
|
-
return this.http.
|
|
643
|
+
return this.http.getList("/orders", params);
|
|
582
644
|
}
|
|
583
645
|
/**
|
|
584
646
|
* Get order by ID or order number
|
|
@@ -639,9 +701,11 @@ var ShopResource = class {
|
|
|
639
701
|
}
|
|
640
702
|
/**
|
|
641
703
|
* Get available coupons for current user
|
|
704
|
+
* @returns Array of coupons (always an array)
|
|
642
705
|
*/
|
|
643
706
|
async myCoupons() {
|
|
644
|
-
|
|
707
|
+
const response = await this.http.getList("/coupons");
|
|
708
|
+
return response.data;
|
|
645
709
|
}
|
|
646
710
|
};
|
|
647
711
|
|
|
@@ -697,6 +761,7 @@ var EntitiesResource = class {
|
|
|
697
761
|
// ============================================
|
|
698
762
|
/**
|
|
699
763
|
* List all active custom entities
|
|
764
|
+
* @returns Array of entities (always an array)
|
|
700
765
|
*
|
|
701
766
|
* @example
|
|
702
767
|
* ```typescript
|
|
@@ -705,7 +770,8 @@ var EntitiesResource = class {
|
|
|
705
770
|
* ```
|
|
706
771
|
*/
|
|
707
772
|
async list() {
|
|
708
|
-
|
|
773
|
+
const response = await this.http.getList("/public/entities");
|
|
774
|
+
return response.data;
|
|
709
775
|
}
|
|
710
776
|
/**
|
|
711
777
|
* Get entity schema by slug
|
|
@@ -724,6 +790,7 @@ var EntitiesResource = class {
|
|
|
724
790
|
// ============================================
|
|
725
791
|
/**
|
|
726
792
|
* List records for an entity
|
|
793
|
+
* @returns ListResponse with data array and pagination meta
|
|
727
794
|
*
|
|
728
795
|
* @example
|
|
729
796
|
* ```typescript
|
|
@@ -744,7 +811,7 @@ var EntitiesResource = class {
|
|
|
744
811
|
* ```
|
|
745
812
|
*/
|
|
746
813
|
async listRecords(slug, params) {
|
|
747
|
-
return this.http.
|
|
814
|
+
return this.http.getList(`/public/entities/${slug}`, params);
|
|
748
815
|
}
|
|
749
816
|
/**
|
|
750
817
|
* Get a single record by ID
|
|
@@ -863,6 +930,110 @@ var EntitiesResource = class {
|
|
|
863
930
|
}
|
|
864
931
|
};
|
|
865
932
|
|
|
933
|
+
// src/resources/reservation.ts
|
|
934
|
+
var ReservationResource = class {
|
|
935
|
+
constructor(http) {
|
|
936
|
+
this.http = http;
|
|
937
|
+
}
|
|
938
|
+
// ============================================
|
|
939
|
+
// Public Endpoints
|
|
940
|
+
// ============================================
|
|
941
|
+
/**
|
|
942
|
+
* Get reservation settings
|
|
943
|
+
* @returns Reservation settings for the tenant
|
|
944
|
+
*/
|
|
945
|
+
async getSettings() {
|
|
946
|
+
return this.http.get("/public/reservations/settings");
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* List available services
|
|
950
|
+
* @returns Array of services (always an array)
|
|
951
|
+
*/
|
|
952
|
+
async listServices() {
|
|
953
|
+
const response = await this.http.getList("/public/reservations/services");
|
|
954
|
+
return response.data;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* List available staff members
|
|
958
|
+
* @param serviceId - Optional: filter staff by service
|
|
959
|
+
* @returns Array of staff members (always an array)
|
|
960
|
+
*/
|
|
961
|
+
async listStaff(serviceId) {
|
|
962
|
+
const params = serviceId ? { service_id: serviceId } : void 0;
|
|
963
|
+
const response = await this.http.getList("/public/reservations/staffs", params);
|
|
964
|
+
return response.data;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Get available dates for booking
|
|
968
|
+
* @returns Array of available date strings (YYYY-MM-DD)
|
|
969
|
+
*/
|
|
970
|
+
async getAvailableDates(params) {
|
|
971
|
+
const response = await this.http.get("/public/reservations/dates", params);
|
|
972
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Get available time slots for a specific date
|
|
976
|
+
* @returns Array of available slots (always an array)
|
|
977
|
+
*/
|
|
978
|
+
async getAvailableSlots(params) {
|
|
979
|
+
const response = await this.http.get("/public/reservations/slots", params);
|
|
980
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
981
|
+
}
|
|
982
|
+
// ============================================
|
|
983
|
+
// Protected Endpoints (requires auth)
|
|
984
|
+
// ============================================
|
|
985
|
+
/**
|
|
986
|
+
* Create a new reservation
|
|
987
|
+
* @returns Created reservation with payment info
|
|
988
|
+
*/
|
|
989
|
+
async create(data) {
|
|
990
|
+
return this.http.post("/reservations", data);
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* List my reservations
|
|
994
|
+
* @returns ListResponse with reservations and pagination meta
|
|
995
|
+
*/
|
|
996
|
+
async list(params) {
|
|
997
|
+
return this.http.getList("/reservations", params);
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Get upcoming reservations
|
|
1001
|
+
* @returns Array of upcoming reservations
|
|
1002
|
+
*/
|
|
1003
|
+
async upcoming(limit = 10) {
|
|
1004
|
+
const response = await this.http.getList("/reservations", {
|
|
1005
|
+
upcoming: true,
|
|
1006
|
+
per_page: limit
|
|
1007
|
+
});
|
|
1008
|
+
return response.data;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Get past reservations
|
|
1012
|
+
* @returns Array of past reservations
|
|
1013
|
+
*/
|
|
1014
|
+
async past(limit = 10) {
|
|
1015
|
+
const response = await this.http.getList("/reservations", {
|
|
1016
|
+
past: true,
|
|
1017
|
+
per_page: limit
|
|
1018
|
+
});
|
|
1019
|
+
return response.data;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Get reservation by reservation number
|
|
1023
|
+
*/
|
|
1024
|
+
async get(reservationNumber) {
|
|
1025
|
+
return this.http.get(`/reservations/${reservationNumber}`);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Cancel a reservation
|
|
1029
|
+
* @param reservationNumber - Reservation number to cancel
|
|
1030
|
+
* @param reason - Optional cancellation reason
|
|
1031
|
+
*/
|
|
1032
|
+
async cancel(reservationNumber, reason) {
|
|
1033
|
+
return this.http.post(`/reservations/${reservationNumber}/cancel`, { reason });
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
|
|
866
1037
|
// src/index.ts
|
|
867
1038
|
var Promptly = class {
|
|
868
1039
|
constructor(config) {
|
|
@@ -874,6 +1045,7 @@ var Promptly = class {
|
|
|
874
1045
|
this.shop = new ShopResource(this.http);
|
|
875
1046
|
this.media = new MediaResource(this.http);
|
|
876
1047
|
this.entities = new EntitiesResource(this.http);
|
|
1048
|
+
this.reservation = new ReservationResource(this.http);
|
|
877
1049
|
}
|
|
878
1050
|
/**
|
|
879
1051
|
* Get site theme settings
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@back23/promptly-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Promptly AI CMS SDK for JavaScript/TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/kingofecommerce/promptly-sdk.git"
|
|
35
|
+
"url": "https://github.com/kingofecommerce/back23-promptly-sdk.git"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsup": "^8.0.0",
|