@blackcode_sa/metaestetics-api 1.6.23 → 1.6.24

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.
@@ -5421,9 +5421,10 @@ declare class DocumentationTemplateService {
5421
5421
  /**
5422
5422
  * Get a document template by ID
5423
5423
  * @param templateId - ID of the template to retrieve
5424
+ * @param version - Optional version number to retrieve (defaults to latest version)
5424
5425
  * @returns The template or null if not found
5425
5426
  */
5426
- getTemplateById(templateId: string): Promise<DocumentTemplate | null>;
5427
+ getTemplateById(templateId: string, version?: number): Promise<DocumentTemplate | null>;
5427
5428
  /**
5428
5429
  * Update an existing document template
5429
5430
  * @param templateId - ID of the template to update
@@ -5468,6 +5469,19 @@ declare class DocumentationTemplateService {
5468
5469
  templates: DocumentTemplate[];
5469
5470
  lastDoc: QueryDocumentSnapshot<DocumentTemplate> | null;
5470
5471
  }>;
5472
+ /**
5473
+ * Get a specific version of a template
5474
+ * @param templateId - ID of the template
5475
+ * @param versionNumber - Version number to retrieve
5476
+ * @returns The template version or null if not found
5477
+ */
5478
+ getTemplateVersion(templateId: string, versionNumber: number): Promise<DocumentTemplate | null>;
5479
+ /**
5480
+ * Get all versions of a template
5481
+ * @param templateId - ID of the template
5482
+ * @returns Array of template versions
5483
+ */
5484
+ getTemplateVersions(templateId: string): Promise<DocumentTemplate[]>;
5471
5485
  }
5472
5486
 
5473
5487
  export { BackofficeError, BlockingCondition, BlockingConditionError, type Brand, BrandService, type Category, CategoryError, CategoryNotFoundError, CategoryService, CertificationLevel, type CertificationRequirement, CertificationSpecialty, CircularReferenceError, Contraindication, ContraindicationError, type CreateDocumentTemplateData, DEFAULT_CERTIFICATION_REQUIREMENT, type DocumentElement, DocumentElementType, type DocumentTemplate, DocumentationTemplateService, DynamicVariable, HeadingLevel, InvalidBlockingConditionError, InvalidCategoryDataError, InvalidContraindicationError, InvalidHierarchyError, InvalidRequirementDataError, InvalidSubcategoryDataError, InvalidTechnologyDataError, InvalidTimeframeError, InvalidTreatmentBenefitError, ListType, ProcedureFamily, type Product, ProductService, RelationshipError, type Requirement, RequirementError, type RequirementImportance, RequirementNotFoundError, RequirementService, RequirementType, type Subcategory, SubcategoryError, SubcategoryNotFoundError, SubcategoryService, type Technology, TechnologyError, TechnologyNotFoundError, type TechnologyRequirements, TechnologyService, type TimeFrame, TimeUnit, TreatmentBenefit, TreatmentBenefitError, type UpdateDocumentTemplateData, blockingConditionSchema, categorySchema, categoryUpdateSchema, certificationLevelSchema, certificationRequirementSchema, certificationSpecialtySchema, contraindicationSchema, createDocumentTemplateSchema, documentElementSchema, documentElementWithoutIdSchema, documentTemplateSchema, procedureFamilySchema, requirementSchema, requirementTypeSchema, requirementUpdateSchema, subcategorySchema, subcategoryUpdateSchema, technologyRequirementsSchema, technologySchema, technologyUpdateSchema, timeUnitSchema, timeframeSchema, treatmentBenefitSchema, updateDocumentTemplateSchema };
