@volter/twin-googlemaps 0.1.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/LICENSE +202 -0
- package/README.md +96 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +23 -0
- package/dist/src/googlemaps-auth.d.ts +31 -0
- package/dist/src/googlemaps-auth.js +37 -0
- package/dist/src/googlemaps-budget.d.ts +61 -0
- package/dist/src/googlemaps-budget.js +142 -0
- package/dist/src/googlemaps-capabilities.d.ts +3 -0
- package/dist/src/googlemaps-capabilities.js +648 -0
- package/dist/src/googlemaps-conformance.d.ts +8 -0
- package/dist/src/googlemaps-conformance.js +18 -0
- package/dist/src/googlemaps-connector.d.ts +94 -0
- package/dist/src/googlemaps-connector.js +243 -0
- package/dist/src/googlemaps-data.d.ts +87 -0
- package/dist/src/googlemaps-data.js +370 -0
- package/dist/src/googlemaps-perform-harness.d.ts +5 -0
- package/dist/src/googlemaps-perform-harness.js +17 -0
- package/dist/src/googlemaps-server.d.ts +14 -0
- package/dist/src/googlemaps-server.js +25 -0
- package/dist/src/googlemaps-twin.d.ts +2 -0
- package/dist/src/googlemaps-twin.js +1116 -0
- package/dist/src/googlemaps-types.d.ts +45 -0
- package/dist/src/googlemaps-types.js +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +65 -0
- package/package.json +52 -0
- package/src/cli.ts +22 -0
- package/src/googlemaps-auth.ts +52 -0
- package/src/googlemaps-budget.ts +168 -0
- package/src/googlemaps-capabilities.ts +766 -0
- package/src/googlemaps-conformance.ts +24 -0
- package/src/googlemaps-connector.ts +250 -0
- package/src/googlemaps-data.ts +399 -0
- package/src/googlemaps-perform-harness.ts +17 -0
- package/src/googlemaps-server.ts +33 -0
- package/src/googlemaps-twin.ts +1110 -0
- package/src/googlemaps-types.ts +47 -0
- package/src/index.ts +124 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @volter/twin-googlemaps
|
|
2
|
+
|
|
3
|
+
A local **Google Maps Platform twin** — offline, deterministic replicas of the
|
|
4
|
+
Maps web-service APIs (`maps.googleapis.com`, `places.googleapis.com`,
|
|
5
|
+
`roads.googleapis.com`, `addressvalidation.googleapis.com`) in vendor-faithful
|
|
6
|
+
response shapes, with the real `status` semantics and the API-key gate. The
|
|
7
|
+
unmodified `@googlemaps/google-maps-services-js` client points at it and gets
|
|
8
|
+
Maps-correct responses.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
world-googlemaps serve [--port N] [--root DIR] [--read-only]
|
|
12
|
+
world-googlemaps conformance [--root DIR]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Coverage
|
|
16
|
+
|
|
17
|
+
The capability manifest (`src/googlemaps-capabilities.ts`) is an honest **partial**
|
|
18
|
+
denominator across the Maps Platform web services. Most of the surface is
|
|
19
|
+
enumerated as the denominator; a core slice is `done` (each with a failable,
|
|
20
|
+
deterministic verify asserting response *values* plus a negative `status` path);
|
|
21
|
+
the long tail (parameters/options like waypoints, travel modes, pagination,
|
|
22
|
+
field masks, Place Photos, the Routes API) is honest `todo`.
|
|
23
|
+
|
|
24
|
+
**Deterministic canned data, NOT real geodata.** A local twin cannot reproduce
|
|
25
|
+
Google's geospatial index, road graph, live traffic, or imagery. It returns
|
|
26
|
+
faithful response *shapes* with stable, deterministic values: a given query
|
|
27
|
+
always maps to the same canned result. Known place names (Los Angeles, New York,
|
|
28
|
+
Mountain View, London, Tokyo) resolve to a small canned dataset; any other
|
|
29
|
+
well-formed query is synthesized deterministically from its hash so the twin
|
|
30
|
+
never falsely 404s a valid request.
|
|
31
|
+
|
|
32
|
+
**Modeled (`done`):**
|
|
33
|
+
|
|
34
|
+
- **Auth gate.** Legacy web services gate on the `key=` query parameter →
|
|
35
|
+
missing/invalid key returns the API's own `status:"REQUEST_DENIED"` envelope
|
|
36
|
+
(HTTP 200); sentinel keys exercise `OVER_QUERY_LIMIT` / `OVER_DAILY_LIMIT`. The
|
|
37
|
+
v1 / "New" APIs gate on the `X-Goog-Api-Key` header → missing key returns a 403
|
|
38
|
+
`google.rpc.Status` `PERMISSION_DENIED`.
|
|
39
|
+
- **Geocoding.** `geocode/json` — forward + reverse, by `address`, `components`,
|
|
40
|
+
or `place_id`; the full real result shape (`formatted_address`,
|
|
41
|
+
`address_components` with `long_name`/`short_name`/`types`, `geometry` with
|
|
42
|
+
`location`, `location_type`, `viewport`, `place_id`, `types`); `OK`,
|
|
43
|
+
`ZERO_RESULTS`, `INVALID_REQUEST`; connector-seeded overrides.
|
|
44
|
+
- **Distance Matrix.** `distancematrix/json` — M×N matrix of `OK`/`NOT_FOUND`
|
|
45
|
+
elements with `duration`/`distance` (`value` + human `text`), metric/imperial
|
|
46
|
+
units, `origin_addresses`/`destination_addresses`. (Matches the QA-stack
|
|
47
|
+
contract exactly.)
|
|
48
|
+
- **Directions.** `directions/json` — `routes[]` with `summary`, `legs[]`
|
|
49
|
+
(`distance`/`duration`/`start_address`/`end_address`/`start_location`/
|
|
50
|
+
`end_location`/`steps[]`), `overview_polyline` (real Encoded Polyline),
|
|
51
|
+
`bounds`, `copyrights`, `warnings`, `geocoded_waypoints`; `ZERO_RESULTS` /
|
|
52
|
+
`INVALID_REQUEST`.
|
|
53
|
+
- **Places (legacy).** Find Place from Text, Text Search, Nearby Search (radius
|
|
54
|
+
vs `rankby=distance`), Place Details, Autocomplete (with
|
|
55
|
+
`structured_formatting`), Query Autocomplete — with `OK`/`ZERO_RESULTS`/
|
|
56
|
+
`NOT_FOUND`/`INVALID_REQUEST`.
|
|
57
|
+
- **Places API (New) — v1.** `places:searchText`, `places:searchNearby`,
|
|
58
|
+
`places:autocomplete`, and `GET /v1/places/{id}` with the v1 shapes
|
|
59
|
+
(`displayName.text`, `location.latitude/longitude`, `formattedAddress`,
|
|
60
|
+
`id`/`name`) and `google.rpc.Status` errors.
|
|
61
|
+
- **Roads.** `snapToRoads`, `nearestRoads` (`snappedPoints[]` with
|
|
62
|
+
`location`/`placeId`/`originalIndex`), `speedLimits`.
|
|
63
|
+
- **Time Zone / Elevation / Geolocation.** `timezone/json`
|
|
64
|
+
(`timeZoneId`/`rawOffset`/`dstOffset`/`timeZoneName`), `elevation/json`
|
|
65
|
+
(locations + path `samples`, real haversine-independent deterministic
|
|
66
|
+
elevations), `geolocation/json` (`location` + `accuracy`).
|
|
67
|
+
- **Address Validation — v1.** `:validateAddress` with `verdict`, `geocode`,
|
|
68
|
+
`responseId`.
|
|
69
|
+
- **Static Maps / Street View Static.** Validate parameters and return image
|
|
70
|
+
*metadata* (content type, size) + Street View `metadata` (`pano_id`, date,
|
|
71
|
+
copyright); serving the image bytes themselves is a filed `todo`.
|
|
72
|
+
- **Audit.** A local audit log of requests (`GET /twin/audit`) — read-only
|
|
73
|
+
requests are not logged.
|
|
74
|
+
- **Connector.** Injected-client pulls for geocode overrides
|
|
75
|
+
(`pullGoogleMapsGeocodes`) and place snapshots (`pullGoogleMapsPlaces`),
|
|
76
|
+
idempotent. The kernel adapter `performGoogleMapsAction` handles supported entries;
|
|
77
|
+
it does not turn synthetic geocode seeds into writes to the real Maps service.
|
|
78
|
+
|
|
79
|
+
**Not yet modeled (honest `todo`):** Directions/Distance Matrix travel modes,
|
|
80
|
+
waypoints + optimization, alternatives, departure-time traffic, avoid filters,
|
|
81
|
+
transit details; Place Photos (binary), search pagination (`next_page_token` /
|
|
82
|
+
`pageToken`), opening hours, reviews, session tokens, field masks; Roads
|
|
83
|
+
`interpolate`; Time Zone DST from timestamp; Address Validation USPS/CASS +
|
|
84
|
+
per-component confirmation; Static Maps styling; the **Routes API (New)**
|
|
85
|
+
(`computeRoutes` / `computeRouteMatrix`); geocode region/components/language
|
|
86
|
+
biasing and Plus Codes; and the image bytes — deterministic placeholder bytes at the Static Maps
|
|
87
|
+
URL, for a Street View pano, and at the Place Photos URL (all three return only metadata today).
|
|
88
|
+
|
|
89
|
+
## Architecture
|
|
90
|
+
|
|
91
|
+
State lives in the `@volter/world-core` event/action log (geocode overrides + the
|
|
92
|
+
audit log); there is no ad-hoc store. The serve path makes no real network
|
|
93
|
+
calls; connector functions accept injected executors for real Maps I/O and are
|
|
94
|
+
not used by the local handler. This is an **API-first** vendor with no
|
|
95
|
+
operator-facing dashboard, so the pack ships **no UI mirror** — coverage is API +
|
|
96
|
+
connector.
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { keepProcessAlive } from '@volter/world-core/lifecycle';
|
|
3
|
+
import { hasFlag, optionValue } from '@volter/world-core/args';
|
|
4
|
+
import { createGoogleMapsTwinServer } from "./googlemaps-server.js";
|
|
5
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
6
|
+
const port = Number(optionValue(rest, '--port', '0')) || undefined;
|
|
7
|
+
const root = optionValue(rest, '--root') || undefined;
|
|
8
|
+
const readOnly = hasFlag(rest, '--read-only');
|
|
9
|
+
if (cmd === 'serve') {
|
|
10
|
+
const server = await createGoogleMapsTwinServer({ readOnly, ...(root ? { root } : {}), ...(port ? { port } : {}) });
|
|
11
|
+
process.stdout.write(`googlemaps twin${readOnly ? ' [read-only]' : ''} at http://127.0.0.1:${server.port}\n`);
|
|
12
|
+
await keepProcessAlive();
|
|
13
|
+
}
|
|
14
|
+
else if (cmd === 'conformance') {
|
|
15
|
+
const { checkGoogleMapsConformance } = await import("./googlemaps-conformance.js");
|
|
16
|
+
const report = await checkGoogleMapsConformance({ ...(root ? { root } : {}) });
|
|
17
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
18
|
+
if (!report.ok)
|
|
19
|
+
process.exitCode = 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
process.stdout.write('Usage: world-googlemaps serve|conformance [--port N] [--root DIR] [--read-only]\n');
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GoogleMapsResponse } from './googlemaps-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Google Maps Platform web services authenticate with an API key, passed either
|
|
4
|
+
* as the `key=` query parameter (legacy web-service APIs: Geocoding, Directions,
|
|
5
|
+
* Distance Matrix, Roads, Time Zone, Elevation, Geolocation, Static Maps, Street
|
|
6
|
+
* View) or as the `X-Goog-Api-Key` header (Places API New, Address Validation).
|
|
7
|
+
*
|
|
8
|
+
* Missing/invalid keys yield REQUEST_DENIED in the API's own status envelope
|
|
9
|
+
* (HTTP 200 with `status:"REQUEST_DENIED"` for legacy web services; a 403
|
|
10
|
+
* google.rpc.Status for the New/v1 APIs). A sentinel key lets verifies exercise
|
|
11
|
+
* OVER_QUERY_LIMIT / OVER_DAILY_LIMIT.
|
|
12
|
+
*/
|
|
13
|
+
export type MapsAuthResult = {
|
|
14
|
+
ok: true;
|
|
15
|
+
key: string;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
status: 'REQUEST_DENIED' | 'OVER_QUERY_LIMIT' | 'OVER_DAILY_LIMIT';
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
export type _AuthResponse = GoogleMapsResponse;
|
|
22
|
+
export declare function header(headers: Record<string, string> | undefined, name: string): string | undefined;
|
|
23
|
+
/** Extract the API key from `key=` query param or the `X-Goog-Api-Key` header. */
|
|
24
|
+
export declare function extractKey(url: URL, headers: Record<string, string> | undefined): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Validate the API key gate. When `headers` is entirely undefined (the in-process
|
|
27
|
+
* handler default used by most internal callers/tests) and no `key=` is present,
|
|
28
|
+
* auth is treated as pre-satisfied so offline flows keep working. When a key is
|
|
29
|
+
* supplied it is validated; the sentinel keys drive the quota error paths.
|
|
30
|
+
*/
|
|
31
|
+
export declare function authenticate(url: URL, headers: Record<string, string> | undefined): MapsAuthResult;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function header(headers, name) {
|
|
2
|
+
if (!headers)
|
|
3
|
+
return undefined;
|
|
4
|
+
const lower = name.toLowerCase();
|
|
5
|
+
for (const [k, v] of Object.entries(headers))
|
|
6
|
+
if (k.toLowerCase() === lower)
|
|
7
|
+
return v;
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Extract the API key from `key=` query param or the `X-Goog-Api-Key` header. */
|
|
11
|
+
export function extractKey(url, headers) {
|
|
12
|
+
return url.searchParams.get('key') ?? header(headers, 'x-goog-api-key') ?? undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validate the API key gate. When `headers` is entirely undefined (the in-process
|
|
16
|
+
* handler default used by most internal callers/tests) and no `key=` is present,
|
|
17
|
+
* auth is treated as pre-satisfied so offline flows keep working. When a key is
|
|
18
|
+
* supplied it is validated; the sentinel keys drive the quota error paths.
|
|
19
|
+
*/
|
|
20
|
+
export function authenticate(url, headers) {
|
|
21
|
+
const key = extractKey(url, headers);
|
|
22
|
+
if (key === undefined) {
|
|
23
|
+
// Implicit auth: only when callers don't model headers at all.
|
|
24
|
+
if (headers === undefined)
|
|
25
|
+
return { ok: true, key: 'twin-implicit' };
|
|
26
|
+
return { ok: false, status: 'REQUEST_DENIED', message: 'The provided API key is invalid or missing. Pass `key=` or the X-Goog-Api-Key header.' };
|
|
27
|
+
}
|
|
28
|
+
if (!key.trim())
|
|
29
|
+
return { ok: false, status: 'REQUEST_DENIED', message: 'The provided API key is empty.' };
|
|
30
|
+
if (key === 'over-query-limit')
|
|
31
|
+
return { ok: false, status: 'OVER_QUERY_LIMIT', message: 'You have exceeded your rate-limit for this API.' };
|
|
32
|
+
if (key === 'over-daily-limit')
|
|
33
|
+
return { ok: false, status: 'OVER_DAILY_LIMIT', message: 'You have exceeded your daily request quota for this API.' };
|
|
34
|
+
if (key === 'request-denied')
|
|
35
|
+
return { ok: false, status: 'REQUEST_DENIED', message: 'This API key is not authorized to use this service or API.' };
|
|
36
|
+
return { ok: true, key };
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { RateBudget, type RateBudgetDeclaration, type RateBudgetOptions, type RateBudgetReservation, type RateBudgetSnapshot } from '@volter/world-core';
|
|
2
|
+
/** Rolling window, in ms. Spend older than this is pruned. Matches Google's own per-MINUTE quotas. */
|
|
3
|
+
export declare const GOOGLEMAPS_BUDGET_WINDOW_MS = 60000;
|
|
4
|
+
/**
|
|
5
|
+
* Weighted units allowed inside one window. 300 geocodes/60s = 10% of the documented 3,000 QPM.
|
|
6
|
+
*/
|
|
7
|
+
export declare const GOOGLEMAPS_BUDGET_CEILING = 300;
|
|
8
|
+
/** Seconds. A `Retry-After` above this means the project is throttled hard — fail loudly. */
|
|
9
|
+
export declare const GOOGLEMAPS_BUDGET_MAX_RETRY_AFTER_S = 300;
|
|
10
|
+
/** Per-call cost, keyed by the `<METHOD> <path>` this connector is about to request. See the header. */
|
|
11
|
+
export declare const GOOGLEMAPS_CALL_WEIGHTS: {
|
|
12
|
+
/** `GET /maps/api/geocode/json` — documented 3,000 QPM, the most generous figure Google publishes. */
|
|
13
|
+
readonly geocode: 1;
|
|
14
|
+
/** `GET /maps/api/place/details/json` — unbounded response, NO published per-minute figure. */
|
|
15
|
+
readonly placeDetails: 4;
|
|
16
|
+
/** Anything this pack has not classified. Priced like a read, never free. */
|
|
17
|
+
readonly other: 2;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* THE PACK'S DECLARATION — pure data, the only Google-specific thing in the whole budget. Rules are
|
|
21
|
+
* ordered and first-match-wins, and they are keyed on `"<METHOD> <pathname>"` (not the bare path):
|
|
22
|
+
* Google's quotas are per API METHOD, and a write to a surface is not the same call as a read of it,
|
|
23
|
+
* so the method has to be part of what gets priced.
|
|
24
|
+
*
|
|
25
|
+
* Also exported as `pack.rateBudget` (see index.ts), so `registerPack` arms it too.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GOOGLEMAPS_RATE_BUDGET: RateBudgetDeclaration;
|
|
28
|
+
/** Split a connector path (which carries its own query string) into pathname + parsed query. */
|
|
29
|
+
export declare function splitGoogleMapsPath(path: string): {
|
|
30
|
+
pathname: string;
|
|
31
|
+
query: Record<string, string>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Price one call. Keyed off the request the connector is ABOUT to make, so an unclassified endpoint
|
|
35
|
+
* still costs `defaultWeight` — an unknown endpoint must never be free.
|
|
36
|
+
*/
|
|
37
|
+
export declare function googleMapsCallWeight(method: string, path: string): number;
|
|
38
|
+
/** Where Google Maps' ledger lives. API-key-keyed and cwd-independent by default (the quota is per
|
|
39
|
+
* project/key, so a cwd-scoped ledger would hand the same key a fresh allowance in every checkout,
|
|
40
|
+
* worktree and CI matrix leg); pass `root` to opt into world-scoped accounting instead. */
|
|
41
|
+
export declare function googleMapsBudgetPath(opts?: {
|
|
42
|
+
root?: string;
|
|
43
|
+
token?: string;
|
|
44
|
+
} | string): string;
|
|
45
|
+
/** Construction options for Google Maps' budget. The vendor is fixed; everything else may only TIGHTEN. */
|
|
46
|
+
export type GoogleMapsBudgetOptions = Omit<RateBudgetOptions, 'vendor'>;
|
|
47
|
+
/**
|
|
48
|
+
* Google Maps' budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
|
|
49
|
+
* not an alias, so `budget instanceof GoogleMapsBudget` in `liveGoogleMapsExecute` still means "a
|
|
50
|
+
* budget that accounts against GOOGLEMAPS' ledger under GOOGLEMAPS' ceiling": another vendor's
|
|
51
|
+
* `RateBudget` (with its own, possibly larger, ceiling) is NOT assignable there.
|
|
52
|
+
*/
|
|
53
|
+
export declare class GoogleMapsBudget extends RateBudget {
|
|
54
|
+
constructor(opts?: GoogleMapsBudgetOptions);
|
|
55
|
+
}
|
|
56
|
+
/** The typed refusal. One error class shared with every other vendor's budget; `err.vendor` says
|
|
57
|
+
* which one refused, and `err.kind` says why. */
|
|
58
|
+
export { RateBudgetError as GoogleMapsBudgetError } from '@volter/world-core';
|
|
59
|
+
export type { RateBudgetErrorKind as GoogleMapsBudgetErrorKind } from '@volter/world-core';
|
|
60
|
+
export type GoogleMapsBudgetReservation = RateBudgetReservation;
|
|
61
|
+
export type GoogleMapsBudgetSnapshot = RateBudgetSnapshot;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Google Maps Platform's CLIENT-SIDE RATE BUDGET — the pack's DECLARATION (the numbers) plus the
|
|
2
|
+
// thin typed bindings `liveGoogleMapsExecute` uses. The MECHANISM — the durable token-keyed ledger,
|
|
3
|
+
// the rolling window, reserve-under-lock, the `Retry-After`/429 cooldown, fail-CLOSED on a corrupt
|
|
4
|
+
// ledger — lives ONCE in the vendor-agnostic kernel (`@volter/world-core` → `rateBudget.ts`). Read that
|
|
5
|
+
// module's header for the full rationale AND for the honest list of what the guard does not
|
|
6
|
+
// guarantee (an injected clock or ledger path still defeats it — it guards carelessness, not malice).
|
|
7
|
+
//
|
|
8
|
+
// ── WHY THIS EXISTS: THE MISSING CHOKE POINT ─────────────────────────────────────────────────
|
|
9
|
+
// A ~4.5-day Figma token lockout (2026-07-25) came from a burst of raw vendor calls made OUTSIDE
|
|
10
|
+
// any guarded client. The lesson generalized: a pack with no single construction site for its live
|
|
11
|
+
// client is a pack that CANNOT be protected, because there is nowhere for a guard to sit.
|
|
12
|
+
//
|
|
13
|
+
// This connector took an INJECTED `GoogleMapsExecute` and nothing more. That is excellent for
|
|
14
|
+
// testing — every verify runs offline against a fake — but it meant the pack itself never built a
|
|
15
|
+
// network-calling execute, so a rate budget could only ever be something the CALLER opted into.
|
|
16
|
+
// `liveGoogleMapsExecute` (in `googlemaps-connector.ts`) is the choke point that fixes that: the ONE
|
|
17
|
+
// place in this pack that turns a credential into a function that really talks to
|
|
18
|
+
// maps.googleapis.com, with this budget charged BEFORE every request goes out. The injected-function
|
|
19
|
+
// contract is untouched — the factory is an ADDITION for production callers, not a replacement.
|
|
20
|
+
//
|
|
21
|
+
// ── HOW THE CEILING WAS CHOSEN ───────────────────────────────────────────────────────────────
|
|
22
|
+
// Google DOES publish a scalar for the endpoint this connector leans on hardest: the Geocoding API
|
|
23
|
+
// is documented as rate-limited to 3,000 QPM (queries per minute), counted as the sum of client-side
|
|
24
|
+
// and server-side queries (developers.google.com/maps/documentation/geocoding/usage-and-billing). The
|
|
25
|
+
// per-PROJECT scoping and the 'temporarily blocked' warning come from the Maps Platform FAQ's
|
|
26
|
+
// usage-limits section, not from the Geocoding page — two sources, cited separately (§9, 2026-07-26). Exceeding a product's QPM returns an error, and REPEATEDLY exceeding it can
|
|
27
|
+
// get access "temporarily blocked" — the lockout shape this guard exists to prevent.
|
|
28
|
+
//
|
|
29
|
+
// So: 300 weighted units per 60s, with a geocode priced at 1. That is 300 geocodes a minute — TEN
|
|
30
|
+
// PERCENT of the documented limit — while a careless loop is refused after 300 rather than running
|
|
31
|
+
// until Google blocks the project. The kernel independently caps any declaration at 1,000 units per
|
|
32
|
+
// window and 20 units/second, so modeling the vendor's 3,000 QPM literally was never on the table;
|
|
33
|
+
// 10% is a deliberate choice inside that cap, sized so the legitimate workload (a pull of a few
|
|
34
|
+
// dozen addresses) fits many times over in one window.
|
|
35
|
+
//
|
|
36
|
+
// ── HOW THE WEIGHTS WERE CHOSEN (and what is a judgement call) ────────────────────────────────
|
|
37
|
+
// Google counts REQUESTS, per API method per project, so weight 1 is the faithful price for a call
|
|
38
|
+
// and the geocode endpoint — the one with a VERIFIED, generous 3,000 QPM figure — gets it.
|
|
39
|
+
//
|
|
40
|
+
// Everything else is priced at `defaultWeight` (2) or above, never below, because Google documents
|
|
41
|
+
// that "the rate limit per minute is per API method per project" WITHOUT publishing the per-method
|
|
42
|
+
// numbers for the Places surfaces. An endpoint whose limit we cannot read is an endpoint we must not
|
|
43
|
+
// assume is generous.
|
|
44
|
+
//
|
|
45
|
+
// Place Details is priced at 4 — above default. That is a JUDGEMENT CALL, not a published cost: it
|
|
46
|
+
// is the only endpoint in this connector whose response is unbounded in size (a full place record),
|
|
47
|
+
// and Google publishes no per-minute figure for it. Unknown limit + heaviest response ⇒ dearest
|
|
48
|
+
// price. No billing figure is cited here because none was verified.
|
|
49
|
+
import { declareRateBudget, rateBudgetPath, rateBudgetWeight, RateBudget, } from '@volter/world-core';
|
|
50
|
+
const VENDOR = 'googlemaps';
|
|
51
|
+
/** Rolling window, in ms. Spend older than this is pruned. Matches Google's own per-MINUTE quotas. */
|
|
52
|
+
export const GOOGLEMAPS_BUDGET_WINDOW_MS = 60_000;
|
|
53
|
+
/**
|
|
54
|
+
* Weighted units allowed inside one window. 300 geocodes/60s = 10% of the documented 3,000 QPM.
|
|
55
|
+
*/
|
|
56
|
+
export const GOOGLEMAPS_BUDGET_CEILING = 300;
|
|
57
|
+
/** Seconds. A `Retry-After` above this means the project is throttled hard — fail loudly. */
|
|
58
|
+
export const GOOGLEMAPS_BUDGET_MAX_RETRY_AFTER_S = 300;
|
|
59
|
+
/** Per-call cost, keyed by the `<METHOD> <path>` this connector is about to request. See the header. */
|
|
60
|
+
export const GOOGLEMAPS_CALL_WEIGHTS = {
|
|
61
|
+
/** `GET /maps/api/geocode/json` — documented 3,000 QPM, the most generous figure Google publishes. */
|
|
62
|
+
geocode: 1,
|
|
63
|
+
/** `GET /maps/api/place/details/json` — unbounded response, NO published per-minute figure. */
|
|
64
|
+
placeDetails: 4,
|
|
65
|
+
/** Anything this pack has not classified. Priced like a read, never free. */
|
|
66
|
+
other: 2,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* THE PACK'S DECLARATION — pure data, the only Google-specific thing in the whole budget. Rules are
|
|
70
|
+
* ordered and first-match-wins, and they are keyed on `"<METHOD> <pathname>"` (not the bare path):
|
|
71
|
+
* Google's quotas are per API METHOD, and a write to a surface is not the same call as a read of it,
|
|
72
|
+
* so the method has to be part of what gets priced.
|
|
73
|
+
*
|
|
74
|
+
* Also exported as `pack.rateBudget` (see index.ts), so `registerPack` arms it too.
|
|
75
|
+
*/
|
|
76
|
+
export const GOOGLEMAPS_RATE_BUDGET = {
|
|
77
|
+
windowMs: GOOGLEMAPS_BUDGET_WINDOW_MS,
|
|
78
|
+
ceiling: GOOGLEMAPS_BUDGET_CEILING,
|
|
79
|
+
defaultWeight: GOOGLEMAPS_CALL_WEIGHTS.other,
|
|
80
|
+
maxRetryAfterSeconds: GOOGLEMAPS_BUDGET_MAX_RETRY_AFTER_S,
|
|
81
|
+
rules: [
|
|
82
|
+
{ match: '^GET /maps/api/place/details', weight: GOOGLEMAPS_CALL_WEIGHTS.placeDetails },
|
|
83
|
+
{ match: '^GET /maps/api/geocode/', weight: GOOGLEMAPS_CALL_WEIGHTS.geocode },
|
|
84
|
+
],
|
|
85
|
+
reason: 'Google documents the Geocoding API as rate-limited to 3,000 QPM (queries per minute), counted as the ' +
|
|
86
|
+
'sum of client-side and server-side queries, and the Maps Platform FAQ warns that repeatedly exceeding ' +
|
|
87
|
+
'a product\'s QPM can get access temporarily blocked. 300 weighted units / 60s prices a geocode at 1, so the ceiling is ' +
|
|
88
|
+
'10% of that documented limit — many times a legitimate pull of a few dozen addresses, and a hard stop ' +
|
|
89
|
+
'for the careless loop that the ~4.5-day Figma lockout (2026-07-25) showed the cost of. Place Details ' +
|
|
90
|
+
'costs 4 because Google publishes NO per-minute figure for it and its response is the pack\'s largest — ' +
|
|
91
|
+
'a judgement call, not a published cost.',
|
|
92
|
+
};
|
|
93
|
+
// Declared at module load, so merely importing this module (which `googlemaps-connector.ts` does) is
|
|
94
|
+
// enough to arm the real ceiling. A budget constructed BEFORE this runs falls back to the kernel's
|
|
95
|
+
// DEFAULT_RATE_BUDGET, which is tighter in call count but prices every endpoint at 2 — cheaper than
|
|
96
|
+
// the weight below for Place Details — so "the fallback is always safer" would be a false comfort.
|
|
97
|
+
// `RateBudget` reads its policy live precisely so this declaration takes effect the moment it lands,
|
|
98
|
+
// and constructing through the subclass below (which imports this module) makes the ordering a
|
|
99
|
+
// non-issue in practice.
|
|
100
|
+
declareRateBudget(VENDOR, GOOGLEMAPS_RATE_BUDGET);
|
|
101
|
+
/** Split a connector path (which carries its own query string) into pathname + parsed query. */
|
|
102
|
+
export function splitGoogleMapsPath(path) {
|
|
103
|
+
const q = path.indexOf('?');
|
|
104
|
+
if (q < 0)
|
|
105
|
+
return { pathname: path, query: {} };
|
|
106
|
+
const query = {};
|
|
107
|
+
for (const [k, v] of new URLSearchParams(path.slice(q + 1)))
|
|
108
|
+
query[k] = v;
|
|
109
|
+
return { pathname: path.slice(0, q), query };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Price one call. Keyed off the request the connector is ABOUT to make, so an unclassified endpoint
|
|
113
|
+
* still costs `defaultWeight` — an unknown endpoint must never be free.
|
|
114
|
+
*/
|
|
115
|
+
export function googleMapsCallWeight(method, path) {
|
|
116
|
+
const { pathname, query } = splitGoogleMapsPath(path);
|
|
117
|
+
return rateBudgetWeight(VENDOR, `${(method || 'GET').toUpperCase()} ${pathname}`, query);
|
|
118
|
+
}
|
|
119
|
+
/** Where Google Maps' ledger lives. API-key-keyed and cwd-independent by default (the quota is per
|
|
120
|
+
* project/key, so a cwd-scoped ledger would hand the same key a fresh allowance in every checkout,
|
|
121
|
+
* worktree and CI matrix leg); pass `root` to opt into world-scoped accounting instead. */
|
|
122
|
+
export function googleMapsBudgetPath(opts = {}) {
|
|
123
|
+
const o = typeof opts === 'string' ? { root: opts } : opts;
|
|
124
|
+
// VENDOR spread LAST: a loosely-typed `{ vendor: 'other', … }` slipping through (TypeScript's
|
|
125
|
+
// excess-property check only catches object literals) must not redirect this pack's ledger to
|
|
126
|
+
// another vendor's file.
|
|
127
|
+
return rateBudgetPath({ ...o, vendor: VENDOR });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Google Maps' budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
|
|
131
|
+
* not an alias, so `budget instanceof GoogleMapsBudget` in `liveGoogleMapsExecute` still means "a
|
|
132
|
+
* budget that accounts against GOOGLEMAPS' ledger under GOOGLEMAPS' ceiling": another vendor's
|
|
133
|
+
* `RateBudget` (with its own, possibly larger, ceiling) is NOT assignable there.
|
|
134
|
+
*/
|
|
135
|
+
export class GoogleMapsBudget extends RateBudget {
|
|
136
|
+
constructor(opts = {}) {
|
|
137
|
+
super({ ...opts, vendor: VENDOR });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** The typed refusal. One error class shared with every other vendor's budget; `err.vendor` says
|
|
141
|
+
* which one refused, and `err.kind` says why. */
|
|
142
|
+
export { RateBudgetError as GoogleMapsBudgetError } from '@volter/world-core';
|