@blackcode_sa/metaestetics-api 1.12.49 → 1.12.51

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
@@ -565,9 +565,10 @@ interface FilledDocumentFileValue {
565
565
  *
566
566
  * @property id - Unique identifier of the product
567
567
  * @property name - Name of the product
568
- * @property description - Detailed description of the product and its purpose
569
568
  * @property brandId - ID of the brand that manufactures this product
570
- * @property technologyId - ID of the technology this product is used with
569
+ * @property brandName - Name of the brand (denormalized for display)
570
+ * @property assignedTechnologyIds - Array of technology IDs this product is assigned to
571
+ * @property description - Detailed description of the product and its purpose
571
572
  * @property technicalDetails - Technical details and specifications
572
573
  * @property warnings - List of warnings related to product use
573
574
  * @property dosage - Dosage information (if applicable)
@@ -583,10 +584,7 @@ interface Product {
583
584
  name: string;
584
585
  brandId: string;
585
586
  brandName: string;
586
- technologyId: string;
587
- technologyName: string;
588
- categoryId: string;
589
- subcategoryId: string;
587
+ assignedTechnologyIds?: string[];
590
588
  createdAt: Date;
591
589
  updatedAt: Date;
592
590
  isActive: boolean;
@@ -597,12 +595,86 @@ interface Product {
597
595
  composition?: string;
598
596
  indications?: string[];
599
597
  contraindications?: ContraindicationDynamic[];
598
+ /** Present only in subcollections - synced from technology metadata */
599
+ technologyId?: string;
600
+ /** Present only in subcollections - synced from technology name */
601
+ technologyName?: string;
602
+ /** Present only in subcollections - synced from technology categoryId */
603
+ categoryId?: string;
604
+ /** Present only in subcollections - synced from technology subcategoryId */
605
+ subcategoryId?: string;
600
606
  }
601
607
  /**
602
608
  * Interface for the ProductService class
609
+ *
610
+ * NOTE: This interface maintains backward compatibility while adding new top-level collection methods.
611
+ * Old methods using technologyId are kept for existing code, new methods work with top-level collection.
603
612
  */
604
613
  interface IProductService {
605
614
  /**
615
+ * Creates a new product in the top-level collection
616
+ * @param brandId - ID of the brand that manufactures this product
617
+ * @param product - Product data
618
+ * @param technologyIds - Optional array of technology IDs to assign this product to
619
+ */
620
+ createTopLevel(brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'assignedTechnologyIds'>, technologyIds?: string[]): Promise<Product>;
621
+ /**
622
+ * Gets all products from the top-level collection
623
+ * @param options - Query options
624
+ */
625
+ getAllTopLevel(options: {
626
+ rowsPerPage: number;
627
+ lastVisible?: any;
628
+ brandId?: string;
629
+ }): Promise<{
630
+ products: Product[];
631
+ lastVisible: any;
632
+ }>;
633
+ /**
634
+ * Gets a product by ID from the top-level collection
635
+ * @param productId - ID of the product
636
+ */
637
+ getByIdTopLevel(productId: string): Promise<Product | null>;
638
+ /**
639
+ * Updates a product in the top-level collection
640
+ * @param productId - ID of the product to update
641
+ * @param product - Updated product data
642
+ */
643
+ updateTopLevel(productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId'>>): Promise<Product | null>;
644
+ /**
645
+ * Deletes a product from the top-level collection (soft delete)
646
+ * @param productId - ID of the product to delete
647
+ */
648
+ deleteTopLevel(productId: string): Promise<void>;
649
+ /**
650
+ * Assigns a product to a technology
651
+ * @param productId - ID of the product
652
+ * @param technologyId - ID of the technology
653
+ */
654
+ assignToTechnology(productId: string, technologyId: string): Promise<void>;
655
+ /**
656
+ * Unassigns a product from a technology
657
+ * @param productId - ID of the product
658
+ * @param technologyId - ID of the technology
659
+ */
660
+ unassignFromTechnology(productId: string, technologyId: string): Promise<void>;
661
+ /**
662
+ * Gets products assigned to a specific technology
663
+ * @param technologyId - ID of the technology
664
+ */
665
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
666
+ /**
667
+ * Gets products NOT assigned to a specific technology
668
+ * @param technologyId - ID of the technology
669
+ */
670
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
671
+ /**
672
+ * Gets all products for a brand
673
+ * @param brandId - ID of the brand
674
+ */
675
+ getByBrand(brandId: string): Promise<Product[]>;
676
+ /**
677
+ * @deprecated Use createTopLevel instead
606
678
  * Creates a new product
607
679
  * @param technologyId - ID of the technology this product is used with
608
680
  * @param brandId - ID of the brand that manufactures this product
@@ -610,6 +682,7 @@ interface IProductService {
610
682
  */
611
683
  create(technologyId: string, brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'technologyId'>): Promise<Product>;
612
684
  /**
685
+ * @deprecated Use getAllTopLevel instead
613
686
  * Gets a paginated list of all products, with optional filters.
614
687
  */
615
688
  getAll(options: {
@@ -623,6 +696,7 @@ interface IProductService {
623
696
  lastVisible: any;
624
697
  }>;
625
698
  /**
699
+ * @deprecated Use alternative counting methods
626
700
  * Gets the total count of active products, with optional filters.
627
701
  */
628
702
  getProductsCount(options: {
@@ -631,6 +705,7 @@ interface IProductService {
631
705
  technologyId?: string;
632
706
  }): Promise<number>;
633
707
  /**
708
+ * @deprecated Use alternative counting methods
634
709
  * Gets counts of active products grouped by category, subcategory, and technology.
635
710
  */
636
711
  getProductCounts(): Promise<{
@@ -639,16 +714,19 @@ interface IProductService {
639
714
  byTechnology: Record<string, number>;
640
715
  }>;
641
716
  /**
717
+ * @deprecated Use getAssignedProducts instead
642
718
  * Gets all products for a specific technology (non-paginated, for filters/dropdowns)
643
719
  * @param technologyId - ID of the technology
644
720
  */
645
721
  getAllByTechnology(technologyId: string): Promise<Product[]>;
646
722
  /**
723
+ * @deprecated Use getByBrand instead
647
724
  * Gets all products for a brand
648
725
  * @param brandId - ID of the brand
649
726
  */
650
727
  getAllByBrand(brandId: string): Promise<Product[]>;
651
728
  /**
729
+ * @deprecated Use updateTopLevel instead
652
730
  * Updates a product
653
731
  * @param technologyId - ID of the technology
654
732
  * @param productId - ID of the product to update
@@ -656,12 +734,14 @@ interface IProductService {
656
734
  */
657
735
  update(technologyId: string, productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId' | 'technologyId'>>): Promise<Product | null>;
658
736
  /**
737
+ * @deprecated Use deleteTopLevel instead
659
738
  * Deletes a product (soft delete)
660
739
  * @param technologyId - ID of the technology
661
740
  * @param productId - ID of the product to delete
662
741
  */
663
742
  delete(technologyId: string, productId: string): Promise<void>;
664
743
  /**
744
+ * @deprecated Use getByIdTopLevel instead
665
745
  * Gets a product by ID
666
746
  * @param technologyId - ID of the technology
667
747
  * @param productId - ID of the product
@@ -1103,6 +1183,18 @@ declare class BrandService extends BaseService {
1103
1183
  * Gets a brand by ID
1104
1184
  */
1105
1185
  getById(brandId: string): Promise<Brand | null>;
1186
+ /**
1187
+ * Exports brands to CSV string, suitable for Excel/Sheets.
1188
+ * Includes headers and optional UTF-8 BOM.
1189
+ * By default exports only active brands (set includeInactive to true to export all).
1190
+ */
1191
+ exportToCsv(options?: {
1192
+ includeInactive?: boolean;
1193
+ includeBom?: boolean;
1194
+ }): Promise<string>;
1195
+ private brandToCsvRow;
1196
+ private formatDateIso;
1197
+ private formatCsvValue;
1106
1198
  }
1107
1199
 
1108
1200
  /**
@@ -1204,6 +1296,18 @@ declare class CategoryService extends BaseService implements ICategoryService {
1204
1296
  * @returns Kategorija ili null ako ne postoji
1205
1297
  */
1206
1298
  getById(id: string): Promise<Category | null>;
1299
+ /**
1300
+ * Exports categories to CSV string, suitable for Excel/Sheets.
1301
+ * Includes headers and optional UTF-8 BOM.
1302
+ * By default exports only active categories (set includeInactive to true to export all).
1303
+ */
1304
+ exportToCsv(options?: {
1305
+ includeInactive?: boolean;
1306
+ includeBom?: boolean;
1307
+ }): Promise<string>;
1308
+ private categoryToCsvRow;
1309
+ private formatDateIso;
1310
+ private formatCsvValue;
1207
1311
  }
1208
1312
 
1209
1313
  /**
@@ -1480,7 +1584,12 @@ declare class FilledDocumentService extends BaseService {
1480
1584
 
1481
1585
  declare class ProductService extends BaseService implements IProductService {
1482
1586
  /**
1483
- * Gets reference to products collection under a technology
1587
+ * Gets reference to top-level products collection (source of truth)
1588
+ * @returns Firestore collection reference
1589
+ */
1590
+ private getTopLevelProductsRef;
1591
+ /**
1592
+ * Gets reference to products collection under a technology (backward compatibility)
1484
1593
  * @param technologyId - ID of the technology
1485
1594
  * @returns Firestore collection reference
1486
1595
  */
@@ -1513,7 +1622,7 @@ declare class ProductService extends BaseService implements IProductService {
1513
1622
  }): Promise<number>;
1514
1623
  /**
1515
1624
  * Gets counts of active products grouped by category, subcategory, and technology.
1516
- * This uses a single collectionGroup query for efficiency.
1625
+ * Queries technology subcollections which have the legacy fields synced by Cloud Functions.
1517
1626
  */
1518
1627
  getProductCounts(): Promise<{
1519
1628
  byCategory: Record<string, number>;
@@ -1540,6 +1649,65 @@ declare class ProductService extends BaseService implements IProductService {
1540
1649
  * Gets a product by ID
1541
1650
  */
1542
1651
  getById(technologyId: string, productId: string): Promise<Product | null>;
1652
+ /**
1653
+ * Creates a new product in the top-level collection
1654
+ */
1655
+ createTopLevel(brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'assignedTechnologyIds'>, technologyIds?: string[]): Promise<Product>;
1656
+ /**
1657
+ * Gets all products from the top-level collection
1658
+ */
1659
+ getAllTopLevel(options: {
1660
+ rowsPerPage: number;
1661
+ lastVisible?: any;
1662
+ brandId?: string;
1663
+ }): Promise<{
1664
+ products: Product[];
1665
+ lastVisible: any;
1666
+ }>;
1667
+ /**
1668
+ * Gets a product by ID from the top-level collection
1669
+ */
1670
+ getByIdTopLevel(productId: string): Promise<Product | null>;
1671
+ /**
1672
+ * Updates a product in the top-level collection
1673
+ */
1674
+ updateTopLevel(productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId'>>): Promise<Product | null>;
1675
+ /**
1676
+ * Deletes a product from the top-level collection (soft delete)
1677
+ */
1678
+ deleteTopLevel(productId: string): Promise<void>;
1679
+ /**
1680
+ * Assigns a product to a technology
1681
+ */
1682
+ assignToTechnology(productId: string, technologyId: string): Promise<void>;
1683
+ /**
1684
+ * Unassigns a product from a technology
1685
+ */
1686
+ unassignFromTechnology(productId: string, technologyId: string): Promise<void>;
1687
+ /**
1688
+ * Gets products assigned to a specific technology
1689
+ */
1690
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
1691
+ /**
1692
+ * Gets products NOT assigned to a specific technology
1693
+ */
1694
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
1695
+ /**
1696
+ * Gets all products for a brand (from top-level collection)
1697
+ */
1698
+ getByBrand(brandId: string): Promise<Product[]>;
1699
+ /**
1700
+ * Exports products to CSV string, suitable for Excel/Sheets.
1701
+ * Includes headers and optional UTF-8 BOM.
1702
+ * By default exports only active products (set includeInactive to true to export all).
1703
+ */
1704
+ exportToCsv(options?: {
1705
+ includeInactive?: boolean;
1706
+ includeBom?: boolean;
1707
+ }): Promise<string>;
1708
+ private productToCsvRow;
1709
+ private formatDateIso;
1710
+ private formatCsvValue;
1543
1711
  }
1544
1712
 
1545
1713
  /**
@@ -1650,6 +1818,18 @@ declare class SubcategoryService extends BaseService {
1650
1818
  * @returns Podkategorija ili null ako ne postoji
1651
1819
  */
1652
1820
  getById(categoryId: string, subcategoryId: string): Promise<Subcategory | null>;
1821
+ /**
1822
+ * Exports subcategories to CSV string, suitable for Excel/Sheets.
1823
+ * Includes headers and optional UTF-8 BOM.
1824
+ * By default exports only active subcategories (set includeInactive to true to export all).
1825
+ */
1826
+ exportToCsv(options?: {
1827
+ includeInactive?: boolean;
1828
+ includeBom?: boolean;
1829
+ }): Promise<string>;
1830
+ private subcategoryToCsvRow;
1831
+ private formatDateIso;
1832
+ private formatCsvValue;
1653
1833
  }
1654
1834
 
1655
1835
  /**
@@ -1973,10 +2153,10 @@ declare class TechnologyService extends BaseService implements ITechnologyServic
1973
2153
  description: string;
1974
2154
  family: ProcedureFamily;
1975
2155
  isActive: boolean;
1976
- categoryId: string;
1977
- subcategoryId: string;
1978
2156
  technicalDetails?: string | undefined;
1979
2157
  contraindications: ContraindicationDynamic[];
2158
+ categoryId: string;
2159
+ subcategoryId: string;
1980
2160
  requirements: {
1981
2161
  pre: Requirement[];
1982
2162
  post: Requirement[];
@@ -2245,6 +2425,54 @@ declare class TechnologyService extends BaseService implements ITechnologyServic
2245
2425
  * Gets all active technologies for filter dropdowns.
2246
2426
  */
2247
2427
  getAllForFilter(): Promise<Technology[]>;
2428
+ /**
2429
+ * Assigns multiple products to a technology
2430
+ * Updates each product's assignedTechnologyIds array
2431
+ */
2432
+ assignProducts(technologyId: string, productIds: string[]): Promise<void>;
2433
+ /**
2434
+ * Unassigns multiple products from a technology
2435
+ * Updates each product's assignedTechnologyIds array
2436
+ */
2437
+ unassignProducts(technologyId: string, productIds: string[]): Promise<void>;
2438
+ /**
2439
+ * Gets products assigned to a specific technology
2440
+ * Reads from top-level collection for immediate consistency (Cloud Functions may lag)
2441
+ */
2442
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
2443
+ /**
2444
+ * Gets products NOT assigned to a specific technology
2445
+ */
2446
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
2447
+ /**
2448
+ * Gets product assignment statistics for a technology
2449
+ */
2450
+ getProductStats(technologyId: string): Promise<{
2451
+ totalAssigned: number;
2452
+ byBrand: Record<string, number>;
2453
+ }>;
2454
+ /**
2455
+ * Updates products in technology subcollection when technology metadata changes
2456
+ * @param technologyId - ID of the technology
2457
+ * @param updates - Fields to update (categoryId, subcategoryId, technologyName)
2458
+ */
2459
+ private updateProductsInSubcollection;
2460
+ /**
2461
+ * Exports technologies to CSV string, suitable for Excel/Sheets.
2462
+ * Includes headers and optional UTF-8 BOM.
2463
+ * By default exports only active technologies (set includeInactive to true to export all).
2464
+ * Includes product names from subcollections.
2465
+ */
2466
+ exportToCsv(options?: {
2467
+ includeInactive?: boolean;
2468
+ includeBom?: boolean;
2469
+ }): Promise<string>;
2470
+ /**
2471
+ * Gets product names from the technology's product subcollection
2472
+ */
2473
+ private getProductNamesForTechnology;
2474
+ private technologyToCsvRow;
2475
+ private formatCsvValue;
2248
2476
  }
2249
2477
 
2250
2478
  /**
@@ -2364,6 +2592,23 @@ declare class ConstantsService extends BaseService {
2364
2592
  * @returns {Promise<void>}
2365
2593
  */
2366
2594
  deleteContraindication(contraindicationId: string): Promise<void>;
2595
+ /**
2596
+ * Exports treatment benefits to CSV string, suitable for Excel/Sheets.
2597
+ * Includes headers and optional UTF-8 BOM.
2598
+ */
2599
+ exportBenefitsToCsv(options?: {
2600
+ includeBom?: boolean;
2601
+ }): Promise<string>;
2602
+ /**
2603
+ * Exports contraindications to CSV string, suitable for Excel/Sheets.
2604
+ * Includes headers and optional UTF-8 BOM.
2605
+ */
2606
+ exportContraindicationsToCsv(options?: {
2607
+ includeBom?: boolean;
2608
+ }): Promise<string>;
2609
+ private benefitToCsvRow;
2610
+ private contraindicationToCsvRow;
2611
+ private formatCsvValue;
2367
2612
  }
2368
2613
 
2369
2614
  /**