@zodic/shared 0.0.379 → 0.0.381

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.
@@ -858,25 +858,29 @@ export class ArchetypeService {
858
858
  rawResponse: ptResponse,
859
859
  });
860
860
 
861
- await this.log('debug', `Parsing PT content response for archetype ${index}`);
862
- const ptContent = this.parseContentResponse(ptResponse, 'PT');
863
- await this.log('info', `Parsed PT content for archetype ${index}`, { ptContent });
861
+ await this.log('debug', `Parsing PT-M content response for archetype ${index}`);
862
+ const ptMaleContentParsed = this.parseContentResponse(ptResponse, 'PT', 'male');
863
+ await this.log('info', `Parsed PT-M content for archetype ${index}`, { ptMaleContentParsed });
864
+
865
+ await this.log('debug', `Parsing PT-F content response for archetype ${index}`);
866
+ const ptFemaleContentParsed = this.parseContentResponse(ptResponse, 'PT', 'female');
867
+ await this.log('info', `Parsed PT-F content for archetype ${index}`, { ptFemaleContentParsed });
864
868
 
865
869
  const ptMaleContent = [
866
- { section: 'voiceOfTheSoul', text: ptContent.voiceOfTheSoul },
867
- { section: 'giftsYouBear', text: ptContent.giftsYouBear },
868
- { section: 'shadowsYouFace', text: ptContent.shadowsYouFace },
869
- { section: 'rhythmOfYourDays', text: ptContent.rhythmOfYourDays },
870
- { section: 'tiesThatBind', text: ptContent.tiesThatBind },
871
- { section: 'lightWithin', text: ptContent.lightWithin },
870
+ { section: 'voiceOfTheSoul', text: ptMaleContentParsed.voiceOfTheSoul },
871
+ { section: 'giftsYouBear', text: ptMaleContentParsed.giftsYouBear },
872
+ { section: 'shadowsYouFace', text: ptMaleContentParsed.shadowsYouFace },
873
+ { section: 'rhythmOfYourDays', text: ptMaleContentParsed.rhythmOfYourDays },
874
+ { section: 'tiesThatBind', text: ptMaleContentParsed.tiesThatBind },
875
+ { section: 'lightWithin', text: ptMaleContentParsed.lightWithin },
872
876
  ];
