@blackcode_sa/metaestetics-api 1.6.22 → 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()) {
@@ -1628,12 +1642,22 @@ var DocumentationTemplateService = class extends BaseService {
1628
1642
  * @returns The updated template
1629
1643
  */
1630
1644
  async updateTemplate(templateId, data) {
1631
- var _a, _b, _c, _d, _e, _f;
1645
+ var _a, _b, _c;
1632
1646
  const validatedData = updateDocumentTemplateSchema.parse(data);
1647
+ console.log("Validated data", validatedData);
1633
1648
  const template = await this.getTemplateById(templateId);
1634
1649
  if (!template) {
1635
1650
  throw new Error(`Template with ID ${templateId} not found`);
1636
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);
1637
1661
  let updatedElements = template.elements;
1638
1662
  if (validatedData.elements) {
1639
1663
  updatedElements = validatedData.elements.map((element) => ({
@@ -1654,13 +1678,49 @@ var DocumentationTemplateService = class extends BaseService {
1654
1678
  updatePayload.isActive = validatedData.isActive;
1655
1679
  if (validatedData.tags !== void 0)
1656
1680
  updatePayload.tags = validatedData.tags;
1657
- updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
1658
- updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
1659
- updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
1681
+ updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
1682
+ updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
1683
+ updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
1660
1684
  const docRef = (0, import_firestore7.doc)(this.collectionRef, templateId);
1685
+ console.log("Update payload", updatePayload);
1661
1686
  await (0, import_firestore7.updateDoc)(docRef, updatePayload);
1662
1687
  return { ...template, ...updatePayload };
1663
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
+ }
1664
1724
  /**
1665
1725
  * Delete a document template
1666
1726
  * @param templateId - ID of the template to delete
@@ -1808,10 +1868,11 @@ var DocumentationTemplateService2 = class {
1808
1868
  /**
1809
1869
  * Get a document template by ID
1810
1870
  * @param templateId - ID of the template to retrieve
1871
+ * @param version - Optional version number to retrieve (defaults to latest version)
1811
1872
  * @returns The template or null if not found
1812
1873
  */
1813
- async getTemplateById(templateId) {
1814
- return this.apiService.getTemplateById(templateId);
1874
+ async getTemplateById(templateId, version) {
1875
+ return this.apiService.getTemplateById(templateId, version);
1815
1876
  }
1816
1877
  /**
1817
1878
  * Update an existing document template
@@ -1858,6 +1919,23 @@ var DocumentationTemplateService2 = class {
1858
1919
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
1859
1920
  return this.apiService.getTemplatesByCreator(userId, pageSize, lastDoc);
1860
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
+ }
1861
1939
  };
1862
1940
  // Annotate the CommonJS export names for ESM import in node:
1863
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()) {
@@ -1605,12 +1619,22 @@ var DocumentationTemplateService = class extends BaseService {
1605
1619
  * @returns The updated template
1606
1620
  */
1607
1621
  async updateTemplate(templateId, data) {
1608
- var _a, _b, _c, _d, _e, _f;
1622
+ var _a, _b, _c;
1609
1623
  const validatedData = updateDocumentTemplateSchema.parse(data);
1624
+ console.log("Validated data", validatedData);
1610
1625
  const template = await this.getTemplateById(templateId);
1611
1626
  if (!template) {
1612
1627
  throw new Error(`Template with ID ${templateId} not found`);
1613
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);
1614
1638
  let updatedElements = template.elements;
1615
1639
  if (validatedData.elements) {
1616
1640
  updatedElements = validatedData.elements.map((element) => ({
@@ -1631,13 +1655,49 @@ var DocumentationTemplateService = class extends BaseService {
1631
1655
  updatePayload.isActive = validatedData.isActive;
1632
1656
  if (validatedData.tags !== void 0)
1633
1657
  updatePayload.tags = validatedData.tags;
1634
- updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
1635
- updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
1636
- updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
1658
+ updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
1659
+ updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
1660
+ updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
1637
1661
  const docRef = doc7(this.collectionRef, templateId);
1662
+ console.log("Update payload", updatePayload);
1638
1663
  await updateDoc7(docRef, updatePayload);
1639
1664
  return { ...template, ...updatePayload };
1640
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
+ }
1641
1701
  /**
1642
1702
  * Delete a document template
1643
1703
  * @param templateId - ID of the template to delete
@@ -1796,10 +1856,11 @@ var DocumentationTemplateService2 = class {
1796
1856
  /**
1797
1857
  * Get a document template by ID
1798
1858
  * @param templateId - ID of the template to retrieve
1859
+ * @param version - Optional version number to retrieve (defaults to latest version)
1799
1860
  * @returns The template or null if not found
1800
1861
  */
1801
- async getTemplateById(templateId) {
1802
- return this.apiService.getTemplateById(templateId);
1862
+ async getTemplateById(templateId, version) {
1863
+ return this.apiService.getTemplateById(templateId, version);
1803
1864
  }
1804
1865
  /**
1805
1866
  * Update an existing document template
@@ -1846,6 +1907,23 @@ var DocumentationTemplateService2 = class {
1846
1907
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
1847
1908
  return this.apiService.getTemplatesByCreator(userId, pageSize, lastDoc);
1848
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
+ }
1849
1927
  };
1850
1928
  export {
1851
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()) {
@@ -8443,12 +8457,22 @@ var DocumentationTemplateService = class extends BaseService {
8443
8457
  * @returns The updated template
8444
8458
  */
8445
8459
  async updateTemplate(templateId, data) {
8446
- var _a, _b, _c, _d, _e, _f;
8460
+ var _a, _b, _c;
8447
8461
  const validatedData = updateDocumentTemplateSchema.parse(data);
8462
+ console.log("Validated data", validatedData);
8448
8463
  const template = await this.getTemplateById(templateId);
8449
8464
  if (!template) {
8450
8465
  throw new Error(`Template with ID ${templateId} not found`);
8451
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);
8452
8476
  let updatedElements = template.elements;
8453
8477
  if (validatedData.elements) {
8454
8478
  updatedElements = validatedData.elements.map((element) => ({
@@ -8469,13 +8493,49 @@ var DocumentationTemplateService = class extends BaseService {
8469
8493
  updatePayload.isActive = validatedData.isActive;
8470
8494
  if (validatedData.tags !== void 0)
8471
8495
  updatePayload.tags = validatedData.tags;
8472
- updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
8473
- updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
8474
- updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
8496
+ updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
8497
+ updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
8498
+ updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
8475
8499
  const docRef = (0, import_firestore25.doc)(this.collectionRef, templateId);
8500
+ console.log("Update payload", updatePayload);
8476
8501
  await (0, import_firestore25.updateDoc)(docRef, updatePayload);
8477
8502
  return { ...template, ...updatePayload };
8478
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
+ }
8479
8539
  /**
8480
8540
  * Delete a document template
8481
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()) {
@@ -8431,12 +8445,22 @@ var DocumentationTemplateService = class extends BaseService {
8431
8445
  * @returns The updated template
8432
8446
  */
8433
8447
  async updateTemplate(templateId, data) {
8434
- var _a, _b, _c, _d, _e, _f;
8448
+ var _a, _b, _c;
8435
8449
  const validatedData = updateDocumentTemplateSchema.parse(data);
8450
+ console.log("Validated data", validatedData);
8436
8451
  const template = await this.getTemplateById(templateId);
8437
8452
  if (!template) {
8438
8453
  throw new Error(`Template with ID ${templateId} not found`);
8439
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);
8440
8464
  let updatedElements = template.elements;
8441
8465
  if (validatedData.elements) {
8442
8466
  updatedElements = validatedData.elements.map((element) => ({
@@ -8457,13 +8481,49 @@ var DocumentationTemplateService = class extends BaseService {
8457
8481
  updatePayload.isActive = validatedData.isActive;
8458
8482
  if (validatedData.tags !== void 0)
8459
8483
  updatePayload.tags = validatedData.tags;
8460
- updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
8461
- updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
8462
- updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
8484
+ updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
8485
+ updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
8486
+ updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
8463
8487
  const docRef = doc16(this.collectionRef, templateId);
8488
+ console.log("Update payload", updatePayload);
8464
8489
  await updateDoc16(docRef, updatePayload);
8465
8490
  return { ...template, ...updatePayload };
8466
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
+ }
8467
8527
  /**
8468
8528
  * Delete a document template
8469
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.22",
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
 
@@ -113,6 +136,7 @@ export class DocumentationTemplateService extends BaseService {
113
136
  ): Promise<DocumentTemplate> {
114
137
  // Validate data
115
138
  const validatedData = updateDocumentTemplateSchema.parse(data);
139
+ console.log("Validated data", validatedData);
116
140
 
117
141
  // Get existing template
118
142
  const template = await this.getTemplateById(templateId);
@@ -120,6 +144,17 @@ export class DocumentationTemplateService extends BaseService {
120
144
  throw new Error(`Template with ID ${templateId} not found`);
121
145
  }
122
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
+
123
158
  // Process elements if provided
124
159
  let updatedElements = template.elements;
125
160
  if (validatedData.elements) {
@@ -146,19 +181,64 @@ export class DocumentationTemplateService extends BaseService {
146
181
  updatePayload.tags = validatedData.tags;
147
182
 
148
183
  // Always include these properties with defaults if they're missing
149
- updatePayload.isUserForm =
150
- validatedData.isUserForm ?? template.isUserForm ?? false;
151
- updatePayload.isRequired =
152
- validatedData.isRequired ?? template.isRequired ?? false;
153
- updatePayload.sortingOrder =
154
- validatedData.sortingOrder ?? template.sortingOrder ?? 0;
184
+ updatePayload.isUserForm = validatedData.isUserForm ?? false;
185
+ updatePayload.isRequired = validatedData.isRequired ?? false;
186
+ updatePayload.sortingOrder = validatedData.sortingOrder ?? 0;
155
187
 
156
188
  const docRef = doc(this.collectionRef, templateId);
189
+ console.log("Update payload", updatePayload);
157
190
  await updateDoc(docRef, updatePayload);
158
191
 
159
192
  return { ...template, ...updatePayload } as DocumentTemplate;
160
193
  }
161
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
+
162
242
  /**
163
243
  * Delete a document template
164
244
  * @param templateId - ID of the template to delete