@@ -5421,9 +5421,10 @@ declare class DocumentationTemplateService {
5421
5421
  /**
5422
5422
  * Get a document template by ID
5423
5423
  * @param templateId - ID of the template to retrieve
5424
+ * @param version - Optional version number to retrieve (defaults to latest version)
5424
5425
  * @returns The template or null if not found
5425
5426
  */
5426
- getTemplateById(templateId: string): Promise<DocumentTemplate | null>;
5427
+ getTemplateById(templateId: string, version?: number): Promise<DocumentTemplate | null>;
5427
5428
  /**
5428
5429
  * Update an existing document template
5429
5430
  * @param templateId - ID of the template to update
@@ -5468,6 +5469,19 @@ declare class DocumentationTemplateService {
5468
5469
  templates: DocumentTemplate[];
5469
5470
  lastDoc: QueryDocumentSnapshot<DocumentTemplate> | null;
5470
5471
  }>;
5472
+ /**
5473
+ * Get a specific version of a template
5474
+ * @param templateId - ID of the template
5475
+ * @param versionNumber - Version number to retrieve
5476
+ * @returns The template version or null if not found
5477
+ */
5478
+ getTemplateVersion(templateId: string, versionNumber: number): Promise<DocumentTemplate | null>;
5479
+ /**
5480
+ * Get all versions of a template
5481
+ * @param templateId - ID of the template
5482
+ * @returns Array of template versions
5483
+ */
5484
+ getTemplateVersions(templateId: string): Promise<DocumentTemplate[]>;
5471
5485
  }
5472
5486
 
5473
5487
  export { BackofficeError, BlockingCondition, BlockingConditionError, type Brand, BrandService, type Category, CategoryError, CategoryNotFoundError, CategoryService, CertificationLevel, type CertificationRequirement, CertificationSpecialty, CircularReferenceError, Contraindication, ContraindicationError, type CreateDocumentTemplateData, DEFAULT_CERTIFICATION_REQUIREMENT, type DocumentElement, DocumentElementType, type DocumentTemplate, DocumentationTemplateService, DynamicVariable, HeadingLevel, InvalidBlockingConditionError, InvalidCategoryDataError, InvalidContraindicationError, InvalidHierarchyError, InvalidRequirementDataError, InvalidSubcategoryDataError, InvalidTechnologyDataError, InvalidTimeframeError, InvalidTreatmentBenefitError, ListType, ProcedureFamily, type Product, ProductService, RelationshipError, type Requirement, RequirementError, type RequirementImportance, RequirementNotFoundError, RequirementService, RequirementType, type Subcategory, SubcategoryError, SubcategoryNotFoundError, SubcategoryService, type Technology, TechnologyError, TechnologyNotFoundError, type TechnologyRequirements, TechnologyService, type TimeFrame, TimeUnit, TreatmentBenefit, TreatmentBenefitError, type UpdateDocumentTemplateData, blockingConditionSchema, categorySchema, categoryUpdateSchema, certificationLevelSchema, certificationRequirementSchema, certificationSpecialtySchema, contraindicationSchema, createDocumentTemplateSchema, documentElementSchema, documentElementWithoutIdSchema, documentTemplateSchema, procedureFamilySchema, requirementSchema, requirementTypeSchema, requirementUpdateSchema, subcategorySchema, subcategoryUpdateSchema, technologyRequirementsSchema, technologySchema, technologyUpdateSchema, timeUnitSchema, timeframeSchema, treatmentBenefitSchema, updateDocumentTemplateSchema };
