@chaosity/location-client-react 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +158 -0
  2. package/package.json +5 -6
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @chaosity/location-client-react
2
+
3
+ React bindings for [@chaosity/location-client](https://www.npmjs.com/package/@chaosity/location-client) - AWS Location Service compatible client.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @chaosity/location-client-react @chaosity/location-client
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```tsx
14
+ import { LocationClientProvider, useLocationClient } from '@chaosity/location-client-react'
15
+ import { places } from '@chaosity/location-client'
16
+
17
+ // 1. Wrap your app with the provider
18
+ function App() {
19
+ return (
20
+ <LocationClientProvider apiUrl="https://api.example.com" token="your-token">
21
+ <MapComponent />
22
+ </LocationClientProvider>
23
+ )
24
+ }
25
+
26
+ // 2. Use the client in any component
27
+ function MapComponent() {
28
+ const client = useLocationClient()
29
+
30
+ const searchPlaces = async (query: string) => {
31
+ const command = new places.SuggestCommand({
32
+ QueryText: query,
33
+ MaxResults: 5
34
+ })
35
+ const response = await client.send(command)
36
+ return response.ResultItems
37
+ }
38
+
39
+ return <div>...</div>
40
+ }
41
+ ```
42
+
43
+ ## API Reference
44
+
45
+ ### LocationClientProvider
46
+
47
+ Provides the location client to all child components.
48
+
49
+ ```tsx
50
+ <LocationClientProvider
51
+ apiUrl="https://api.example.com"
52
+ token="your-bearer-token"
53
+ >
54
+ {children}
55
+ </LocationClientProvider>
56
+ ```
57
+
58
+ **Props:**
59
+ - `apiUrl` (string, required) - API endpoint URL
60
+ - `token` (string, required) - Bearer token for authentication
61
+ - `children` (ReactNode, required) - Child components
62
+
63
+ ### useLocationClient
64
+
65
+ Hook to access the location client in any component.
66
+
67
+ ```tsx
68
+ const client = useLocationClient()
69
+ ```
70
+
71
+ **Returns:** `GeoPlacesClient` instance
72
+
73
+ **Throws:** Error if used outside `LocationClientProvider`
74
+
75
+ ## Usage with Server Actions (Next.js)
76
+
77
+ ```tsx
78
+ // app/actions/location.ts (Server-side)
79
+ 'use server'
80
+
81
+ export async function getLocationConfig() {
82
+ const response = await fetch('https://api.example.com/auth/token', {
83
+ method: 'POST',
84
+ headers: { 'Content-Type': 'application/json' },
85
+ body: JSON.stringify({
86
+ grant_type: 'client_credentials',
87
+ client_id: process.env.LOCATION_CLIENT_ID!,
88
+ client_secret: process.env.LOCATION_CLIENT_SECRET!
89
+ })
90
+ })
91
+
92
+ const data = await response.json()
93
+ return {
94
+ apiUrl: 'https://api.example.com',
95
+ token: data.access_token
96
+ }
97
+ }
98
+
99
+ // app/page.tsx (Client-side)
100
+ 'use client'
101
+ import { LocationClientProvider } from '@chaosity/location-client-react'
102
+ import { getLocationConfig } from './actions/location'
103
+
104
+ export default async function Page() {
105
+ const config = await getLocationConfig()
106
+
107
+ return (
108
+ <LocationClientProvider {...config}>
109
+ <MapComponent />
110
+ </LocationClientProvider>
111
+ )
112
+ }
113
+ ```
114
+
115
+ ## Available Commands
116
+
117
+ All AWS Location Service commands are available through the client:
118
+
119
+ ```tsx
120
+ import { places } from '@chaosity/location-client'
121
+
122
+ // Autocomplete
123
+ new places.SuggestCommand({ QueryText: 'Van', MaxResults: 5 })
124
+
125
+ // Geocoding
126
+ new places.GeocodeCommand({ QueryText: 'Vancouver, BC' })
127
+
128
+ // Reverse Geocoding
129
+ new places.ReverseGeocodeCommand({ QueryPosition: [-123.1207, 49.2827] })
130
+
131
+ // Place Details
132
+ new places.GetPlaceCommand({ PlaceId: 'place-id' })
133
+
134
+ // Search Nearby
135
+ new places.SearchNearbyCommand({ QueryPosition: [-123.1207, 49.2827] })
136
+
137
+ // Text Search
138
+ new places.SearchTextCommand({ QueryText: 'coffee shops' })
139
+ ```
140
+
141
+ See [@chaosity/location-client](https://www.npmjs.com/package/@chaosity/location-client) for complete documentation.
142
+
143
+ ## TypeScript Support
144
+
145
+ Full TypeScript support with types from AWS SDK:
146
+
147
+ ```tsx
148
+ import { places } from '@chaosity/location-client'
149
+ import type { SuggestCommandOutput } from '@aws-sdk/client-geo-places'
150
+
151
+ const response: SuggestCommandOutput = await client.send(
152
+ new places.SuggestCommand({ QueryText: 'Vancouver' })
153
+ )
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaosity/location-client-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "React bindings for Chaosity Location Service client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,15 +20,14 @@
20
20
  "license": "MIT",
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/chaosity-io/location-service-workspace.git",
24
- "directory": "location-service-client-react"
23
+ "url": "https://github.com/chaosity-io/location-service-client-react.git"
25
24
  },
26
- "homepage": "https://github.com/chaosity-io/location-service-workspace/tree/main/location-service-client-react",
25
+ "homepage": "https://github.com/chaosity-io/location-service-client-react",
27
26
  "bugs": {
28
- "url": "https://github.com/chaosity-io/location-service-workspace/issues"
27
+ "url": "https://github.com/chaosity-io/location-service-client-react/issues"
29
28
  },
30
29
  "dependencies": {
31
- "@chaosity/location-client": "^0.1.0"
30
+ "@chaosity/location-client": "^0.1.2"
32
31
  },
33
32
  "peerDependencies": {
34
33
  "react": "^18.0.0 || ^19.0.0"