lifeastroapi 0.8.0 → 0.9.1

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/README.md CHANGED
@@ -17,6 +17,8 @@ Free tier: 1,500 credits a month, no card — [get a key](https://lifeastroapi.c
17
17
  print-ready kundli / matchmaking / numerology / horoscope PDFs. Rendering needs
18
18
  Puppeteer (a headless Chrome), installed separately — see
19
19
  [Branded PDF reports](#branded-pdf-reports).
20
+ - ✅ **React Native and Expo**: the same client, and report PDFs printed on the
21
+ device from `lifeastroapi/pdf-html` — see [React Native and Expo](#react-native-and-expo).
20
22
 
21
23
  ```bash
22
24
  npm install lifeastroapi
@@ -83,8 +85,9 @@ error. Get a key at **https://lifeastroapi.com/dashboard/keys**.
83
85
  > desktop, or any client-side code**, where end users could extract it and run up your bill.
84
86
  > For client apps, call LifeAstroAPI from your own backend and forward the results.
85
87
  >
86
- > (Need PDFs in the browser? The dependency-free `lifeastroapi/pdf` `render*Html`
87
- > functions take **no key** and are safe to run anywhere — see [Branded PDF reports](#branded-pdf-reports).)
88
+ > (Need PDFs in a browser or a mobile app? The dependency-free `render*Html` functions of
89
+ > `lifeastroapi/pdf-html` take **no key** and are safe to run anywhere — see
90
+ > [React Native and Expo](#react-native-and-expo).)
88
91
 
89
92
  ## Configuration
90
93
 
@@ -113,7 +116,7 @@ exact wire parameters the API expects (`birth.lat`, `boy.date`, `start_date`,
113
116
  | **Two-person** | `western.synastry.*`, `western.composite.*` | `{ personA: Birth, personB: Birth }` |
114
117
  | **Rashi** | `horoscope.*` | `{ rashi: "aries", date?, lang? }` |
115
118
  | **Date range** | `eclipses.*`, `western.ingresses` | `{ startDate, endDate }` |
116
- | **Muhurta (search)** | `muhurta.bestTime` | `{ lat, lon, tz, startDate, endDate }` |
119
+ | **Muhurta (search)** | `muhurta.bestTime` | `{ lat, lon, tz, startDate, endDate, purpose?, topN?, birthDate? }` |
117
120
  | **Natal + window** | `transit.sadeSatiWindows`, `transit.windows` (`birth` optional) | `{ birth: Birth, from?, tz? }` |
118
121
  | **Natal + transit** | `transit.tarabala`, `transit.vedha`, `transit.smallPanoti`, `ashtakavarga.kaksha`, `ashtakavarga.transitScore`, `western.transits.toNatal`, `narrative.transitPhal`, `narrative.dashaPhal`, `narrative.transitDouble`, `narrative.sadeSatiStatus` / `Phase` / `History` | `{ birth: Birth, date, time, tz }` |
119
122
 
@@ -508,7 +511,7 @@ Bring your own renderer, or run where a browser is not available — the HTML la
508
511
  has no dependencies:
509
512
 
510
513
  ```ts
511
- import { renderMatchMakingHtml } from "lifeastroapi/pdf";
514
+ import { renderMatchMakingHtml } from "lifeastroapi/pdf-html"; // or "lifeastroapi/pdf"
512
515
  const html = renderMatchMakingHtml(matchReport, { primaryColor: "#b91c1c" });
513
516
  // → your own Puppeteer/Playwright, Gotenberg, a print service, or the browser's Print dialog
514
517
  ```
@@ -518,6 +521,9 @@ footer), so any Chromium-based converter gives the same layout. The Brihad table
518
521
  contents, running header and bookmarks are added by `kundliBrihadPdf` and are not
519
522
  part of the plain HTML.
520
523
 
524
+ `lifeastroapi/pdf-html` has only the HTML renderers and branding helpers: no Puppeteer
525
+ and no Node code, so it bundles for browsers, edge runtimes and React Native.
526
+
521
527
  ### `htmlToPdf` options
522
528
 
523
529
  All `*Pdf` functions accept these alongside `branding`:
@@ -554,6 +560,79 @@ restricted network egress to avoid requests to internal hosts (SSRF).
554
560
  | Timeouts on Brihad Kundli | It is a very large document rendered twice. Raise `timeoutMs` and render in a background job. |
555
561
  | Cover says "Subject" | Pass `name` (and `place`) when requesting the report. |
556
562
 
563
+ ## React Native and Expo
564
+
565
+ The SDK runs in React Native as it does in Node: the client uses the platform `fetch`,
566
+ and `lifeastroapi/pdf-html` builds the report HTML with no Puppeteer and no Node code.
567
+ The device's own print engine turns that HTML into a PDF, so the report is rendered on
568
+ the phone.
569
+
570
+ ```bash
571
+ npm install lifeastroapi
572
+ npx expo install expo-print expo-sharing
573
+ ```
574
+
575
+ ```tsx
576
+ import * as Print from "expo-print";
577
+ import * as Sharing from "expo-sharing";
578
+ import { renderKundliLiteHtml, A4_PRINT_OPTIONS } from "lifeastroapi/pdf-html";
579
+
580
+ // 1. Report JSON from YOUR backend (see below); it is the JSON of client.reports.kundliLite().
581
+ const report = await (await fetch("https://api.your-app.example/kundli?lang=bn")).json();
582
+
583
+ // 2. Branded HTML, built on the device
584
+ const html = renderKundliLiteHtml(report, {
585
+ companyName: "Acme Astro",
586
+ primaryColor: "#6b21a8",
587
+ });
588
+
589
+ // 3. PDF, printed on the device
590
+ const { uri } = await Print.printToFileAsync({ html, ...A4_PRINT_OPTIONS });
591
+ await Sharing.shareAsync(uri, { mimeType: "application/pdf" });
592
+ ```
593
+
594
+ **Keep the API key on your server.** Anything shipped inside an app can be read out of
595
+ it. Call LifeAstroAPI from your backend with this SDK and send the JSON to the app:
596
+
597
+ ```ts
598
+ // your backend (Node)
599
+ import { LifeAstro } from "lifeastroapi";
600
+ const client = new LifeAstro(); // reads LIFEASTRO_API_KEY
601
+
602
+ app.get("/kundli", async (req, res) => {
603
+ res.json(await client.reports.kundliLite({ ...birthOf(req.user), lang: req.query.lang }));
604
+ });
605
+ ```
606
+
607
+ What to know:
608
+
609
+ - **Entry point.** Import the renderers from `lifeastroapi/pdf-html` in an app.
610
+ `lifeastroapi/pdf` also carries the Puppeteer `*Pdf` functions, which cannot run on a
611
+ phone. Metro finds the subpath through the package `exports` field, which is on by
612
+ default from React Native 0.79 (Expo SDK 53).
613
+ - **Page size and margins.** The templates set A4 and the page margins with a CSS `@page`
614
+ rule. Chromium follows it; the iOS print engine does not, so pass `A4_PRINT_OPTIONS`
615
+ (`width`, `height` and `margins` in points) to `printToFileAsync`.
616
+ - **All ten reports** have a renderer: `renderKundliLiteHtml`, `renderKundliDetailedHtml`,
617
+ `renderKundliBrihadHtml`, `renderMatchMakingHtml`, `renderMangalDoshaHtml`,
618
+ `renderDashaAnalysisHtml`, `renderNumerologyHtml`, `renderSadeSatiHtml`,
619
+ `renderVarshaphalHtml` and `renderHoroscopeHtml`, in every language the PDF reports
620
+ support.
621
+ - **Differences from the Puppeteer PDF.** The footer line and the Brihad Kundli table of
622
+ contents, running header and bookmarks are drawn by Chromium features, so they are not
623
+ in a device-printed PDF. If you need them, make that PDF on your server with
624
+ `lifeastroapi/pdf` and download it in the app.
625
+ - **Fonts.** iOS and Android include fonts for the Indian scripts. The templates also name
626
+ the Noto fonts, which the device uses when they are installed.
627
+ - **Timeouts and errors** are the same classes as in Node (`AuthenticationError`,
628
+ `RateLimitError`, `LifeAstroConnectionError` with `code: "timeout"` …).
629
+
630
+ Tested in an Expo SDK 58 app (React Native 0.88) on the iOS simulator: client calls with
631
+ `lang`, typed errors, and Kundli (Bengali), detailed Kundli (Hindi) and match-making
632
+ (Tamil) PDFs. An Android build bundles; it has not been run on an Android device.
633
+ Without Expo, any library that prints HTML to PDF with the system WebView takes the same
634
+ HTML.
635
+
557
636
  ## Contributing
558
637
 
559
638
  The typed surface is generated from a manifest. After editing