@@ -1611,9 +1611,23 @@ var DocumentationTemplateService = class extends BaseService {
1611
1611
  /**
1612
1612
  * Get a document template by ID
1613
1613
  * @param templateId - ID of the template to retrieve
1614
+ * @param version - Optional version number to retrieve (defaults to latest version)
1614
1615
  * @returns The template or null if not found
1615
1616
  */
1616
- async getTemplateById(templateId) {
1617
+ async getTemplateById(templateId, version) {
1618
+ if (version !== void 0) {
1619
+ try {
1620
+ const versionTemplate = await this.getTemplateVersion(
1621
+ templateId,
1622
+ version
1623
+ );
1624
+ if (versionTemplate) {
1625
+ return versionTemplate;
1626
+ }
1627
+ } catch (error) {
1628
+ console.error(`Error getting template version ${version}:`, error);
1629
+ }
1630
+ }
1617
1631
  const docRef = (0, import_firestore7.doc)(this.collectionRef, templateId);
1618
1632
  const docSnap = await (0, import_firestore7.getDoc)(docRef);
1619
1633
  if (!docSnap.exists()) {
@@ -1635,6 +1649,15 @@ var DocumentationTemplateService = class extends BaseService {
1635
1649
  if (!template) {
1636
1650
  throw new Error(`Template with ID ${templateId} not found`);
1637
1651
  }
1652
+ const versionsCollectionRef = (0, import_firestore7.collection)(
1653
+ this.db,
1654
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
1655
+ );
1656
+ const versionDocRef = (0, import_firestore7.doc)(
1657
+ versionsCollectionRef,
1658
+ template.version.toString()
1659
+ );
1660
+ await (0, import_firestore7.setDoc)(versionDocRef, template);
1638
1661
  let updatedElements = template.elements;
1639
1662
  if (validatedData.elements) {
1640
1663
  updatedElements = validatedData.elements.map((element) => ({
@@ -1663,6 +1686,41 @@ var DocumentationTemplateService = class extends BaseService {
1663
1686
  await (0, import_firestore7.updateDoc)(docRef, updatePayload);
1664
1687
  return { ...template, ...updatePayload };
1665
1688
  }
1689
+ /**
1690
+ * Get a specific version of a template
1691
+ * @param templateId - ID of the template
1692
+ * @param versionNumber - Version number to retrieve
1693
+ * @returns The template version or null if not found
1694
+ */
1695
+ async getTemplateVersion(templateId, versionNumber) {
1696
+ const versionDocRef = (0, import_firestore7.doc)(
1697
+ this.db,
1698
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
1699
+ );
1700
+ const versionDocSnap = await (0, import_firestore7.getDoc)(versionDocRef);
1701
+ if (!versionDocSnap.exists()) {
1702
+ return null;
1703
+ }
1704
+ return versionDocSnap.data();
1705
+ }
1706
+ /**
1707
+ * Get all versions of a template
1708
+ * @param templateId - ID of the template
1709
+ * @returns Array of template versions
1710
+ */
1711
+ async getTemplateOldVersions(templateId) {
1712
+ const versionsCollectionRef = (0, import_firestore7.collection)(
1713
+ this.db,
1714
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
1715
+ );
1716
+ const q = (0, import_firestore7.query)(versionsCollectionRef, (0, import_firestore7.orderBy)("version", "desc"));
1717
+ const querySnapshot = await (0, import_firestore7.getDocs)(q);
1718
+ const versions = [];
1719
+ querySnapshot.forEach((doc9) => {
1720
+ versions.push(doc9.data());
1721
+ });
1722
+ return versions;
1723
+ }
1666
1724
  /**
1667
1725
  * Delete a document template
1668
1726
  * @param templateId - ID of the template to delete
@@ -1810,10 +1868,11 @@ var DocumentationTemplateService2 = class {
1810
1868
  /**
1811
1869
  * Get a document template by ID
1812
1870
  * @param templateId - ID of the template to retrieve
1871
+ * @param version - Optional version number to retrieve (defaults to latest version)
1813
1872
  * @returns The template or null if not found
1814
1873
  */
1815
- async getTemplateById(templateId) {
1816
- return this.apiService.getTemplateById(templateId);
1874
+ async getTemplateById(templateId, version) {
1875
+ return this.apiService.getTemplateById(templateId, version);
1817
1876
  }
1818
1877
  /**
1819
1878
  * Update an existing document template
@@ -1860,6 +1919,23 @@ var DocumentationTemplateService2 = class {
1860
1919
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
1861
1920
  return this.apiService.getTemplatesByCreator(userId, pageSize, lastDoc);
1862
1921
  }
1922
+ /**
1923
+ * Get a specific version of a template
1924
+ * @param templateId - ID of the template
1925
+ * @param versionNumber - Version number to retrieve
1926
+ * @returns The template version or null if not found
1927
+ */
1928
+ async getTemplateVersion(templateId, versionNumber) {
1929
+ return this.apiService.getTemplateVersion(templateId, versionNumber);
1930
+ }
1931
+ /**
1932
+ * Get all versions of a template
1933
+ * @param templateId - ID of the template
1934
+ * @returns Array of template versions
1935
+ */
1936
+ async getTemplateVersions(templateId) {
1937
+ return this.apiService.getTemplateOldVersions(templateId);
1938
+ }
1863
1939
  };
1864
1940
  // Annotate the CommonJS export names for ESM import in node:
1865
1941
  0 && (module.exports = {
@@ -1588,9 +1588,23 @@ var DocumentationTemplateService = class extends BaseService {
1588
1588
  /**
1589
1589
  * Get a document template by ID
1590
1590
  * @param templateId - ID of the template to retrieve
1591
+ * @param version - Optional version number to retrieve (defaults to latest version)
1591
1592
  * @returns The template or null if not found
1592
1593
  */
1593
- async getTemplateById(templateId) {
1594
+ async getTemplateById(templateId, version) {
1595
+ if (version !== void 0) {
1596
+ try {
1597
+ const versionTemplate = await this.getTemplateVersion(
1598
+ templateId,
1599
+ version
1600
+ );
1601
+ if (versionTemplate) {
1602
+ return versionTemplate;
1603
+ }
1604
+ } catch (error) {
1605
+ console.error(`Error getting template version ${version}:`, error);
1606
+ }
1607
+ }
1594
1608
  const docRef = doc7(this.collectionRef, templateId);
1595
1609
  const docSnap = await getDoc7(docRef);
1596
1610
  if (!docSnap.exists()) {
@@ -1612,6 +1626,15 @@ var DocumentationTemplateService = class extends BaseService {
1612
1626
  if (!template) {
1613
1627
  throw new Error(`Template with ID ${templateId} not found`);
1614
1628
  }
1629
+ const versionsCollectionRef = collection7(
1630
+ this.db,
1631
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
1632
+ );
1633
+ const versionDocRef = doc7(
1634
+ versionsCollectionRef,
1635
+ template.version.toString()
1636
+ );
1637
+ await setDoc(versionDocRef, template);
1615
1638
  let updatedElements = template.elements;
1616
1639
  if (validatedData.elements) {
1617
1640
  updatedElements = validatedData.elements.map((element) => ({
@@ -1640,6 +1663,41 @@ var DocumentationTemplateService = class extends BaseService {
1640
1663
  await updateDoc7(docRef, updatePayload);
1641
1664
  return { ...template, ...updatePayload };
1642
1665
  }
1666
+ /**
1667
+ * Get a specific version of a template
1668
+ * @param templateId - ID of the template
1669
+ * @param versionNumber - Version number to retrieve
1670
+ * @returns The template version or null if not found
1671
+ */
1672
+ async getTemplateVersion(templateId, versionNumber) {
1673
+ const versionDocRef = doc7(
1674
+ this.db,
1675
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
1676
+ );
1677
+ const versionDocSnap = await getDoc7(versionDocRef);
1678
+ if (!versionDocSnap.exists()) {
1679
+ return null;
1680
+ }
1681
+ return versionDocSnap.data();
1682
+ }
1683
+ /**
1684
+ * Get all versions of a template
1685
+ * @param templateId - ID of the template
1686
+ * @returns Array of template versions
1687
+ */
1688
+ async getTemplateOldVersions(templateId) {
1689
+ const versionsCollectionRef = collection7(
1690
+ this.db,
1691
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
1692
+ );
1693
+ const q = query7(versionsCollectionRef, orderBy("version", "desc"));
1694
+ const querySnapshot = await getDocs7(q);
1695
+ const versions = [];
1696
+ querySnapshot.forEach((doc9) => {
1697
+ versions.push(doc9.data());
1698
+ });
1699
+ return versions;
1700
+ }
1643
1701
  /**
1644
1702
  * Delete a document template
1645
1703
  * @param templateId - ID of the template to delete
@@ -1798,10 +1856,11 @@ var DocumentationTemplateService2 = class {
1798
1856
  /**
1799
1857
  * Get a document template by ID
1800
1858
  * @param templateId - ID of the template to retrieve
1859
+ * @param version - Optional version number to retrieve (defaults to latest version)
1801
1860
  * @returns The template or null if not found
1802
1861
  */
1803
- async getTemplateById(templateId) {
1804
- return this.apiService.getTemplateById(templateId);
1862
+ async getTemplateById(templateId, version) {
1863
+ return this.apiService.getTemplateById(templateId, version);
1805
1864
  }
1806
1865
  /**
1807
1866
  * Update an existing document template
@@ -1848,6 +1907,23 @@ var DocumentationTemplateService2 = class {
1848
1907
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
1849
1908
  return this.apiService.getTemplatesByCreator(userId, pageSize, lastDoc);
1850
1909
  }
1910
+ /**
1911
+ * Get a specific version of a template
1912
+ * @param templateId - ID of the template
1913
+ * @param versionNumber - Version number to retrieve
1914
+ * @returns The template version or null if not found
1915
+ */
1916
+ async getTemplateVersion(templateId, versionNumber) {
1917
+ return this.apiService.getTemplateVersion(templateId, versionNumber);
1918
+ }
1919
+ /**
1920
+ * Get all versions of a template
1921
+ * @param templateId - ID of the template
1922
+ * @returns Array of template versions
1923
+ */
1924
+ async getTemplateVersions(templateId) {
1925
+ return this.apiService.getTemplateOldVersions(templateId);
1926
+ }
1851
1927
  };
1852
1928
  export {
1853
1929
  BackofficeError,
package/dist/index.d.mts CHANGED
@@ -6409,9 +6409,10 @@ declare class DocumentationTemplateService extends BaseService {
6409
6409
  /**
6410
6410
  * Get a document template by ID
6411
6411
  * @param templateId - ID of the template to retrieve
6412
+ * @param version - Optional version number to retrieve (defaults to latest version)
6412
6413
  * @returns The template or null if not found
6413
6414
  */
6414
- getTemplateById(templateId: string): Promise<DocumentTemplate | null>;
6415
+ getTemplateById(templateId: string, version?: number): Promise<DocumentTemplate | null>;
6415
6416
  /**
6416
6417
  * Update an existing document template
6417
6418
  * @param templateId - ID of the template to update
@@ -6419,6 +6420,19 @@ declare class DocumentationTemplateService extends BaseService {
6419
6420
  * @returns The updated template
6420
6421
  */
6421
6422
  updateTemplate(templateId: string, data: UpdateDocumentTemplateData): Promise<DocumentTemplate>;
6423
+ /**
6424
+ * Get a specific version of a template
6425
+ * @param templateId - ID of the template
6426
+ * @param versionNumber - Version number to retrieve
6427
+ * @returns The template version or null if not found
6428
+ */
6429
+ getTemplateVersion(templateId: string, versionNumber: number): Promise<DocumentTemplate | null>;
6430
+ /**
6431
+ * Get all versions of a template
6432
+ * @param templateId - ID of the template
6433
+ * @returns Array of template versions
6434
+ */
6435
+ getTemplateOldVersions(templateId: string): Promise<DocumentTemplate[]>;
6422
6436
  /**
6423
6437
  * Delete a document template
6424
6438
  * @param templateId - ID of the template to delete
package/dist/index.d.ts CHANGED
@@ -6409,9 +6409,10 @@ declare class DocumentationTemplateService extends BaseService {
6409
6409
  /**
6410
6410
  * Get a document template by ID
6411
6411
  * @param templateId - ID of the template to retrieve
6412
+ * @param version - Optional version number to retrieve (defaults to latest version)
6412
6413
  * @returns The template or null if not found
6413
6414
  */
6414
- getTemplateById(templateId: string): Promise<DocumentTemplate | null>;
6415
+ getTemplateById(templateId: string, version?: number): Promise<DocumentTemplate | null>;
6415
6416
  /**
6416
6417
  * Update an existing document template
6417
6418
  * @param templateId - ID of the template to update
@@ -6419,6 +6420,19 @@ declare class DocumentationTemplateService extends BaseService {
6419
6420
  * @returns The updated template
6420
6421
  */
6421
6422
  updateTemplate(templateId: string, data: UpdateDocumentTemplateData): Promise<DocumentTemplate>;
6423
+ /**
6424
+ * Get a specific version of a template
6425
+ * @param templateId - ID of the template
6426
+ * @param versionNumber - Version number to retrieve
6427
+ * @returns The template version or null if not found
6428
+ */
6429
+ getTemplateVersion(templateId: string, versionNumber: number): Promise<DocumentTemplate | null>;
6430
+ /**
6431
+ * Get all versions of a template
6432
+ * @param templateId - ID of the template
6433
+ * @returns Array of template versions
6434
+ */
6435
+ getTemplateOldVersions(templateId: string): Promise<DocumentTemplate[]>;
6422
6436
  /**
6423
6437
  * Delete a document template
6424
6438
  * @param templateId - ID of the template to delete
package/dist/index.js CHANGED
@@ -8426,9 +8426,23 @@ var DocumentationTemplateService = class extends BaseService {
8426
8426
  /**
8427
8427
  * Get a document template by ID
8428
8428
  * @param templateId - ID of the template to retrieve
8429
+ * @param version - Optional version number to retrieve (defaults to latest version)
8429
8430
  * @returns The template or null if not found
8430
8431
  */
8431
- async getTemplateById(templateId) {
8432
+ async getTemplateById(templateId, version) {
8433
+ if (version !== void 0) {
8434
+ try {
8435
+ const versionTemplate = await this.getTemplateVersion(
8436
+ templateId,
8437
+ version
8438
+ );
8439
+ if (versionTemplate) {
8440
+ return versionTemplate;
8441
+ }
8442
+ } catch (error) {
8443
+ console.error(`Error getting template version ${version}:`, error);
8444
+ }
8445
+ }
8432
8446
  const docRef = (0, import_firestore25.doc)(this.collectionRef, templateId);
8433
8447
  const docSnap = await (0, import_firestore25.getDoc)(docRef);
8434
8448
  if (!docSnap.exists()) {
@@ -8450,6 +8464,15 @@ var DocumentationTemplateService = class extends BaseService {
8450
8464
  if (!template) {
8451
8465
  throw new Error(`Template with ID ${templateId} not found`);
8452
8466
  }
8467
+ const versionsCollectionRef = (0, import_firestore25.collection)(
8468
+ this.db,
8469
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
8470
+ );
8471
+ const versionDocRef = (0, import_firestore25.doc)(
8472
+ versionsCollectionRef,
8473
+ template.version.toString()
8474
+ );
8475
+ await (0, import_firestore25.setDoc)(versionDocRef, template);
8453
8476
  let updatedElements = template.elements;
8454
8477
  if (validatedData.elements) {
8455
8478
  updatedElements = validatedData.elements.map((element) => ({
@@ -8478,6 +8501,41 @@ var DocumentationTemplateService = class extends BaseService {
8478
8501
  await (0, import_firestore25.updateDoc)(docRef, updatePayload);
8479
8502
  return { ...template, ...updatePayload };
8480
8503
  }
8504
+ /**
8505
+ * Get a specific version of a template
8506
+ * @param templateId - ID of the template
8507
+ * @param versionNumber - Version number to retrieve
8508
+ * @returns The template version or null if not found
8509
+ */
8510
+ async getTemplateVersion(templateId, versionNumber) {
8511
+ const versionDocRef = (0, import_firestore25.doc)(
8512
+ this.db,
8513
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
8514
+ );
8515
+ const versionDocSnap = await (0, import_firestore25.getDoc)(versionDocRef);
8516
+ if (!versionDocSnap.exists()) {
8517
+ return null;
8518
+ }
8519
+ return versionDocSnap.data();
8520
+ }
8521
+ /**
8522
+ * Get all versions of a template
8523
+ * @param templateId - ID of the template
8524
+ * @returns Array of template versions
8525
+ */
8526
+ async getTemplateOldVersions(templateId) {
8527
+ const versionsCollectionRef = (0, import_firestore25.collection)(
8528
+ this.db,
8529
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
8530
+ );
8531
+ const q = (0, import_firestore25.query)(versionsCollectionRef, (0, import_firestore25.orderBy)("version", "desc"));
8532
+ const querySnapshot = await (0, import_firestore25.getDocs)(q);
8533
+ const versions = [];
8534
+ querySnapshot.forEach((doc33) => {
8535
+ versions.push(doc33.data());
8536
+ });
8537
+ return versions;
8538
+ }
8481
8539
  /**
8482
8540
  * Delete a document template
8483
8541
  * @param templateId - ID of the template to delete
package/dist/index.mjs CHANGED
@@ -8414,9 +8414,23 @@ var DocumentationTemplateService = class extends BaseService {
8414
8414
  /**
8415
8415
  * Get a document template by ID
8416
8416
  * @param templateId - ID of the template to retrieve
8417
+ * @param version - Optional version number to retrieve (defaults to latest version)
8417
8418
  * @returns The template or null if not found
8418
8419
  */
8419
- async getTemplateById(templateId) {
8420
+ async getTemplateById(templateId, version) {
8421
+ if (version !== void 0) {
8422
+ try {
8423
+ const versionTemplate = await this.getTemplateVersion(
8424
+ templateId,
8425
+ version
8426
+ );
8427
+ if (versionTemplate) {
8428
+ return versionTemplate;
8429
+ }
8430
+ } catch (error) {
8431
+ console.error(`Error getting template version ${version}:`, error);
8432
+ }
8433
+ }
8420
8434
  const docRef = doc16(this.collectionRef, templateId);
8421
8435
  const docSnap = await getDoc19(docRef);
8422
8436
  if (!docSnap.exists()) {
@@ -8438,6 +8452,15 @@ var DocumentationTemplateService = class extends BaseService {
8438
8452
  if (!template) {
8439
8453
  throw new Error(`Template with ID ${templateId} not found`);
8440
8454
  }
8455
+ const versionsCollectionRef = collection16(
8456
+ this.db,
8457
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
8458
+ );
8459
+ const versionDocRef = doc16(
8460
+ versionsCollectionRef,
8461
+ template.version.toString()
8462
+ );
8463
+ await setDoc14(versionDocRef, template);
8441
8464
  let updatedElements = template.elements;
8442
8465
  if (validatedData.elements) {
8443
8466
  updatedElements = validatedData.elements.map((element) => ({
@@ -8466,6 +8489,41 @@ var DocumentationTemplateService = class extends BaseService {
8466
8489
  await updateDoc16(docRef, updatePayload);
8467
8490
  return { ...template, ...updatePayload };
8468
8491
  }
8492
+ /**
8493
+ * Get a specific version of a template
8494
+ * @param templateId - ID of the template
8495
+ * @param versionNumber - Version number to retrieve
8496
+ * @returns The template version or null if not found
8497
+ */
8498
+ async getTemplateVersion(templateId, versionNumber) {
8499
+ const versionDocRef = doc16(
8500
+ this.db,
8501
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
8502
+ );
8503
+ const versionDocSnap = await getDoc19(versionDocRef);
8504
+ if (!versionDocSnap.exists()) {
8505
+ return null;
8506
+ }
8507
+ return versionDocSnap.data();
8508
+ }
8509
+ /**
8510
+ * Get all versions of a template
8511
+ * @param templateId - ID of the template
8512
+ * @returns Array of template versions
8513
+ */
8514
+ async getTemplateOldVersions(templateId) {
8515
+ const versionsCollectionRef = collection16(
8516
+ this.db,
8517
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
8518
+ );
8519
+ const q = query16(versionsCollectionRef, orderBy5("version", "desc"));
8520
+ const querySnapshot = await getDocs16(q);
8521
+ const versions = [];
8522
+ querySnapshot.forEach((doc33) => {
8523
+ versions.push(doc33.data());
8524
+ });
8525
+ return versions;
8526
+ }
8469
8527
  /**
8470
8528
  * Delete a document template
8471
8529
  * @param templateId - ID of the template to delete
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.6.23",
4
+ "version": "1.6.24",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -41,10 +41,14 @@ export class DocumentationTemplateService {
41
41
  /**
42
42
  * Get a document template by ID
43
43
  * @param templateId - ID of the template to retrieve
44
+ * @param version - Optional version number to retrieve (defaults to latest version)
44
45
  * @returns The template or null if not found
45
46
  */
46
- async getTemplateById(templateId: string): Promise<DocumentTemplate | null> {
47
- return this.apiService.getTemplateById(templateId);
47
+ async getTemplateById(
48
+ templateId: string,
49
+ version?: number
50
+ ): Promise<DocumentTemplate | null> {
51
+ return this.apiService.getTemplateById(templateId, version);
48
52
  }
49
53
 
50
54
  /**
@@ -119,4 +123,26 @@ export class DocumentationTemplateService {
119
123
  }> {
120
124
  return this.apiService.getTemplatesByCreator(userId, pageSize, lastDoc);
121
125
  }
126
+
127
+ /**
128
+ * Get a specific version of a template
129
+ * @param templateId - ID of the template
130
+ * @param versionNumber - Version number to retrieve
131
+ * @returns The template version or null if not found
132
+ */
133
+ async getTemplateVersion(
134
+ templateId: string,
135
+ versionNumber: number
136
+ ): Promise<DocumentTemplate | null> {
137
+ return this.apiService.getTemplateVersion(templateId, versionNumber);
138
+ }
139
+
140
+ /**
141
+ * Get all versions of a template
142
+ * @param templateId - ID of the template
143
+ * @returns Array of template versions
144
+ */
145
+ async getTemplateVersions(templateId: string): Promise<DocumentTemplate[]> {
146
+ return this.apiService.getTemplateOldVersions(templateId);
147
+ }
122
148
  }
@@ -88,9 +88,32 @@ export class DocumentationTemplateService extends BaseService {
88
88
  /**
89
89
  * Get a document template by ID
90
90
  * @param templateId - ID of the template to retrieve
91
+ * @param version - Optional version number to retrieve (defaults to latest version)
91
92
  * @returns The template or null if not found
92
93
  */
93
- async getTemplateById(templateId: string): Promise<DocumentTemplate | null> {
94
+ async getTemplateById(
95
+ templateId: string,
96
+ version?: number
97
+ ): Promise<DocumentTemplate | null> {
98
+ // If version is specified, try to get that specific version
99
+ if (version !== undefined) {
100
+ try {
101
+ const versionTemplate = await this.getTemplateVersion(
102
+ templateId,
103
+ version
104
+ );
105
+ // If the version exists, return it
106
+ if (versionTemplate) {
107
+ return versionTemplate;
108
+ }
109
+ // If version doesn't exist, fall back to latest version (continue with code below)
110
+ } catch (error) {
111
+ console.error(`Error getting template version ${version}:`, error);
112
+ // Fall back to latest version if error occurs
113
+ }
114
+ }
115
+
116
+ // Get the latest version (default behavior)
94
117
  const docRef = doc(this.collectionRef, templateId);
95
118
  const docSnap = await getDoc(docRef);
96
119
 
@@ -121,6 +144,17 @@ export class DocumentationTemplateService extends BaseService {
121
144
  throw new Error(`Template with ID ${templateId} not found`);
122
145
  }
123
146
 
147
+ // Store the current version in the versions subcollection
148
+ const versionsCollectionRef = collection(
149
+ this.db,
150
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
151
+ );
152
+ const versionDocRef = doc(
153
+ versionsCollectionRef,
154
+ template.version.toString()
155
+ );
156
+ await setDoc(versionDocRef, template);
157
+
124
158
  // Process elements if provided
125
159
  let updatedElements = template.elements;
126
160
  if (validatedData.elements) {
@@ -158,6 +192,53 @@ export class DocumentationTemplateService extends BaseService {
158
192
  return { ...template, ...updatePayload } as DocumentTemplate;
159
193
  }
160
194
 
195
+ /**
196
+ * Get a specific version of a template
197
+ * @param templateId - ID of the template
198
+ * @param versionNumber - Version number to retrieve
199
+ * @returns The template version or null if not found
200
+ */
201
+ async getTemplateVersion(
202
+ templateId: string,
203
+ versionNumber: number
204
+ ): Promise<DocumentTemplate | null> {
205
+ const versionDocRef = doc(
206
+ this.db,
207
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
208
+ );
209
+ const versionDocSnap = await getDoc(versionDocRef);
210
+
211
+ if (!versionDocSnap.exists()) {
212
+ return null;
213
+ }
214
+
215
+ return versionDocSnap.data() as DocumentTemplate;
216
+ }
217
+
218
+ /**
219
+ * Get all versions of a template
220
+ * @param templateId - ID of the template
221
+ * @returns Array of template versions
222
+ */
223
+ async getTemplateOldVersions(
224
+ templateId: string
225
+ ): Promise<DocumentTemplate[]> {
226
+ const versionsCollectionRef = collection(
227
+ this.db,
228
+ `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
229
+ );
230
+ const q = query(versionsCollectionRef, orderBy("version", "desc"));
231
+
232
+ const querySnapshot = await getDocs(q);
233
+ const versions: DocumentTemplate[] = [];
234
+
235
+ querySnapshot.forEach((doc) => {
236
+ versions.push(doc.data() as DocumentTemplate);
237
+ });
238
+
239
+ return versions;
240
+ }
241
+
161
242
  /**
162
243
  * Delete a document template
163
244
  * @param templateId - ID of the template to delete