@zodic/shared 0.0.409 → 0.0.412

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/app/api/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import OpenAI from 'openai';
2
2
  import {
3
+ AstroEngineInput,
4
+ AstroEngineResponse,
3
5
  BackendBindings,
4
6
  BatchInputItem,
5
7
  ChatGPTBatchResponse,
@@ -639,6 +641,44 @@ export const Api = (env: BackendBindings) => ({
639
641
  },
640
642
  },
641
643
 
644
+ callAstroEngine: {
645
+ calculateFullChart: async (payload: AstroEngineInput): Promise<AstroEngineResponse> => {
646
+ // Verifica se o binding existe (segurança para não quebrar em dev local se não tiver configurado)
647
+ if (!env.ASTRO_API) {
648
+ console.error("❌ ASTRO_API binding não encontrado via Service Binding");
649
+ throw new Error("Configuração de ambiente inválida: ASTRO_API ausente");
650
+ }
651
+
652
+ console.log(`🌌 [ENGINE] Chamando Python Container via Service Binding`);
653
+
654
+ try {
655
+ // AQUI ESTÁ A DIFERENÇA: Usamos o fetch DO BINDING, não o global.
656
+ // O hostname 'http://astro-engine' é ignorado pelo binding, só o path importa.
657
+ const response = await env.ASTRO_API.fetch('http://astro-engine/calculate-full-chart', {
658
+ method: 'POST',
659
+ headers: {
660
+ 'Content-Type': 'application/json',
661
+ // Não precisa de Authorization header pois é comunicação interna segura
662
+ },
663
+ body: JSON.stringify(payload),
664
+ });
665
+
666
+ if (!response.ok) {
667
+ const errorText = await response.text();
668
+ console.error(`❌ [ENGINE ERROR] Status: ${response.status} - ${errorText}`);
669
+ throw new Error(`Erro no motor astrológico: ${response.status}`);
670
+ }
671
+
672
+ // O Python retorna exatamente o JSON que definimos
673
+ return (await response.json()) as AstroEngineResponse;
674
+
675
+ } catch (err: any) {
676
+ console.error('❌ [ENGINE FATAL] Falha ao conectar no Container Python:', err.message);
677
+ throw err;
678
+ }
679
+ },
680
+ },
681
+
642
682
  callTimezone: async ({
643
683
  lat,
644
684
  lon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.409",
3
+ "version": "0.0.412",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Ai,
3
3
  D1Database,
4
+ Fetcher,
4
5
  KVNamespace,
5
6
  Queue,
6
7
  R2Bucket,
@@ -59,6 +60,7 @@ export type CentralBindings = {
59
60
  ASAAS_API_KEY: string;
60
61
 
61
62
  API_BASE_URL: string;
63
+ ASTRO_API: Fetcher;
62
64
  };
63
65
 
64
66
  export type Variables = {
@@ -105,6 +107,7 @@ export type BackendBindings = Env &
105
107
  | 'ASAAS_API_KEY'
106
108
  | 'ASAAS_API_URL'
107
109
  | 'PAYMENT_QUEUE'
110
+ | 'ASTRO_API'
108
111
  >;
109
112
 
110
113
  export type BackendCtx = Context<
@@ -663,3 +663,47 @@ export interface ProductLabels {
663
663
  };
664
664
  }
665
665
 
666
+ // types/astro-engine.ts
667
+
668
+ export interface AstroEnginePoint {
669
+ name: string;
670
+ type: 'planet' | 'karmic_point' | 'arabic_part' | 'key_point';
671
+ sign: string;
672
+ full_degree: number;
673
+ norm_degree: number;
674
+ house: number;
675
+ speed: number;
676
+ is_retro: boolean;
677
+ }
678
+
679
+ export interface AstroEngineHouse {
680
+ house: number;
681
+ sign: string;
682
+ degree: number;
683
+ }
684
+
685
+ export interface AstroEngineAspect {
686
+ aspecting_planet: string;
687
+ aspected_planet: string;
688
+ type: string;
689
+ orb: number;
690
+ diff: number;
691
+ }
692
+
693
+ export interface AstroEngineResponse {
694
+ meta: {
695
+ is_diurnal: boolean;
696
+ sun_house: number;
697
+ };
698
+ points: Record<string, AstroEnginePoint>;
699
+ houses: AstroEngineHouse[];
700
+ aspects: AstroEngineAspect[];
701
+ }
702
+
703
+ // Input payload expected by the Python Container
704
+ export interface AstroEngineInput {
705
+ date: string; // "YYYY/MM/DD"
706
+ time: string; // "HH:MM" (UTC)
707
+ lat: number;
708
+ lon: number;
709
+ }