873
877
  const ptFemaleContent = [
874
- { section: 'voiceOfTheSoul', text: ptContent.voiceOfTheSoul.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
875
- { section: 'giftsYouBear', text: ptContent.giftsYouBear.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
876
- { section: 'shadowsYouFace', text: ptContent.shadowsYouFace.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
877
- { section: 'rhythmOfYourDays', text: ptContent.rhythmOfYourDays.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
878
- { section: 'tiesThatBind', text: ptContent.tiesThatBind.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
879
- { section: 'lightWithin', text: ptContent.lightWithin.replace(/ele/g, 'ela').replace(/seu/g, 'sua') },
878
+ { section: 'voiceOfTheSoul', text: ptFemaleContentParsed.voiceOfTheSoul },
879
+ { section: 'giftsYouBear', text: ptFemaleContentParsed.giftsYouBear },
880
+ { section: 'shadowsYouFace', text: ptFemaleContentParsed.shadowsYouFace },
881
+ { section: 'rhythmOfYourDays', text: ptFemaleContentParsed.rhythmOfYourDays },
882
+ { section: 'tiesThatBind', text: ptFemaleContentParsed.tiesThatBind },
883
+ { section: 'lightWithin', text: ptFemaleContentParsed.lightWithin },
880
884
  ];
881
885
 
882
886
  await this.log('debug', `Updating PT-M content for ${ptIds.male}`, { content: ptMaleContent });
@@ -921,13 +925,13 @@ export class ArchetypeService {
921
925
  return contentResults;
922
926
  }
923
927
 
924
- private parseContentResponse(response: string, section: string) {
925
- this.log('debug', 'Starting parseContentResponse', { responseLength: response.length, section });
928
+ private parseContentResponse(response: string, section: string, gender: Gender | null = null) {
929
+ this.log('debug', 'Starting parseContentResponse', { responseLength: response.length, section, gender });
926
930
 
927
- const lines = response.split('\n').map(line => line.trim()); // Trim each line
931
+ const lines = response.split('\n').map(line => line.trim());
928
932
  this.log('debug', 'Split response into lines', { linesCount: lines.length, lines });
929
933
 
930
- // Skip initial --- and any empty lines
934
+ // Skip initial --- and empty lines
931
935
  let startIndex = 0;
932
936
  while (startIndex < lines.length && (lines[startIndex] === '---' || lines[startIndex] === '')) {
933
937
  startIndex++;
@@ -938,65 +942,99 @@ export class ArchetypeService {
938
942
  throw new Error(`No content found after skipping delimiters for ${section}`);
939
943
  }
940
944
 
941
- const expectedHeader = `${section}:`;
942
- const actualHeader = lines[startIndex];
943
- if (!actualHeader.startsWith(expectedHeader)) {
944
- this.log('error', `Invalid language header for ${section}`, {
945
- expected: expectedHeader,
946
- found: actualHeader,
947
- });
948
- throw new Error(`Invalid language header for ${section}: expected ${expectedHeader}, got ${actualHeader}`);
949
- }
950
-
951
- const content: Record<string, string> = {};
945
+ const content: Record<string, Record<string, string>> = { 'PT-M:': {}, 'PT-F:': {}, 'EN:': {} };
946
+ let currentSectionHeader = '';
952
947
  let currentSection = '';
953
948
  let currentText: string[] = [];
949
+ let currentLang = '';
950
+
951
+ for (let i = startIndex; i < lines.length; i++) {
952
+ const line = lines[i];
953
+
954
+ if (line === '---') {
955
+ if (currentSection && currentText.length > 0) {
956
+ const key = currentSection.toLowerCase().replace(/\s+/g, '').replace(/([A-Z])/g, (match) => match.toLowerCase());
957
+ content[currentLang][key] = currentText.join(' ').trim();
958
+ this.log('debug', `Extracted section ${currentSection} for ${currentLang}`, { key, text: content[currentLang][key] });
959
+ }
960
+ currentSection = '';
961
+ currentText = [];
962
+ // Look for the next header
963
+ while (i + 1 < lines.length && (lines[i + 1] === '' || lines[i + 1] === '---')) {
964
+ i++;
965
+ }
966
+ if (i + 1 < lines.length && (lines[i + 1] === 'PT-M:' || lines[i + 1] === 'PT-F:' || lines[i + 1] === 'EN:')) {
967
+ i++;
968
+ currentLang = lines[i];
969
+ this.log('debug', `Found new language section: ${currentLang}`);
970
+ }
971
+ continue;
972
+ }
973
+
974
+ if (line === 'PT-M:' || line === 'PT-F:' || line === 'EN:') {
975
+ currentLang = line;
976
+ this.log('debug', `Starting language section: ${currentLang}`);
977
+ continue;
978
+ }
954
979
 
955
- for (const line of lines.slice(startIndex + 1)) {
956
980
  if (line.startsWith('#')) {
957
981
  if (currentSection && currentText.length > 0) {
958
982
  const key = currentSection.toLowerCase().replace(/\s+/g, '').replace(/([A-Z])/g, (match) => match.toLowerCase());
959
- content[key] = currentText.join(' ').trim();
960
- this.log('debug', `Extracted section ${currentSection} for ${section}`, {
961
- key,
962
- text: content[key],
963
- });
983
+ content[currentLang][key] = currentText.join(' ').trim();
984
+ this.log('debug', `Extracted section ${currentSection} for ${currentLang}`, { key, text: content[currentLang][key] });
964
985
  }
965
986
  currentSection = line.replace('# ', '');
987
+ currentSectionHeader = currentSection.toLowerCase();
966
988
  currentText = [];
967
- this.log('debug', `Starting new section ${currentSection} for ${section}`);
968
- } else if (line) { // Ignore empty lines
989
+ this.log('debug', `Starting new section ${currentSection} for ${currentLang}`);
990
+ } else if (line) {
969
991
  currentText.push(line);
992
+ this.log('debug', `Adding line to ${currentSection} for ${currentLang}`, { line });
970
993
  }
971
994
  }
972
995
 
996
+ // Handle the last section
973
997
  if (currentSection && currentText.length > 0) {
974
998
  const key = currentSection.toLowerCase().replace(/\s+/g, '').replace(/([A-Z])/g, (match) => match.toLowerCase());
975
- content[key] = currentText.join(' ').trim();
976
- this.log('debug', `Extracted final section ${currentSection} for ${section}`, {
977
- key,
978
- text: content[key],
979
- });
999
+ content[currentLang][key] = currentText.join(' ').trim();
1000
+ this.log('debug', `Extracted final section ${currentSection} for ${currentLang}`, { key, text: content[currentLang][key] });
1001
+ }
1002
+
1003
+ // Log the full content object for debugging
1004
+ this.log('debug', `Full parsed content before selection`, { content });
1005
+
1006
+ // Determine which content to return based on section and gender
1007
+ let targetLang = section;
1008
+ if (section === 'PT') {
1009
+ targetLang = gender === 'male' ? 'PT-M:' : 'PT-F:';
1010
+ } else {
1011
+ targetLang = `${section}:`;
1012
+ }
1013
+
1014
+ const targetContent = content[targetLang];
1015
+ if (!targetContent) {
1016
+ this.log('error', `No content found for target ${targetLang}`, { response, section, gender });
1017
+ throw new Error(`No content found for target ${targetLang}`);
980
1018
  }
981
1019
 
982
1020
  const parsedContent = {
983
- voiceOfTheSoul: content['thevoiceofthesoul'] || content['avozdaalma'] || '',
984
- giftsYouBear: content['thegiftsyoubear'] || content['osdonsquevocêcarrega'] || '',
985
- shadowsYouFace: content['theshadowsyouface'] || content['assombrasqueenfrenta'] || '',
986
- rhythmOfYourDays: content['therhythmofyourdays'] || content['oritmodosseusdias'] || '',
987
- tiesThatBind: content['thetiesthatbind'] || content['oslaçosqueteconectam'] || '',
988
- lightWithin: content['thelightwithin'] || content['aluzinterior'] || '',
1021
+ voiceOfTheSoul: targetContent['thevoiceofthesoul'] || targetContent['avozdaalma'] || '',
1022
+ giftsYouBear: targetContent['thegiftsyoubear'] || targetContent['osdonsquevocêcarrega'] || '',
1023
+ shadowsYouFace: targetContent['theshadowsyouface'] || targetContent['assombrasqueenfrenta'] || '',
1024
+ rhythmOfYourDays: targetContent['therhythmofyourdays'] || targetContent['oritmodosseusdias'] || '',
1025
+ tiesThatBind: targetContent['thetiesthatbind'] || targetContent['oslaçosqueteconectam'] || '',
1026
+ lightWithin: targetContent['thelightwithin'] || targetContent['aluzinterior'] || '',
989
1027
  };
990
1028
 
1029
+ // Log the parsed content before validation
1030
+ this.log('debug', `Parsed content before validation for ${targetLang}`, { parsedContent });
1031
+
991
1032
  if (Object.values(parsedContent).some((value) => !value)) {
992
- this.log('error', `Malformed content response for ${section}`, {
993
- parsedContent,
994
- response,
995
- });
996
- throw new Error(`Malformed content response for ${section}`);
1033
+ this.log('error', `Malformed content response for ${targetLang}`, { parsedContent, response });
1034
+ throw new Error(`Malformed content response for ${targetLang}`);
997
1035
  }
998
1036
 
999
- this.log('info', 'Completed parseContentResponse', { parsedContent, section });
1037
+ this.log('info', 'Completed parseContentResponse', { parsedContent, section, gender });
1000
1038
  return parsedContent;
1001
1039
  }
1002
1040
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.379",
3
+ "version": "0.0.381",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {