@tonk/google-maps-locations-worker
v1.0.1
Published
Retrieves user's saved Google Maps locations
Readme
Google Maps Locations Worker
A Tonk worker service that retrieves and syncs your saved Google Maps locations to your local-first Tonk environment.
Overview
This worker connects to your Google account, exports your saved locations from Google Maps, and stores them in your Tonk environment. It runs on a daily schedule to keep your locations up-to-date.
Prerequisites
- Google Cloud Platform account with OAuth 2.0 credentials
- Node.js 18 or higher
- Tonk CLI installed
Getting Started
Install the worker:
npm install -g @tonk/google-maps-locations-workerSet up credentials and authentication:
google-maps-locations-worker setup- This interactive setup will guide you through:
- Creating the required
credentials.jsonfile (you'll need to create OAuth 2.0 credentials in the Google Cloud Console) - Running the OAuth authentication flow to create a
token.jsonfile
- Creating the required
- The setup will open a browser window for Google authentication
- After authenticating, a
token.jsonfile will be created with refresh credentials - If you want to skip the authentication step, you can use the
--skip-authflag:google-maps-locations-worker setup --skip-auth
- This interactive setup will guide you through:
Create a
.envfile (optional):# Example .env file WORKER_PORT=5555 KEEPSYNC_DOC_PATH=google-maps-locationsStart the worker:
google-maps-locations-worker start- The worker will use the credentials and token created during setup
- If you skipped authentication during setup, this will open a browser window for Google authentication
Register the worker with Tonk (if using Tonk):
tonk worker register
Development Setup
If you're developing or modifying the worker:
Clone the repository and install dependencies:
git clone <repository-url> cd google-maps-locations-worker pnpm installSet up credentials:
pnpm devBuild for production:
pnpm build
Deployment
After the initial authentication step, you can deploy the worker to run automatically:
- Make sure both
credentials.jsonandtoken.jsonfiles are included in your deployment - The worker will run without user intervention using the refresh token
- Locations are exported daily at 3:00 AM by default
API Endpoints
GET /health- Health check endpointPOST /export-locations- Trigger a manual export of locations
Worker Configuration
The worker is configured using the worker.config.js file. You can modify this file to change the worker's behavior.
Project Structure
google-maps-locations-worker/
├── src/
│ ├── index.ts # Main entry point
│ ├── cli.ts # CLI for controlling the worker
│ ├── exportLocations.ts # Google Maps location export logic
│ └── utils.ts # Utility functions
├── credentials.json # Google OAuth credentials (you must create this)
├── token.json # Authentication token (generated after first run)
├── worker.config.js # Worker configuration
└── package.json # Project configurationHow It Works
- The worker authenticates with Google using OAuth 2.0
- It uses the Data Portability API to export your saved Google Maps locations
- The exported data is downloaded as ZIP files containing CSV files
- The CSV files are processed and converted to JSON
- The locations are stored in your Tonk environment at the specified
KEEPSYNC_DOC_PATH
License
MIT © Tonk Labs
