@tempo-kit/plugin-geo 0.0.0-stage → 3.0.0-rc.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,125 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `@tempo-kit/plugin-geo` project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [3.0.0] - 2026-11-27
9
+
10
+ ### Breaking Changes
11
+ - Migrated package namespace from `@magmacomputing/tempo-plugin-geo` to `@tempo-kit/plugin-geo`.
12
+ - Updated `peerDependencies` to `tempo-kit@^5.0.0`.
13
+
14
+ ## [3.0.0] - 2026-11-27
15
+
16
+ ### Breaking Changes
17
+ - Migrated package namespace from `@magmacomputing/tempo-plugin-geo` to `@tempo-kit/plugin-geo`.
18
+ - Updated `peerDependencies` to `tempo-kit@^5.0.0`.
19
+
20
+ ## [2.0.0] - 2026-10-23
21
+
22
+ ### Breaking Changes
23
+ - **API Surface Symmetry (`Tempo.geo.set`)**:
24
+ - Renamed the static namespace method `Tempo.geo.stash()` to `Tempo.geo.set()` for clean semantic symmetry with `Tempo.geo.get()` and `Tempo.geo.clear()`.
25
+ - Updated namespace TypeScript interface definition and documentation examples.
26
+
27
+ ## [1.4.2] - 2026-10-03
28
+
29
+ ### Changed
30
+ - **Internal Cleanups & Compatibility**:
31
+ - Replaced prototype `Object.hasOwn` with the unified `hasOwn` helper from `@magmacomputing/tempo/plugin/sdk`.
32
+ - Streamlined timezone string validation with `isText`.
33
+ - Added comprehensive documentation for use cases, patterns, and cultural synchronization.
34
+
35
+ ## [1.4.1] - 2026-09-28
36
+
37
+ ### Fixed
38
+ - **Polymorphic Options in `Tempo.geo.resolve`**:
39
+ - Support single-argument options usage (e.g. `Tempo.geo.resolve({ reverse: true })`) when target coordinates are omitted.
40
+ - **Deterministic Return Schema**:
41
+ - Normalized cold IP geolocation responses through `assembleGeoConfig` to eliminate leaking provider transport metadata (`query`, `status`) and guarantee a consistent `GeoConfig` return shape across cold, cached, and reverse lookups.
42
+ - **Auto-Reverse on Stashed / Looked-up Coordinates**:
43
+ - Automatically triggers reverse geocoding when `{ reverse: true }` is specified on coordinates that lack locality (`city` / `country`) metadata.
44
+
45
+ ## [1.4.0] - 2026-09-27
46
+
47
+ ### Added
48
+ - **Reverse Geocoding & Spatial Deduplication (`Tempo.geo.reverse`)**:
49
+ - Reverse geocodes coordinates to address/locality metadata with source-partitioned 2-decimal spatial `BoundedCache` (~1.1 km resolution, 24h TTL) and `{ refresh: true }` cache bypass.
50
+ - Opt-in reverse geocoding during `.geoLocate()` via `t.geoLocate({ reverse: true })` when coordinates exist without locality metadata.
51
+ - **Dependency on `@magmacomputing/tempo-fns`**:
52
+ - Imported pure `resolveCulturalLocale` and `type LocaleSyncMode` from `@magmacomputing/tempo-fns`.
53
+
54
+ ### Changed (Clean Break)
55
+ - **Extracted GIS Math & Navigation to `@magmacomputing/tempo-plugin-spatial`**:
56
+ - Removed GIS calculations (`haversineDistance`, `calculateBearing`, `calculateMidpoint`, `calculateVelocity`, `isImpossibleTravel`, `isWithin`, `inBoundingBox`, `solarOffset`) and instance methods (`geoDistance`, `geoSolarOffset`) from `tempo-plugin-geo` to keep the core lean and focused solely on coordinate resolution, hardware/IP detection, and geocoding.
57
+ - GIS navigation and spatial geometry are now available via the dedicated `@magmacomputing/tempo-plugin-spatial` plugin under the immutable `Tempo.spatial` namespace.
58
+
59
+ ## [1.3.0] - 2026-09-25
60
+
61
+ ### Added
62
+ - **Pluggable Geocoding Provider Gateway (`GeoProvider`)**:
63
+ - `GeoProvider` interface: Standardized adapter interface for custom geocoding and geolocation providers (`lookup`, `reverseGeocode`, `forwardGeocode`).
64
+ - `Tempo.geo.setProvider(provider)` & `Tempo.geo.getProvider()`: Global registration of custom geolocation providers on the static namespace.
65
+ - `Tempo.geo.reverse(coords, options?)`: Reverse geocodes coordinates to address/locality metadata.
66
+ - `Tempo.geo.forward(query, options?)`: Forward geocodes place query strings to resolved coordinates.
67
+ - Call-site provider override: `t.geoLocate({ provider })` to dynamically override provider per operation.
68
+ - Automatic 24-hour BoundedCache integration and graceful failover to default environment lookup.
69
+ - **Navigation & Transit Analytics (`Tempo.geo` Static Namespace)**:
70
+ - `Tempo.geo.velocity(from, to, options?)`: Calculates travel speed between two timestamped geographic instances or coordinate objects in `km/h`, `mph`, or `m/s`.
71
+ - `Tempo.geo.isImpossibleTravel(from, to, options?)`: Evaluates physical travel feasibility against commercial aviation thresholds (default: 900 km/h) for cybersecurity anomaly detection and impossible travel prevention.
72
+ - `Tempo.geo.bearing(from, to, options?)`: Computes Great-Circle forward azimuth compass bearing in degrees (0° to 360°).
73
+ - `Tempo.geo.midpoint(from, to)`: Computes Great-Circle geographic midpoint with automatic hemisphere inference (`{ latitude, longitude, sphere }`).
74
+ - **Spatial Boundaries & Geofencing (`Tempo.geo` Static Namespace)**:
75
+ - `Tempo.geo.isWithin(from, to, maxDistance, unit?)`: Radial proximity query evaluating whether coordinates are within a specified distance (`'km'`, `'miles'`, `'m'`).
76
+ - `Tempo.geo.inBoundingBox(coords, bbox)`: Spatial containment test evaluating if coordinates fall within rectangular bounding box, including antimeridian crossing (180° longitude wrap).
77
+ - **Automated Cultural Sync (`t.geoLocate({ setLocale })`)**:
78
+ - `LocaleSyncMode`: Synchronizes BCP 47 locale during `.geoLocate()` with default regional adaptation (`true` / `'regional'`), preserving source language while adapting the cultural calendar (e.g. `en-US` ➜ `en-SA` for Saturday-start weeks and Friday/Saturday weekends).
79
+ - Supports `'native'` (e.g. `ar-SA`), custom BCP 47 tags (`'es-SA'`, `'fr-CH'`), and opt-out (`false` / `'none'`).
80
+ - **Exported Standalone Functional Utilities**:
81
+ - Direct named exports: `calculateBearing`, `calculateMidpoint`, `calculateVelocity`, `isImpossibleTravel`, `isWithin`, `inBoundingBox`, `resolveCulturalLocale`, and types `BearingOptions`, `VelocityOptions`, `ImpossibleTravelOptions`, `BoundingBox`, `LocaleSyncMode`, `TimeUnit`.
82
+
83
+ ## [1.2.0] - 2026-09-18
84
+
85
+ ### Added
86
+ - **`/install` Subpath Side-Effect Entry Point**:
87
+ - Added dedicated `@tempo-kit/plugin-geo/install` subpath for one-line side-effect installation (`import '@tempo-kit/plugin-geo/install'`).
88
+ - Automatically mounts `Tempo.geo` on `globalThis.Tempo` or imported `Tempo` while preserving 100% tree-shakeability for the main package entry point.
89
+
90
+ ## [1.1.0] - 2026-09-16
91
+
92
+ ### Added
93
+ - **Plugin Options Merging & Callable Plugin Support**:
94
+ - `GeoPlugin.install` now accepts resolved options passed by `Tempo.use(GeoPlugin, options)` or `Tempo.use(GeoPlugin(options))` or tuple syntax `[GeoPlugin, options]`.
95
+ - Merges class defaults (`installedClass.config?.pluginOptions?.geo`), plugin registration options, instance options, and call-site options prior to coordinate resolution and lookup.
96
+ - Ensures call-site options override configured defaults (such as `timeout` and `highAccuracy`) while preserving existing coordinate resolution behavior.
97
+
98
+ ## [1.0.0] - 2026-09-08
99
+
100
+ ### Changed (Breaking Changes)
101
+ - **Consolidated `Tempo.geo` Namespace**:
102
+ - Removed loose static methods mounted directly on the `Tempo` root class (`Tempo.geoLookup`, `Tempo.resolveGeoCoordinates`, `Tempo.serverGeoLocation`, `Tempo.geoLocation`) to prevent flat base class pollution.
103
+ - All static geolocation utilities are now organized under the dedicated, immutable **`Tempo.geo`** namespace (`Tempo.geo.lookup`, `Tempo.geo.resolve`, `Tempo.geo.server`, `Tempo.geo.browser`, `Tempo.geo.stash`, `Tempo.geo.clear`, `Tempo.geo.get`, and `Tempo.geo.current`).
104
+ - Standalone tree-shakeable functions (`geoLookup`, `resolveGeoCoordinates`, `serverGeoLocation`, etc.) remain available as direct named exports from the package for tree-shaking.
105
+ - **Storage Key Scoping**:
106
+ - Standardized ambient coordinate storage on `_magma_geo_`.
107
+
108
+ ### Added
109
+ - **24-Hour TTL Caching & Multi-Tenant Partitioning**:
110
+ - Added automatic 24-hour TTL caching for `Tempo.geo.lookup()` with `{ refresh: true }` cache bypass support.
111
+ - Added multi-tenant partitioning in `Tempo.geo.stash()`, `Tempo.geo.get()`, and `Tempo.geo.clear()`, scoping storage under `_magma_geo_:<tenant-id>`.
112
+ - Added `Tempo.geo.current` read-only getter to inspect active ambient coordinates snapshot.
113
+ - **Immutability Hardening**:
114
+ - The `Tempo.geo` namespace and attached utilities are recursively frozen via `deepFreeze()`.
115
+ - **Stable Community Release**:
116
+ - Official 1.0.0 release of `@tempo-kit/plugin-geo`.
117
+ - Configured npm Trusted Publisher automation for CI/CD publishing with Sigstore provenance.
118
+
119
+ ## [0.1.0] - 2026-09-07
120
+
121
+ ### Added
122
+ - **Initial Community Release (Bootstrap)**:
123
+ - Decoupled IP geolocation lookup and browser hardware location services from core `@magmacomputing/tempo`.
124
+ - Exported functional utilities: `geoLookup()`, `resolveGeoCoordinates()`, `serverGeoLocation()`, `serverGeoCoords()`, `serverMapHemisphere()`, `geoLocation()`, `coerceGeo()`, `getStashedGeo()`.
125
+ - Exported `GeoPlugin` installing `geoLocate()` and `geoLookup()` on Tempo instances alongside static helpers on `Tempo`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Magma Computing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,127 @@
1
- # Temporary Holding Version
1
+ ![Tempo Plugin](https://raw.githubusercontent.com/magmacomputing/magma/main/packages/tempo/public/plugin-logo.svg)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @tempo-kit/plugin-geo
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@tempo-kit/plugin-geo"><img src="https://img.shields.io/npm/v/@tempo-kit/plugin-geo?style=flat-square" alt="npm version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/tempo-kit"><img src="https://img.shields.io/npm/dependency-version/@tempo-kit/plugin-geo/peer/tempo-kit?style=flat-square" alt="npm peer dependency version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/@tempo-kit/plugin-geo"><img src="https://img.shields.io/npm/l/@tempo-kit/plugin-geo?style=flat-square" alt="License" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-blue?logo=typescript&style=flat-square" alt="TypeScript Ready" style="display: inline-block; margin: 0 4px;"></a> <a href="https://magmacomputing.github.io/magma/doc/9-plugins/geo.index.html"><img src="https://img.shields.io/badge/Docs-VitePress-brightgreen?logo=vitepress&style=flat-square" alt="Documentation" style="display: inline-block; margin: 0 4px;"></a>
7
+ </p>
8
+
9
+ A Community plugin for the [Tempo](https://github.com/magmacomputing/magma) ecosystem that provides IP geolocation lookup, browser hardware location services, forward & reverse geocoding gateway with pluggable providers, cultural locale synchronization, and 24-hour multi-tenant coordinate caching.
10
+
11
+ For geometric GIS math, Great-Circle navigation, and impossible travel anomaly detection, see [`@tempo-kit/plugin-spatial`](https://www.npmjs.com/package/@tempo-kit/plugin-spatial).
12
+
13
+ 👉 **[View the full documentation on our GitHub Pages](https://magmacomputing.github.io/magma/doc/9-plugins/geo.index.html)**
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @tempo-kit/plugin-geo
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Usage
26
+
27
+ ### 1. Fluent OOP with Namespaced `Tempo.geo`
28
+
29
+ Installing `GeoPlugin` mounts an immutable, locked-down **`Tempo.geo`** namespace onto the `Tempo` class:
30
+
31
+ ```typescript
32
+ import { Tempo } from 'tempo-kit';
33
+ import { GeoPlugin } from '@tempo-kit/plugin-geo';
34
+
35
+ Tempo.use(GeoPlugin);
36
+
37
+ // 1. Universal Geolocation Lookup (cached for 24h)
38
+ const lookupResult = await Tempo.geo.lookup();
39
+ console.log(lookupResult.lat, lookupResult.lng, lookupResult.city);
40
+
41
+ // 2. Reverse Geocoding (Coordinates -> Address / City / Country)
42
+ const address = await Tempo.geo.reverse({ lat: -33.8688, lng: 151.2093 });
43
+ console.log(address?.city, address?.country); // 'Sydney', 'AU'
44
+
45
+ // 3. Inspect Current Ambient / Global Coordinates
46
+ console.log(Tempo.geo.current); // { latitude: ..., longitude: ..., city: ... }
47
+
48
+ // 4. Force Fresh Network Lookup (bypassing 24h cache)
49
+ const fresh = await Tempo.geo.lookup({ refresh: true });
50
+
51
+ // 5. Enrich a Tempo Instance Asynchronously with Cultural Sync
52
+ const t = new Tempo('2026-06-21T12:00:00Z', {
53
+ geo: { lat: 30.0444, lng: 31.2357, country: 'EG' } // Cairo
54
+ });
55
+ const localTime = await t.geoLocate({ setLocale: 'native' });
56
+ console.log(localTime.locale); // 'ar-EG'
57
+ ```
58
+
59
+ > ⚡ **[Try this live in the interactive Tempo Sandbox ↗](https://magmacomputing.github.io/magma/repl/index.html?plugin=geo)**
60
+
61
+ ### 2. Functional Tree-Shakeable APIs
62
+
63
+ All underlying utilities can be imported as standalone tree-shakeable functions without augmenting `Tempo`:
64
+
65
+ ```typescript
66
+ import { Tempo } from 'tempo-kit';
67
+ import {
68
+ geoLookup,
69
+ reverseGeocode,
70
+ forwardGeocode,
71
+ resolveCulturalLocale,
72
+ resolveGeoCoordinates,
73
+ stashGeo,
74
+ clearStashedGeo,
75
+ getStashedGeo,
76
+ } from '@tempo-kit/plugin-geo';
77
+
78
+ // Standalone lookup & instance creation
79
+ const coords = await geoLookup();
80
+ const t = new Tempo('2026-06-21', { geo: coords });
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Which Method Should I Choose?
86
+
87
+ | Goal | Method to Use | Input | Output |
88
+ | :--- | :--- | :--- | :--- |
89
+ | **"Where is this machine / user right now?"** | `Tempo.geo.lookup()` | None / ambient options | `{ latitude, longitude, city, ... }` |
90
+ | **"Convert place name / address to coordinates"** | `Tempo.geo.forward("Paris")` | Address query string | `{ latitude, longitude, ... }` |
91
+ | **"Convert GPS coordinates to street / city / country"** | `Tempo.geo.reverse({ lat, lng })` | Coordinate object | `{ city, country, ... }` |
92
+ | **"Extract or safely normalize coordinates from any input"** | `Tempo.geo.resolve(input)` | Instance, config, or object | Canonical `{ latitude, longitude, ... }` |
93
+ | **"Localize a Tempo instance with timezone & cultural calendar"** | `await t.geoLocate()` | Existing `Tempo` instance | New enriched `Tempo` instance |
94
+
95
+ ---
96
+
97
+ ## The `Tempo.geo` API Surface
98
+
99
+ | Method / Property | Description |
100
+ | :--- | :--- |
101
+ | `Tempo.geo.lookup(opts?)` | Universal geolocation lookup (browser hardware GPS or server IP lookup) cached for 24h. Supports `{ refresh: true }`. |
102
+ | `Tempo.geo.forward(query, opts?)` | Forward geocodes query string to coordinates using the active provider. |
103
+ | `Tempo.geo.reverse(coords, opts?)` | Reverse geocodes coordinates to place/locality metadata using the active provider. |
104
+ | `Tempo.geo.setProvider(provider)` | Sets the active custom geocoding provider (e.g. OpenStreetMap, Mapbox, internal IP proxy). |
105
+ | `Tempo.geo.getProvider()` | Retrieves the active custom geocoding provider. |
106
+ | `Tempo.geo.resolve(input, opts?)` | Asynchronously resolves coordinates from an instance, configuration, or ambient storage cache. |
107
+ | `Tempo.geo.coerce(input)` | Pure function normalizing various coordinate formats (`lat/lng`, `latitude/longitude`, etc.) into a canonical `GeoConfig`. |
108
+ | `Tempo.geo.get(keyOrOpts?)` | Reads stored coordinates for the specified tenant/IP or ambient default. |
109
+ | `Tempo.geo.set(coords, ttl?, keyOrOpts?)` | Sets coordinates in storage with an optional custom TTL (default: 24h) and multi-tenant partitioning. |
110
+ | `Tempo.geo.clear(keyOrOpts?)` | Purges stored coordinates from storage. |
111
+ | `Tempo.geo.current` | **Read-only getter** returning the active global/ambient coordinates snapshot (`getStashedGeo() ?? Tempo.config.geo`). |
112
+ | `Tempo.geo.server(opts?)` | Low-level server-side IP geolocation handler. |
113
+ | `Tempo.geo.browser(opts?)` | Low-level browser Geolocation API handler. |
114
+
115
+ ---
116
+
117
+ ## ⚠️ Critical Operational Warnings
118
+
119
+ > [!CAUTION]
120
+ > **Server Environments (Node.js, Deno, Bun, Workers)**:
121
+ > In server environments without hardware GPS, calling `Tempo.geo.lookup()` falls back to server outbound public IP geolocation. When executing in multi-user request pipelines, do **not** use the default singleton ambient cache if requests come from multiple distinct users. Instead, pass explicit coordinate payloads (`new Tempo({ geo: userGeo })`) or use tenant keys with `stashGeo(coords, ttl, tenantKey)`.
122
+
123
+ ---
124
+
125
+ ## License
126
+
127
+ This is a **Community** plugin. It is completely free and open-source for personal and commercial use under the MIT license.