@back23/promptly-sdk 2.13.0 → 2.14.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 CHANGED
@@ -103,6 +103,8 @@ interface Member {
103
103
  interface AuthResponse {
104
104
  token: string;
105
105
  user: Member;
106
+ /** @alias user - for backward compatibility */
107
+ member: Member;
106
108
  }
107
109
  interface ForgotPasswordData {
108
110
  email: string;
@@ -384,13 +386,19 @@ interface Product {
384
386
  content?: string;
385
387
  price: number;
386
388
  compare_price?: number;
389
+ /** @alias compare_price - for backward compatibility */
390
+ sale_price?: number;
387
391
  cost_price?: number;
388
392
  sku?: string;
389
393
  stock_quantity: number;
394
+ /** @alias stock_quantity - for backward compatibility */
395
+ stock?: number;
390
396
  track_inventory: boolean;
391
397
  thumbnail?: string;
392
398
  images?: string[];
393
399
  status: ProductStatus;
400
+ /** @alias status === 'active' - for backward compatibility */
401
+ is_active?: boolean;
394
402
  is_featured: boolean;
395
403
  has_options: boolean;
396
404
  option_type?: 'single' | 'combination';
@@ -473,6 +481,8 @@ interface OrderItem {
473
481
  order_id: number;
474
482
  product_id: number;
475
483
  variant_id?: number;
484
+ /** Product relation - populated when fetching order details */
485
+ product?: Product;
476
486
  product_name: string;
477
487
  variant_name?: string;
478
488
  thumbnail?: string;
@@ -1294,9 +1304,9 @@ declare class ShopResource {
1294
1304
  searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<ListResponse<Product>>;
1295
1305
  /**
1296
1306
  * List product categories
1297
- * @returns Array of categories (always an array)
1307
+ * @returns ListResponse with data array and pagination meta
1298
1308
  */
1299
- listCategories(): Promise<ProductCategory[]>;
1309
+ listCategories(): Promise<ListResponse<ProductCategory>>;
1300
1310
  /**
1301
1311
  * Get category by ID or slug
1302
1312
  */
package/dist/index.d.ts CHANGED
@@ -103,6 +103,8 @@ interface Member {
103
103
  interface AuthResponse {
104
104
  token: string;
105
105
  user: Member;
106
+ /** @alias user - for backward compatibility */
107
+ member: Member;
106
108
  }
107
109
  interface ForgotPasswordData {
108
110
  email: string;
@@ -384,13 +386,19 @@ interface Product {
384
386
  content?: string;
385
387
  price: number;
386
388
  compare_price?: number;
389
+ /** @alias compare_price - for backward compatibility */
390
+ sale_price?: number;
387
391
  cost_price?: number;
388
392
  sku?: string;
389
393
  stock_quantity: number;
394
+ /** @alias stock_quantity - for backward compatibility */
395
+ stock?: number;
390
396
  track_inventory: boolean;
391
397
  thumbnail?: string;
392
398
  images?: string[];
393
399
  status: ProductStatus;
400
+ /** @alias status === 'active' - for backward compatibility */
401
+ is_active?: boolean;
394
402
  is_featured: boolean;
395
403
  has_options: boolean;
396
404
  option_type?: 'single' | 'combination';
@@ -473,6 +481,8 @@ interface OrderItem {
473
481
  order_id: number;
474
482
  product_id: number;
475
483
  variant_id?: number;
484
+ /** Product relation - populated when fetching order details */
485
+ product?: Product;
476
486
  product_name: string;
477
487
  variant_name?: string;
478
488
  thumbnail?: string;
@@ -1294,9 +1304,9 @@ declare class ShopResource {
1294
1304
  searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<ListResponse<Product>>;
1295
1305
  /**
1296
1306
  * List product categories
1297
- * @returns Array of categories (always an array)
1307
+ * @returns ListResponse with data array and pagination meta
1298
1308
  */
1299
- listCategories(): Promise<ProductCategory[]>;
1309
+ listCategories(): Promise<ListResponse<ProductCategory>>;
1300
1310
  /**
1301
1311
  * Get category by ID or slug
1302
1312
  */
package/dist/index.js CHANGED
@@ -294,6 +294,13 @@ var HttpClient = class {
294
294
  };
295
295
 
296
296
  // src/resources/auth.ts
297
+ function transformAuthResponse(response) {
298
+ return {
299
+ ...response,
300
+ // Add member alias for backward compatibility (same as user)
301
+ member: response.member ?? response.user
302
+ };
303
+ }
297
304
  var AuthResource = class {
298
305
  constructor(http) {
299
306
  this.http = http;
@@ -306,7 +313,7 @@ var AuthResource = class {
306
313
  if (response.token) {
307
314
  this.http.setToken(response.token);
308
315
  }
309
- return response;
316
+ return transformAuthResponse(response);
310
317
  }
311
318
  /**
312
319
  * Register new member
@@ -316,7 +323,7 @@ var AuthResource = class {
316
323
  if (response.token) {
317
324
  this.http.setToken(response.token);
318
325
  }
319
- return response;
326
+ return transformAuthResponse(response);
320
327
  }
321
328
  /**
322
329
  * Logout current user
@@ -372,7 +379,7 @@ var AuthResource = class {
372
379
  if (response.token) {
373
380
  this.http.setToken(response.token);
374
381
  }
375
- return response;
382
+ return transformAuthResponse(response);
376
383
  }
377
384
  /**
378
385
  * Set token manually (e.g., from localStorage)
@@ -670,6 +677,36 @@ var FormsResource = class {
670
677
  };
671
678
 
672
679
  // src/resources/shop.ts
680
+ function transformProduct(product) {
681
+ return {
682
+ ...product,
683
+ // Add alias fields for backward compatibility
684
+ sale_price: product.sale_price ?? product.compare_price,
685
+ stock: product.stock ?? product.stock_quantity,
686
+ is_active: product.is_active ?? product.status === "active"
687
+ };
688
+ }
689
+ function transformProducts(products) {
690
+ return products.map(transformProduct);
691
+ }
692
+ function transformCart(cart) {
693
+ return {
694
+ ...cart,
695
+ items: cart.items.map((item) => ({
696
+ ...item,
697
+ product: item.product ? transformProduct(item.product) : item.product
698
+ }))
699
+ };
700
+ }
701
+ function transformOrder(order) {
702
+ return {
703
+ ...order,
704
+ items: order.items?.map((item) => ({
705
+ ...item,
706
+ product: item.product ? transformProduct(item.product) : item.product
707
+ }))
708
+ };
709
+ }
673
710
  var ShopResource = class {
674
711
  constructor(http) {
675
712
  this.http = http;
@@ -682,13 +719,18 @@ var ShopResource = class {
682
719
  * @returns ListResponse with data array and pagination meta
683
720
  */
684
721
  async listProducts(params) {
685
- return this.http.getList("/products", params);
722
+ const response = await this.http.getList("/products", params);
723
+ return {
724
+ ...response,
725
+ data: transformProducts(response.data)
726
+ };
686
727
  }
687
728
  /**
688
729
  * Get product by ID or slug
689
730
  */
690
731
  async getProduct(idOrSlug) {
691
- return this.http.get(`/products/${idOrSlug}`);
732
+ const product = await this.http.get(`/products/${idOrSlug}`);
733
+ return transformProduct(product);
692
734
  }
693
735
  /**
694
736
  * Get featured products
@@ -699,28 +741,31 @@ var ShopResource = class {
699
741
  per_page: limit,
700
742
  is_featured: true
701
743
  });
702
- return response.data;
744
+ return transformProducts(response.data);
703
745
  }
704
746
  /**
705
747
  * Search products
706
748
  * @returns ListResponse with data array and pagination meta
707
749
  */
708
750
  async searchProducts(query, params) {
709
- return this.http.getList("/products", {
751
+ const response = await this.http.getList("/products", {
710
752
  ...params,
711
753
  search: query
712
754
  });
755
+ return {
756
+ ...response,
757
+ data: transformProducts(response.data)
758
+ };
713
759
  }
714
760
  // ============================================
715
761
  // Categories (Public)
716
762
  // ============================================
717
763
  /**
718
764
  * List product categories
719
- * @returns Array of categories (always an array)
765
+ * @returns ListResponse with data array and pagination meta
720
766
  */
721
767
  async listCategories() {
722
- const response = await this.http.getList("/categories");
723
- return response.data;
768
+ return this.http.getList("/categories");
724
769
  }
725
770
  /**
726
771
  * Get category by ID or slug
@@ -733,7 +778,11 @@ var ShopResource = class {
733
778
  * @returns ListResponse with data array and pagination meta
734
779
  */
735
780
  async categoryProducts(categoryIdOrSlug, params) {
736
- return this.http.getList(`/categories/${categoryIdOrSlug}/products`, params);
781
+ const response = await this.http.getList(`/categories/${categoryIdOrSlug}/products`, params);
782
+ return {
783
+ ...response,
784
+ data: transformProducts(response.data)
785
+ };
737
786
  }
738
787
  // ============================================
739
788
  // Cart
@@ -745,7 +794,7 @@ var ShopResource = class {
745
794
  if (cart.session_id) {
746
795
  this.http.setCartSessionId(cart.session_id);
747
796
  }
748
- return cart;
797
+ return transformCart(cart);
749
798
  }
750
799
  /**
751
800
  * Get current cart
@@ -790,25 +839,32 @@ var ShopResource = class {
790
839
  * @returns ListResponse with data array and pagination meta
791
840
  */
792
841
  async listOrders(params) {
793
- return this.http.getList("/orders", params);
842
+ const response = await this.http.getList("/orders", params);
843
+ return {
844
+ ...response,
845
+ data: response.data.map(transformOrder)
846
+ };
794
847
  }
795
848
  /**
796
849
  * Get order by ID or order number
797
850
  */
798
851
  async getOrder(idOrNumber) {
799
- return this.http.get(`/orders/${idOrNumber}`);
852
+ const order = await this.http.get(`/orders/${idOrNumber}`);
853
+ return transformOrder(order);
800
854
  }
801
855
  /**
802
856
  * Create order from cart
803
857
  */
804
858
  async createOrder(data) {
805
- return this.http.post("/orders", data);
859
+ const order = await this.http.post("/orders", data);
860
+ return transformOrder(order);
806
861
  }
807
862
  /**
808
863
  * Cancel order
809
864
  */
810
865
  async cancelOrder(orderId) {
811
- return this.http.post(`/orders/${orderId}/cancel`);
866
+ const order = await this.http.post(`/orders/${orderId}/cancel`);
867
+ return transformOrder(order);
812
868
  }
813
869
  // ============================================
814
870
  // Payments
package/dist/index.mjs CHANGED
@@ -266,6 +266,13 @@ var HttpClient = class {
266
266
  };
267
267
 
268
268
  // src/resources/auth.ts
269
+ function transformAuthResponse(response) {
270
+ return {
271
+ ...response,
272
+ // Add member alias for backward compatibility (same as user)
273
+ member: response.member ?? response.user
274
+ };
275
+ }
269
276
  var AuthResource = class {
270
277
  constructor(http) {
271
278
  this.http = http;
@@ -278,7 +285,7 @@ var AuthResource = class {
278
285
  if (response.token) {
279
286
  this.http.setToken(response.token);
280
287
  }
281
- return response;
288
+ return transformAuthResponse(response);
282
289
  }
283
290
  /**
284
291
  * Register new member
@@ -288,7 +295,7 @@ var AuthResource = class {
288
295
  if (response.token) {
289
296
  this.http.setToken(response.token);
290
297
  }
291
- return response;
298
+ return transformAuthResponse(response);
292
299
  }
293
300
  /**
294
301
  * Logout current user
@@ -344,7 +351,7 @@ var AuthResource = class {
344
351
  if (response.token) {
345
352
  this.http.setToken(response.token);
346
353
  }
347
- return response;
354
+ return transformAuthResponse(response);
348
355
  }
349
356
  /**
350
357
  * Set token manually (e.g., from localStorage)
@@ -642,6 +649,36 @@ var FormsResource = class {
642
649
  };
643
650
 
644
651
  // src/resources/shop.ts
652
+ function transformProduct(product) {
653
+ return {
654
+ ...product,
655
+ // Add alias fields for backward compatibility
656
+ sale_price: product.sale_price ?? product.compare_price,
657
+ stock: product.stock ?? product.stock_quantity,
658
+ is_active: product.is_active ?? product.status === "active"
659
+ };
660
+ }
661
+ function transformProducts(products) {
662
+ return products.map(transformProduct);
663
+ }
664
+ function transformCart(cart) {
665
+ return {
666
+ ...cart,
667
+ items: cart.items.map((item) => ({
668
+ ...item,
669
+ product: item.product ? transformProduct(item.product) : item.product
670
+ }))
671
+ };
672
+ }
673
+ function transformOrder(order) {
674
+ return {
675
+ ...order,
676
+ items: order.items?.map((item) => ({
677
+ ...item,
678
+ product: item.product ? transformProduct(item.product) : item.product
679
+ }))
680
+ };
681
+ }
645
682
  var ShopResource = class {
646
683
  constructor(http) {
647
684
  this.http = http;
@@ -654,13 +691,18 @@ var ShopResource = class {
654
691
  * @returns ListResponse with data array and pagination meta
655
692
  */
656
693
  async listProducts(params) {
657
- return this.http.getList("/products", params);
694
+ const response = await this.http.getList("/products", params);
695
+ return {
696
+ ...response,
697
+ data: transformProducts(response.data)
698
+ };
658
699
  }
659
700
  /**
660
701
  * Get product by ID or slug
661
702
  */
662
703
  async getProduct(idOrSlug) {
663
- return this.http.get(`/products/${idOrSlug}`);
704
+ const product = await this.http.get(`/products/${idOrSlug}`);
705
+ return transformProduct(product);
664
706
  }
665
707
  /**
666
708
  * Get featured products
@@ -671,28 +713,31 @@ var ShopResource = class {
671
713
  per_page: limit,
672
714
  is_featured: true
673
715
  });
674
- return response.data;
716
+ return transformProducts(response.data);
675
717
  }
676
718
  /**
677
719
  * Search products
678
720
  * @returns ListResponse with data array and pagination meta
679
721
  */
680
722
  async searchProducts(query, params) {
681
- return this.http.getList("/products", {
723
+ const response = await this.http.getList("/products", {
682
724
  ...params,
683
725
  search: query
684
726
  });
727
+ return {
728
+ ...response,
729
+ data: transformProducts(response.data)
730
+ };
685
731
  }
686
732
  // ============================================
687
733
  // Categories (Public)
688
734
  // ============================================
689
735
  /**
690
736
  * List product categories
691
- * @returns Array of categories (always an array)
737
+ * @returns ListResponse with data array and pagination meta
692
738
  */
693
739
  async listCategories() {
694
- const response = await this.http.getList("/categories");
695
- return response.data;
740
+ return this.http.getList("/categories");
696
741
  }
697
742
  /**
698
743
  * Get category by ID or slug
@@ -705,7 +750,11 @@ var ShopResource = class {
705
750
  * @returns ListResponse with data array and pagination meta
706
751
  */
707
752
  async categoryProducts(categoryIdOrSlug, params) {
708
- return this.http.getList(`/categories/${categoryIdOrSlug}/products`, params);
753
+ const response = await this.http.getList(`/categories/${categoryIdOrSlug}/products`, params);
754
+ return {
755
+ ...response,
756
+ data: transformProducts(response.data)
757
+ };
709
758
  }
710
759
  // ============================================
711
760
  // Cart
@@ -717,7 +766,7 @@ var ShopResource = class {
717
766
  if (cart.session_id) {
718
767
  this.http.setCartSessionId(cart.session_id);
719
768
  }
720
- return cart;
769
+ return transformCart(cart);
721
770
  }
722
771
  /**
723
772
  * Get current cart
@@ -762,25 +811,32 @@ var ShopResource = class {
762
811
  * @returns ListResponse with data array and pagination meta
763
812
  */
764
813
  async listOrders(params) {
765
- return this.http.getList("/orders", params);
814
+ const response = await this.http.getList("/orders", params);
815
+ return {
816
+ ...response,
817
+ data: response.data.map(transformOrder)
818
+ };
766
819
  }
767
820
  /**
768
821
  * Get order by ID or order number
769
822
  */
770
823
  async getOrder(idOrNumber) {
771
- return this.http.get(`/orders/${idOrNumber}`);
824
+ const order = await this.http.get(`/orders/${idOrNumber}`);
825
+ return transformOrder(order);
772
826
  }
773
827
  /**
774
828
  * Create order from cart
775
829
  */
776
830
  async createOrder(data) {
777
- return this.http.post("/orders", data);
831
+ const order = await this.http.post("/orders", data);
832
+ return transformOrder(order);
778
833
  }
779
834
  /**
780
835
  * Cancel order
781
836
  */
782
837
  async cancelOrder(orderId) {
783
- return this.http.post(`/orders/${orderId}/cancel`);
838
+ const order = await this.http.post(`/orders/${orderId}/cancel`);
839
+ return transformOrder(order);
784
840
  }
785
841
  // ============================================
786
842
  // Payments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@back23/promptly-sdk",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "Promptly AI CMS SDK for JavaScript/TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",