@basemaps/lambda-tiler 6.29.0 → 6.32.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.
Files changed (259) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/build/__tests__/config.data.d.ts +11 -0
  3. package/build/__tests__/config.data.d.ts.map +1 -0
  4. package/build/__tests__/config.data.js +112 -0
  5. package/build/__tests__/config.data.js.map +1 -0
  6. package/build/__tests__/index.test.js +5 -14
  7. package/build/__tests__/index.test.js.map +1 -0
  8. package/build/__tests__/tile.style.json.test.js +1 -0
  9. package/build/__tests__/tile.style.json.test.js.map +1 -0
  10. package/build/__tests__/wmts.capability.test.d.ts +1 -1
  11. package/build/__tests__/wmts.capability.test.d.ts.map +1 -1
  12. package/build/__tests__/wmts.capability.test.js +286 -125
  13. package/build/__tests__/wmts.capability.test.js.map +1 -0
  14. package/build/__tests__/xyz.util.d.ts +7 -11
  15. package/build/__tests__/xyz.util.d.ts.map +1 -1
  16. package/build/__tests__/xyz.util.js +14 -42
  17. package/build/__tests__/xyz.util.js.map +1 -0
  18. package/build/index.d.ts +0 -2
  19. package/build/index.d.ts.map +1 -1
  20. package/build/index.js +68 -41
  21. package/build/index.js.map +1 -0
  22. package/build/routes/__tests__/attribution.test.js +351 -399
  23. package/build/routes/__tests__/attribution.test.js.map +1 -0
  24. package/build/routes/__tests__/fonts.test.js +17 -3
  25. package/build/routes/__tests__/fonts.test.js.map +1 -0
  26. package/build/routes/__tests__/health.test.js +17 -13
  27. package/build/routes/__tests__/health.test.js.map +1 -0
  28. package/build/routes/__tests__/imagery.test.js +1 -0
  29. package/build/routes/__tests__/imagery.test.js.map +1 -0
  30. package/build/routes/__tests__/memory.fs.js +1 -0
  31. package/build/routes/__tests__/memory.fs.js.map +1 -0
  32. package/build/routes/__tests__/sprites.test.js +7 -0
  33. package/build/routes/__tests__/sprites.test.js.map +1 -0
  34. package/build/routes/__tests__/tile.json.test.d.ts +2 -0
  35. package/build/routes/__tests__/tile.json.test.d.ts.map +1 -0
  36. package/build/routes/__tests__/tile.json.test.js +124 -0
  37. package/build/routes/__tests__/tile.json.test.js.map +1 -0
  38. package/build/routes/__tests__/tile.style.json.test.d.ts +2 -0
  39. package/build/routes/__tests__/tile.style.json.test.d.ts.map +1 -0
  40. package/build/routes/__tests__/tile.style.json.test.js +95 -0
  41. package/build/routes/__tests__/tile.style.json.test.js.map +1 -0
  42. package/build/routes/__tests__/wmts.test.js +37 -27
  43. package/build/routes/__tests__/wmts.test.js.map +1 -0
  44. package/build/{__tests__ → routes/__tests__}/xyz.test.d.ts +0 -0
  45. package/build/routes/__tests__/xyz.test.d.ts.map +1 -0
  46. package/build/routes/__tests__/xyz.test.js +99 -0
  47. package/build/routes/__tests__/xyz.test.js.map +1 -0
  48. package/build/routes/attribution.d.ts +7 -5
  49. package/build/routes/attribution.d.ts.map +1 -1
  50. package/build/routes/attribution.js +50 -91
  51. package/build/routes/attribution.js.map +1 -0
  52. package/build/routes/fonts.d.ts +1 -1
  53. package/build/routes/fonts.d.ts.map +1 -1
  54. package/build/routes/fonts.js +33 -10
  55. package/build/routes/fonts.js.map +1 -0
  56. package/build/routes/health.d.ts +3 -3
  57. package/build/routes/health.d.ts.map +1 -1
  58. package/build/routes/health.js +16 -13
  59. package/build/routes/health.js.map +1 -0
  60. package/build/routes/imagery.d.ts +8 -1
  61. package/build/routes/imagery.d.ts.map +1 -1
  62. package/build/routes/imagery.js +17 -17
  63. package/build/routes/imagery.js.map +1 -0
  64. package/build/routes/ping.d.ts +3 -0
  65. package/build/routes/ping.d.ts.map +1 -0
  66. package/build/routes/ping.js +7 -0
  67. package/build/routes/ping.js.map +1 -0
  68. package/build/routes/sprites.d.ts.map +1 -1
  69. package/build/routes/sprites.js +22 -22
  70. package/build/routes/sprites.js.map +1 -0
  71. package/build/routes/tile.json.d.ts +7 -1
  72. package/build/routes/tile.json.d.ts.map +1 -1
  73. package/build/routes/tile.json.js +19 -22
  74. package/build/routes/tile.json.js.map +1 -0
  75. package/build/routes/tile.style.json.d.ts +6 -1
  76. package/build/routes/tile.style.json.d.ts.map +1 -1
  77. package/build/routes/tile.style.json.js +11 -13
  78. package/build/routes/tile.style.json.js.map +1 -0
  79. package/build/routes/tile.wmts.d.ts +9 -3
  80. package/build/routes/tile.wmts.d.ts.map +1 -1
  81. package/build/routes/tile.wmts.js +37 -50
  82. package/build/routes/tile.wmts.js.map +1 -0
  83. package/build/routes/tile.xyz.d.ts +14 -4
  84. package/build/routes/tile.xyz.d.ts.map +1 -1
  85. package/build/routes/tile.xyz.js +22 -17
  86. package/build/routes/tile.xyz.js.map +1 -0
  87. package/build/routes/tile.xyz.raster.d.ts +11 -0
  88. package/build/routes/tile.xyz.raster.d.ts.map +1 -0
  89. package/build/routes/tile.xyz.raster.js +90 -0
  90. package/build/routes/tile.xyz.raster.js.map +1 -0
  91. package/build/routes/tile.xyz.vector.d.ts +8 -0
  92. package/build/routes/tile.xyz.vector.d.ts.map +1 -0
  93. package/build/routes/tile.xyz.vector.js +46 -0
  94. package/build/routes/tile.xyz.vector.js.map +1 -0
  95. package/build/routes/version.d.ts +3 -0
  96. package/build/routes/version.d.ts.map +1 -0
  97. package/build/routes/version.js +9 -0
  98. package/build/routes/version.js.map +1 -0
  99. package/build/util/__test__/validate.test.d.ts +2 -0
  100. package/build/util/__test__/validate.test.d.ts.map +1 -0
  101. package/build/util/__test__/validate.test.js +66 -0
  102. package/build/util/__test__/validate.test.js.map +1 -0
  103. package/build/util/cotar.serve.d.ts +20 -0
  104. package/build/util/cotar.serve.d.ts.map +1 -0
  105. package/build/util/cotar.serve.js +41 -0
  106. package/build/util/cotar.serve.js.map +1 -0
  107. package/build/util/etag.d.ts +6 -0
  108. package/build/util/etag.d.ts.map +1 -0
  109. package/build/util/etag.js +20 -0
  110. package/build/util/etag.js.map +1 -0
  111. package/build/util/response.d.ts +4 -0
  112. package/build/util/response.d.ts.map +1 -0
  113. package/build/util/response.js +4 -0
  114. package/build/util/response.js.map +1 -0
  115. package/build/util/source.cache.d.ts +28 -0
  116. package/build/util/source.cache.d.ts.map +1 -0
  117. package/build/util/source.cache.js +53 -0
  118. package/build/util/source.cache.js.map +1 -0
  119. package/build/{source.tracer.d.ts → util/source.tracer.d.ts} +1 -0
  120. package/build/util/source.tracer.d.ts.map +1 -0
  121. package/build/{source.tracer.js → util/source.tracer.js} +4 -0
  122. package/build/util/source.tracer.js.map +1 -0
  123. package/build/util/swapping.lru.d.ts +21 -0
  124. package/build/util/swapping.lru.d.ts.map +1 -0
  125. package/build/util/swapping.lru.js +56 -0
  126. package/build/util/swapping.lru.js.map +1 -0
  127. package/build/util/validate.d.ts +46 -0
  128. package/build/util/validate.d.ts.map +1 -0
  129. package/build/util/validate.js +107 -0
  130. package/build/util/validate.js.map +1 -0
  131. package/build/wmts.capability.d.ts +27 -13
  132. package/build/wmts.capability.d.ts.map +1 -1
  133. package/build/wmts.capability.js +156 -55
  134. package/build/wmts.capability.js.map +1 -0
  135. package/dist/index.js +89 -73
  136. package/dist/node_modules/.package-lock.json +1 -1
  137. package/dist/package-lock.json +2 -2
  138. package/dist/package.json +1 -1
  139. package/package.json +10 -10
  140. package/src/__tests__/config.data.ts +120 -0
  141. package/src/__tests__/index.test.ts +4 -20
  142. package/src/__tests__/wmts.capability.test.ts +312 -139
  143. package/src/__tests__/xyz.util.ts +17 -45
  144. package/src/index.ts +75 -41
  145. package/src/routes/__tests__/attribution.test.ts +356 -403
  146. package/src/routes/__tests__/fonts.test.ts +18 -3
  147. package/src/routes/__tests__/health.test.ts +17 -13
  148. package/src/routes/__tests__/sprites.test.ts +6 -1
  149. package/src/routes/__tests__/tile.json.test.ts +145 -0
  150. package/src/routes/__tests__/tile.style.json.test.ts +105 -0
  151. package/src/routes/__tests__/wmts.test.ts +44 -34
  152. package/src/routes/__tests__/xyz.test.ts +119 -0
  153. package/src/routes/attribution.ts +59 -111
  154. package/src/routes/fonts.ts +32 -10
  155. package/src/routes/health.ts +17 -16
  156. package/src/routes/imagery.ts +18 -15
  157. package/src/routes/ping.ts +8 -0
  158. package/src/routes/sprites.ts +20 -22
  159. package/src/routes/tile.json.ts +24 -19
  160. package/src/routes/tile.style.json.ts +15 -12
  161. package/src/routes/tile.wmts.ts +41 -44
  162. package/src/routes/tile.xyz.raster.ts +106 -0
  163. package/src/routes/tile.xyz.ts +31 -16
  164. package/src/routes/tile.xyz.vector.ts +47 -0
  165. package/src/routes/version.ts +8 -0
  166. package/src/util/__test__/validate.test.ts +74 -0
  167. package/src/util/cotar.serve.ts +46 -0
  168. package/src/util/etag.ts +20 -0
  169. package/src/util/response.ts +4 -0
  170. package/src/util/source.cache.ts +71 -0
  171. package/src/{source.tracer.ts → util/source.tracer.ts} +4 -0
  172. package/src/util/swapping.lru.ts +63 -0
  173. package/src/util/validate.ts +126 -0
  174. package/src/wmts.capability.ts +170 -68
  175. package/tsconfig.tsbuildinfo +1 -1
  176. package/build/__tests__/route.test.d.ts +0 -2
  177. package/build/__tests__/route.test.d.ts.map +0 -1
  178. package/build/__tests__/route.test.js +0 -20
  179. package/build/__tests__/tiff.cache.test.d.ts +0 -2
  180. package/build/__tests__/tiff.cache.test.d.ts.map +0 -1
  181. package/build/__tests__/tiff.cache.test.js +0 -58
  182. package/build/__tests__/tile.cache.key.test.d.ts +0 -2
  183. package/build/__tests__/tile.cache.key.test.d.ts.map +0 -1
  184. package/build/__tests__/tile.cache.key.test.js +0 -48
  185. package/build/__tests__/tile.set.cache.test.d.ts +0 -2
  186. package/build/__tests__/tile.set.cache.test.d.ts.map +0 -1
  187. package/build/__tests__/tile.set.cache.test.js +0 -123
  188. package/build/__tests__/tile.set.test.d.ts +0 -2
  189. package/build/__tests__/tile.set.test.d.ts.map +0 -1
  190. package/build/__tests__/tile.set.test.js +0 -11
  191. package/build/__tests__/xyz.test.d.ts.map +0 -1
  192. package/build/__tests__/xyz.test.js +0 -306
  193. package/build/api.key.d.ts +0 -2
  194. package/build/api.key.d.ts.map +0 -1
  195. package/build/api.key.js +0 -23
  196. package/build/cli/dump.d.ts +0 -2
  197. package/build/cli/dump.d.ts.map +0 -1
  198. package/build/cli/dump.js +0 -47
  199. package/build/cli/tile.set.local.d.ts +0 -12
  200. package/build/cli/tile.set.local.d.ts.map +0 -1
  201. package/build/cli/tile.set.local.js +0 -39
  202. package/build/router.d.ts +0 -15
  203. package/build/router.d.ts.map +0 -1
  204. package/build/router.js +0 -49
  205. package/build/routes/api.d.ts +0 -5
  206. package/build/routes/api.d.ts.map +0 -1
  207. package/build/routes/api.js +0 -16
  208. package/build/routes/esri/rest.d.ts +0 -10
  209. package/build/routes/esri/rest.d.ts.map +0 -1
  210. package/build/routes/esri/rest.js +0 -87
  211. package/build/routes/response.d.ts +0 -4
  212. package/build/routes/response.d.ts.map +0 -1
  213. package/build/routes/response.js +0 -3
  214. package/build/routes/tile.d.ts +0 -3
  215. package/build/routes/tile.d.ts.map +0 -1
  216. package/build/routes/tile.etag.d.ts +0 -11
  217. package/build/routes/tile.etag.d.ts.map +0 -1
  218. package/build/routes/tile.etag.js +0 -29
  219. package/build/routes/tile.js +0 -27
  220. package/build/source.tracer.d.ts.map +0 -1
  221. package/build/tiff.cache.d.ts +0 -17
  222. package/build/tiff.cache.d.ts.map +0 -1
  223. package/build/tiff.cache.js +0 -45
  224. package/build/tile.set.cache.d.ts +0 -21
  225. package/build/tile.set.cache.d.ts.map +0 -1
  226. package/build/tile.set.cache.js +0 -100
  227. package/build/tile.set.d.ts +0 -4
  228. package/build/tile.set.d.ts.map +0 -1
  229. package/build/tile.set.js +0 -1
  230. package/build/tile.set.raster.d.ts +0 -49
  231. package/build/tile.set.raster.d.ts.map +0 -1
  232. package/build/tile.set.raster.js +0 -186
  233. package/build/tile.set.vector.d.ts +0 -25
  234. package/build/tile.set.vector.d.ts.map +0 -1
  235. package/build/tile.set.vector.js +0 -71
  236. package/build/validate.d.ts +0 -16
  237. package/build/validate.d.ts.map +0 -1
  238. package/build/validate.js +0 -31
  239. package/src/__tests__/route.test.ts +0 -24
  240. package/src/__tests__/tiff.cache.test.ts +0 -73
  241. package/src/__tests__/tile.cache.key.test.ts +0 -56
  242. package/src/__tests__/tile.set.cache.test.ts +0 -146
  243. package/src/__tests__/tile.set.test.ts +0 -12
  244. package/src/__tests__/xyz.test.ts +0 -362
  245. package/src/api.key.ts +0 -23
  246. package/src/cli/dump.ts +0 -61
  247. package/src/cli/tile.set.local.ts +0 -51
  248. package/src/router.ts +0 -58
  249. package/src/routes/api.ts +0 -19
  250. package/src/routes/esri/rest.ts +0 -90
  251. package/src/routes/response.ts +0 -4
  252. package/src/routes/tile.etag.ts +0 -36
  253. package/src/routes/tile.ts +0 -23
  254. package/src/tiff.cache.ts +0 -51
  255. package/src/tile.set.cache.ts +0 -111
  256. package/src/tile.set.raster.ts +0 -228
  257. package/src/tile.set.ts +0 -4
  258. package/src/tile.set.vector.ts +0 -79
  259. package/src/validate.ts +0 -32
@@ -1,11 +0,0 @@
1
- import { GoogleTms, Nztm2000Tms } from '@basemaps/geo';
2
- import o from 'ospec';
3
- import { TileSetRaster } from '../tile.set.raster.js';
4
- o.spec('tile.set', () => {
5
- o('extent', () => {
6
- o(new TileSetRaster('google', GoogleTms).extent.toBbox()).deepEquals([
7
- -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892,
8
- ]);
9
- o(new TileSetRaster('nztm', Nztm2000Tms).extent.toBbox()).deepEquals([274000, 3087000, 3327000, 7173000]);
10
- });
11
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"xyz.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/xyz.test.ts"],"names":[],"mappings":""}
@@ -1,306 +0,0 @@
1
- import { GoogleTms, Nztm2000QuadTms, TileMatrixSets } from '@basemaps/geo';
2
- import { Config, Env, LogConfig, VNodeParser } from '@basemaps/shared';
3
- import { round } from '@basemaps/test/build/rounding.js';
4
- import o from 'ospec';
5
- import sinon from 'sinon';
6
- import { handleRequest } from '../index.js';
7
- import { TileEtag } from '../routes/tile.etag.js';
8
- import { TileSets } from '../tile.set.cache.js';
9
- import { TileComposer } from '../tile.set.raster.js';
10
- import { FakeTileSet, FakeTileSetVector, mockRequest, Provider } from './xyz.util.js';
11
- const sandbox = sinon.createSandbox();
12
- const TileSetNames = ['aerial', 'aerial@head', 'aerial@beta', '01E7PJFR9AMQFJ05X9G7FQ3XMW'];
13
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
14
- o.spec('LambdaXyz', () => {
15
- const host = 'https://tiles.test';
16
- const origPublicUrlBase = process.env[Env.PublicUrlBase];
17
- /** Generate mock ALBEvent */
18
- let rasterMock = o.spy();
19
- const generateMock = o.spy(() => 'foo');
20
- const rasterMockBuffer = Buffer.from([1]);
21
- const origTileEtag = TileEtag.generate;
22
- const origCompose = TileComposer.compose;
23
- const apiKey = 'd01f7w7rnhdzg0p7fyrc9v9ard1';
24
- const apiKeyHeader = { 'x-linz-api-key': 'd01f7w7rnhdzg0p7fyrc9v9ard1' };
25
- o.beforeEach(() => {
26
- process.env[Env.PublicUrlBase] = host;
27
- LogConfig.disable();
28
- // tileMock = o.spy(() => tileMockData) as any;
29
- rasterMock = o.spy(() => {
30
- return {
31
- buffer: rasterMockBuffer,
32
- };
33
- });
34
- TileEtag.generate = generateMock;
35
- TileComposer.compose = rasterMock;
36
- const allMatrix = [...TileMatrixSets.All.values()];
37
- for (const tileSetName of TileSetNames) {
38
- for (const tileMatrix of allMatrix) {
39
- const tileSet = new FakeTileSet(tileSetName, tileMatrix);
40
- TileSets.add(tileSet);
41
- tileSet.getTiffsForTile = () => [];
42
- tileSet.initTiffs = async () => [];
43
- }
44
- }
45
- TileSets.add(new FakeTileSetVector('topographic', GoogleTms));
46
- Config.Provider.get = async () => Provider;
47
- });
48
- o.afterEach(() => {
49
- TileSets.cache.clear();
50
- TileComposer.compose = origCompose;
51
- TileEtag.generate = origTileEtag;
52
- process.env[Env.PublicUrlBase] = origPublicUrlBase;
53
- sandbox.restore();
54
- });
55
- o('should export handler', async () => {
56
- const base = await import('../index.js');
57
- o(typeof base.handler).equals('function');
58
- });
59
- TileSetNames.forEach((tileSetName) => {
60
- o(`should generate a tile 0,0,0 for ${tileSetName}.png`, async () => {
61
- o.timeout(200);
62
- const request = mockRequest(`/v1/tiles/${tileSetName}/global-mercator/0/0/0.png`, 'get', apiKeyHeader);
63
- const res = await handleRequest(request);
64
- o(res.status).equals(200);
65
- o(res.header('content-type')).equals('image/png');
66
- o(res.header('eTaG')).equals('foo');
67
- o(res.body).equals(rasterMockBuffer.toString('base64'));
68
- // Validate the session information has been set correctly
69
- o(request.logContext['tileSet']).equals(tileSetName);
70
- o(request.logContext['xyz']).deepEquals({ x: 0, y: 0, z: 0 });
71
- o(round(request.logContext['location'])).deepEquals({ lat: 0, lon: 0 });
72
- });
73
- });
74
- o('should generate a tile 0,0,0 for webp', async () => {
75
- const request = mockRequest('/v1/tiles/aerial/3857/0/0/0.webp', 'get', apiKeyHeader);
76
- const res = await handleRequest(request);
77
- o(res.status).equals(200);
78
- o(res.header('content-type')).equals('image/webp');
79
- o(res.header('eTaG')).equals('foo');
80
- o(res.body).equals(rasterMockBuffer.toString('base64'));
81
- // Validate the session information has been set correctly
82
- o(request.logContext['xyz']).deepEquals({ x: 0, y: 0, z: 0 });
83
- o(round(request.logContext['location'])).deepEquals({ lat: 0, lon: 0 });
84
- });
85
- ['png', 'webp', 'jpeg'].forEach((fmt) => {
86
- o(`should 200 with empty ${fmt} if a tile is out of bounds`, async () => {
87
- // tiler.tile = async () => [];
88
- const res = await handleRequest(mockRequest(`/v1/tiles/aerial/global-mercator/0/0/0.${fmt}`, 'get', apiKeyHeader));
89
- o(res.status).equals(200);
90
- o(res.header('content-type')).equals(`image/${fmt}`);
91
- o(rasterMock.calls.length).equals(1);
92
- });
93
- });
94
- o('should 304 if a tile is not modified', async () => {
95
- const key = 'foo';
96
- const request = mockRequest('/v1/tiles/aerial/global-mercator/0/0/0.png', 'get', {
97
- 'if-none-match': key,
98
- ...apiKeyHeader,
99
- });
100
- const res = await handleRequest(request);
101
- o(res.status).equals(304);
102
- o(res.header('eTaG')).equals(undefined);
103
- o(rasterMock.calls.length).equals(0);
104
- o(request.logContext['cache']).deepEquals({ key, match: key, hit: true });
105
- });
106
- o('should 404 if a tile is outside of the range', async () => {
107
- try {
108
- const res = await handleRequest(mockRequest('/v1/tiles/aerial/global-mercator/25/0/0.png', 'get', apiKeyHeader));
109
- o(res.status).equals(404);
110
- }
111
- catch (e) {
112
- o(e.status).equals(404);
113
- }
114
- try {
115
- const res = await handleRequest(mockRequest('/v1/tiles/aerial/2193/17/0/0.png', 'get', apiKeyHeader));
116
- o(res.status).equals(404);
117
- }
118
- catch (e) {
119
- o(e.status).equals(404);
120
- }
121
- });
122
- o.spec('WMTSCapabilities', () => {
123
- o('should 304 if a xml is not modified', async () => {
124
- delete process.env[Env.PublicUrlBase];
125
- o.timeout(1000);
126
- const key = 'NuirTK8fozzCJV1iG1FznmdHhKvk6WaWuDhhEA1d40c=';
127
- const request = mockRequest('/v1/tiles/WMTSCapabilities.xml', 'get', {
128
- 'if-none-match': key,
129
- ...apiKeyHeader,
130
- });
131
- const res = await handleRequest(request);
132
- if (res.status === 200) {
133
- o(res.header('eTaG')).equals(key); // this line is useful for discovering the new etag
134
- return;
135
- }
136
- o(res.status).equals(304);
137
- o(rasterMock.calls.length).equals(0);
138
- o(request.logContext['cache']).deepEquals({ key, match: key, hit: true });
139
- });
140
- o('should serve WMTSCapabilities for tile_set', async () => {
141
- var _a;
142
- const request = mockRequest('/v1/tiles/aerial@beta/WMTSCapabilities.xml', 'get', apiKeyHeader);
143
- const res = await handleRequest(request);
144
- o(res.status).equals(200);
145
- o(res.header('content-type')).equals('text/xml');
146
- o(res.header('cache-control')).equals('max-age=0');
147
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
148
- o(body.slice(0, 100)).equals('<?xml version="1.0"?>\n' + '<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.op');
149
- const vdom = await VNodeParser.parse(body);
150
- const url = vdom.tags('ResourceURL').next().value;
151
- o(url === null || url === void 0 ? void 0 : url.toString()).equals('<ResourceURL format="image/jpeg" resourceType="tile" ' +
152
- `template="https://tiles.test/v1/tiles/aerial@beta/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.jpeg?api=${apiKey}" />`);
153
- });
154
- });
155
- o.spec('tileJson', () => {
156
- o('should 404 if invalid url is given', async () => {
157
- const request = mockRequest('/v1/tiles/tile.json', 'get', apiKeyHeader);
158
- const res = await handleRequest(request);
159
- o(res.status).equals(404);
160
- });
161
- o('should serve tile json for tile_set', async () => {
162
- var _a;
163
- const request = mockRequest('/v1/tiles/aerial/NZTM2000Quad/tile.json', 'get', apiKeyHeader);
164
- const res = await handleRequest(request);
165
- o(res.status).equals(200);
166
- o(res.header('cache-control')).equals('no-store');
167
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
168
- o(JSON.parse(body)).deepEquals({
169
- tiles: [`https://tiles.test/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.webp?api=${apiKey}`],
170
- tilejson: '3.0.0',
171
- });
172
- });
173
- o('should serve vector tiles', async () => {
174
- var _a;
175
- const request = mockRequest('/v1/tiles/topographic/WebMercatorQuad/tile.json', 'get', apiKeyHeader);
176
- const res = await handleRequest(request);
177
- o(res.status).equals(200);
178
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
179
- o(JSON.parse(body)).deepEquals({
180
- tiles: [`https://tiles.test/v1/tiles/topographic/EPSG:3857/{z}/{x}/{y}.pbf?api=${apiKey}`],
181
- tilejson: '3.0.0',
182
- });
183
- });
184
- o('should serve vector tiles with min/max zoom', async () => {
185
- var _a;
186
- const fakeTileSet = new FakeTileSetVector('fake-vector', GoogleTms);
187
- fakeTileSet.tileSet.maxZoom = 15;
188
- fakeTileSet.tileSet.minZoom = 3;
189
- TileSets.add(fakeTileSet);
190
- const request = mockRequest('/v1/tiles/fake-vector/WebMercatorQuad/tile.json', 'get', apiKeyHeader);
191
- const res = await handleRequest(request);
192
- o(res.status).equals(200);
193
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
194
- o(JSON.parse(body)).deepEquals({
195
- tiles: [`https://tiles.test/v1/tiles/fake-vector/EPSG:3857/{z}/{x}/{y}.pbf?api=${apiKey}`],
196
- maxzoom: 15,
197
- minzoom: 3,
198
- tilejson: '3.0.0',
199
- });
200
- });
201
- o('should serve convert zoom to tile matrix', async () => {
202
- var _a;
203
- const fakeTileSet = new FakeTileSetVector('fake-vector', Nztm2000QuadTms);
204
- fakeTileSet.tileSet.maxZoom = 15;
205
- fakeTileSet.tileSet.minZoom = 1;
206
- TileSets.add(fakeTileSet);
207
- const request = mockRequest('/v1/tiles/fake-vector/NZTM2000Quad/tile.json', 'get', apiKeyHeader);
208
- const res = await handleRequest(request);
209
- o(res.status).equals(200);
210
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
211
- o(JSON.parse(body)).deepEquals({
212
- tiles: [`https://tiles.test/v1/tiles/fake-vector/NZTM2000Quad/{z}/{x}/{y}.pbf?api=${apiKey}`],
213
- maxzoom: 13,
214
- minzoom: 0,
215
- tilejson: '3.0.0',
216
- });
217
- });
218
- });
219
- o.spec('styleJson', () => {
220
- o('should not found style json', async () => {
221
- const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
222
- sandbox.stub(Config.Style, 'get').resolves(null);
223
- const res = await handleRequest(request);
224
- o(res.status).equals(404);
225
- });
226
- o('should serve style json', async () => {
227
- var _a;
228
- const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
229
- const fakeStyle = {
230
- version: 8,
231
- id: 'test',
232
- name: 'topographic',
233
- sources: {
234
- basemaps_vector: {
235
- type: 'vector',
236
- url: `/vector`,
237
- },
238
- basemaps_raster: {
239
- type: 'raster',
240
- tiles: [`/raster`],
241
- },
242
- basemaps_raster_encode: {
243
- type: 'raster',
244
- tiles: [`/raster/{z}/{x}/{y}.webp`], // Shouldn't encode the {}
245
- },
246
- test_vector: {
247
- type: 'vector',
248
- url: 'vector.url.co.nz',
249
- },
250
- test_raster: {
251
- type: 'raster',
252
- tiles: ['raster.url.co.nz'],
253
- },
254
- },
255
- layers: [
256
- {
257
- layout: {
258
- visibility: 'visible',
259
- },
260
- paint: {
261
- 'background-color': 'rgba(206, 229, 242, 1)',
262
- },
263
- id: 'Background',
264
- type: 'background',
265
- minzoom: 0,
266
- },
267
- ],
268
- glyphs: '/glyphs',
269
- sprite: '/sprite',
270
- metadata: { id: 'test' },
271
- };
272
- const fakeRecord = {
273
- id: 'st_topographic_production',
274
- name: 'topographic',
275
- style: fakeStyle,
276
- };
277
- sandbox.stub(Config.Style, 'get').resolves(fakeRecord);
278
- const res = await handleRequest(request);
279
- o(res.status).equals(200);
280
- o(res.header('content-type')).equals('application/json');
281
- o(res.header('cache-control')).equals('no-store');
282
- const body = Buffer.from((_a = res.body) !== null && _a !== void 0 ? _a : '', 'base64').toString();
283
- fakeStyle.sources.basemaps_vector = {
284
- type: 'vector',
285
- url: `${host}/vector?api=${apiKey}`,
286
- };
287
- fakeStyle.sources.basemaps_raster = {
288
- type: 'raster',
289
- tiles: [`${host}/raster?api=${apiKey}`],
290
- };
291
- fakeStyle.sources.basemaps_raster_encode = {
292
- type: 'raster',
293
- tiles: [`${host}/raster/{z}/{x}/{y}.webp?api=${apiKey}`],
294
- };
295
- fakeStyle.sprite = `${host}/sprite`;
296
- fakeStyle.glyphs = `${host}/glyphs`;
297
- o(JSON.parse(body)).deepEquals(fakeStyle);
298
- });
299
- });
300
- ['/favicon.ico', '/index.html', '/foo/bar'].forEach((path) => {
301
- o('should error on invalid paths: ' + path, async () => {
302
- const res = await handleRequest(mockRequest(path, 'get', apiKeyHeader));
303
- o(res.status).equals(404);
304
- });
305
- });
306
- });
@@ -1,2 +0,0 @@
1
- export declare function isValidApiKey(apiKey?: string | null): boolean;
2
- //# sourceMappingURL=api.key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.key.d.ts","sourceRoot":"","sources":["../src/api.key.ts"],"names":[],"mappings":"AAMA,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAgB7D"}
package/build/api.key.js DELETED
@@ -1,23 +0,0 @@
1
- import * as ulid from 'ulid';
2
- const OneHourMs = 60 * 60 * 1000;
3
- const OneDayMs = 24 * OneHourMs;
4
- const MaxApiAgeMs = 91 * OneDayMs;
5
- export function isValidApiKey(apiKey) {
6
- if (apiKey == null)
7
- return false;
8
- if (!apiKey.startsWith('c') && !apiKey.startsWith('d'))
9
- return false;
10
- const ulidId = apiKey.slice(1).toUpperCase();
11
- try {
12
- const ulidTime = ulid.decodeTime(ulidId);
13
- if (apiKey.startsWith('d'))
14
- return true;
15
- if (Date.now() - ulidTime > MaxApiAgeMs) {
16
- return false;
17
- }
18
- }
19
- catch (e) {
20
- return false;
21
- }
22
- return true;
23
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=dump.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dump.d.ts","sourceRoot":"","sources":["../../src/cli/dump.ts"],"names":[],"mappings":""}
package/build/cli/dump.js DELETED
@@ -1,47 +0,0 @@
1
- import { Nztm2000Tms, ImageFormat } from '@basemaps/geo';
2
- import { LogConfig } from '@basemaps/shared';
3
- import { LambdaAlbRequest } from '@linzjs/lambda';
4
- import { promises as fs } from 'fs';
5
- import { tileXyz } from '../routes/tile.xyz.js';
6
- import { TileSets } from '../tile.set.cache.js';
7
- import { TileSetLocal } from './tile.set.local.js';
8
- const xyz = { x: 0, y: 0, z: 0 };
9
- const tileMatrix = Nztm2000Tms;
10
- const tileSetName = 'aerial';
11
- const ext = ImageFormat.Png;
12
- /** Load a tileset form a file path otherwise default to the hard coded one from AWS */
13
- async function getTileSet(filePath) {
14
- if (filePath != null) {
15
- const tileSet = new TileSetLocal('local', filePath);
16
- await tileSet.load();
17
- TileSets.add(tileSet);
18
- return tileSet;
19
- }
20
- const tileSet = await TileSets.get(tileSetName, tileMatrix);
21
- if (tileSet == null)
22
- throw new Error('Missing');
23
- return tileSet;
24
- }
25
- /**
26
- * Utility to render a single tile then save it as a png
27
- */
28
- async function main() {
29
- var _a;
30
- const logger = LogConfig.get();
31
- const filePath = process.argv[2];
32
- const tileSet = await getTileSet(filePath);
33
- logger.info({ ...xyz, projection: tileMatrix.projection.code, tileMatrix: tileMatrix.identifier }, 'RenderTile');
34
- const ctx = new LambdaAlbRequest({
35
- httpMethod: 'get',
36
- path: `/v1/tiles/${tileSet.fullName}/${tileMatrix.identifier}/${xyz.z}/${xyz.x}/${xyz.y}.${ext}`,
37
- }, {}, logger);
38
- const tileData = await tileXyz(ctx);
39
- const headers = {};
40
- for (const [key, value] of tileData.headers)
41
- headers[key] = value;
42
- logger.info({ ...tileData, _body: (_a = tileData.body) === null || _a === void 0 ? void 0 : _a.length, headers }, 'Done');
43
- if (tileData._body != null) {
44
- await fs.writeFile(`output_${xyz.x}_${xyz.y}_z${xyz.z}.${ext}`, tileData._body);
45
- }
46
- }
47
- main().catch(console.error);
@@ -1,12 +0,0 @@
1
- import { CogTiff } from '@cogeotiff/core';
2
- import { TileSetRaster } from '../tile.set.raster.js';
3
- export declare class TileSetLocal extends TileSetRaster {
4
- tiffs: CogTiff[];
5
- filePath: string;
6
- tileSet: any;
7
- constructor(name: string, path: string);
8
- setTitle(name: string): void;
9
- load(): Promise<boolean>;
10
- getTiffsForTile(): CogTiff[];
11
- }
12
- //# sourceMappingURL=tile.set.local.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.set.local.d.ts","sourceRoot":"","sources":["../../src/cli/tile.set.local.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAc,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAMtD,qBAAa,YAAa,SAAQ,aAAa;IAC7C,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,MAAa;gBAER,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAQtC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAItB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB9B,eAAe,IAAI,OAAO,EAAE;CAG7B"}
@@ -1,39 +0,0 @@
1
- import { Epsg, GoogleTms, TileMatrixSets } from '@basemaps/geo';
2
- import { fsa, LogConfig } from '@basemaps/shared';
3
- import { CogTiff, TiffTagGeo } from '@cogeotiff/core';
4
- import { TileSetRaster } from '../tile.set.raster.js';
5
- function isTiff(fileName) {
6
- return fileName.toLowerCase().endsWith('.tif') || fileName.toLowerCase().endsWith('.tiff');
7
- }
8
- export class TileSetLocal extends TileSetRaster {
9
- constructor(name, path) {
10
- super(name, GoogleTms);
11
- this.tileSet = {};
12
- this.filePath = path;
13
- this.tileSet.name = name;
14
- this.tileSet.title = name;
15
- this.tileSet.projection = GoogleTms.projection.code;
16
- }
17
- setTitle(name) {
18
- this.tileSet.title = name;
19
- }
20
- async load() {
21
- if (this.tiffs != null)
22
- return true;
23
- const fileList = isTiff(this.filePath) ? [this.filePath] : await fsa.toArray(fsa.list(this.filePath));
24
- const files = fileList.filter(isTiff);
25
- if (files.length === 0)
26
- throw new Error(`No tiff files found in ${this.filePath}`);
27
- this.tiffs = files.map((filePath) => new CogTiff(fsa.source(filePath)));
28
- // Read in the projection information
29
- const [firstTiff] = this.tiffs;
30
- await firstTiff.init(true);
31
- const projection = Epsg.get(firstTiff.getImage(0).valueGeo(TiffTagGeo.ProjectedCSTypeGeoKey));
32
- this.tileMatrix = TileMatrixSets.get(projection);
33
- LogConfig.get().info({ path: this.filePath, count: this.tiffs.length, tileMatrix: this.tileMatrix.identifier }, 'LoadedTiffs');
34
- return true;
35
- }
36
- getTiffsForTile() {
37
- return this.tiffs;
38
- }
39
- }
package/build/router.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
- export declare type ReqCallback = (req: LambdaHttpRequest) => Promise<LambdaHttpResponse>;
3
- export interface ActionData {
4
- version: string;
5
- name: string;
6
- rest: string[];
7
- }
8
- export declare class Router {
9
- static action(req: LambdaHttpRequest): ActionData;
10
- static apiKey(req: LambdaHttpRequest): string | undefined;
11
- private handlers;
12
- handle(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
13
- get(path: string, handler: ReqCallback): void;
14
- }
15
- //# sourceMappingURL=router.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,oBAAY,WAAW,GAAG,CAAC,GAAG,EAAE,iBAAiB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAElF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,qBAAa,MAAM;IACjB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,UAAU;IASjD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS;IASzD,OAAO,CAAC,QAAQ,CAAmC;IAE7C,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqBjE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;CAI9C"}
package/build/router.js DELETED
@@ -1,49 +0,0 @@
1
- import { Const } from '@basemaps/shared';
2
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
3
- export class Router {
4
- constructor() {
5
- this.handlers = {};
6
- }
7
- static action(req) {
8
- const path = req.path;
9
- const [version, name, ...rest] = (path[0] === '/' ? path.slice(1) : path)
10
- .split('/')
11
- .map((c) => decodeURIComponent(c));
12
- if (name == null)
13
- return { version: 'v1', name: version, rest: [] };
14
- return { version, name: name, rest };
15
- }
16
- static apiKey(req) {
17
- var _a;
18
- const apiKey = (_a = req.query.get(Const.ApiKey.QueryString)) !== null && _a !== void 0 ? _a : req.header('X-LINZ-Api-Key');
19
- if (apiKey != null && !Array.isArray(apiKey)) {
20
- req.set(Const.ApiKey.QueryString, this.apiKey);
21
- return apiKey;
22
- }
23
- return;
24
- }
25
- async handle(req) {
26
- // Allow cross origin requests
27
- if (req.method === 'options') {
28
- return new LambdaHttpResponse(200, 'Options', {
29
- [HttpHeader.Cors]: '*',
30
- 'Access-Control-Allow-Credentials': 'false',
31
- 'Access-Control-Allow-Methods': 'OPTIONS,GET,PUT,POST,DELETE',
32
- });
33
- }
34
- if (req.method !== 'GET')
35
- return new LambdaHttpResponse(405, 'Method not allowed');
36
- const action = Router.action(req);
37
- const handler = action.version === 'v1' ? this.handlers[action.name] : null;
38
- if (handler == null)
39
- return new LambdaHttpResponse(404, 'Not Found');
40
- const response = await handler(req);
41
- response.header(HttpHeader.Cors, '*');
42
- return response;
43
- }
44
- get(path, handler) {
45
- if (this.handlers[path] != null)
46
- throw new Error(path + ' already registered');
47
- this.handlers[path] = handler;
48
- }
49
- }
@@ -1,5 +0,0 @@
1
- import { LambdaHttpResponse } from '@linzjs/lambda';
2
- export declare function Health(): Promise<LambdaHttpResponse>;
3
- export declare function Ping(): Promise<LambdaHttpResponse>;
4
- export declare function Version(): Promise<LambdaHttpResponse>;
5
- //# sourceMappingURL=api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/routes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAc,MAAM,gBAAgB,CAAC;AAKhE,wBAAsB,MAAM,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAE1D;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAExD;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAK3D"}
@@ -1,16 +0,0 @@
1
- import { LambdaHttpResponse, HttpHeader } from '@linzjs/lambda';
2
- const OkResponse = new LambdaHttpResponse(200, 'ok');
3
- OkResponse.header(HttpHeader.CacheControl, 'no-store');
4
- export async function Health() {
5
- return OkResponse;
6
- }
7
- export async function Ping() {
8
- return OkResponse;
9
- }
10
- export async function Version() {
11
- var _a;
12
- const response = new LambdaHttpResponse(200, 'ok');
13
- response.header(HttpHeader.CacheControl, 'no-store');
14
- response.json({ version: (_a = process.env.GIT_VERSION) !== null && _a !== void 0 ? _a : 'dev', hash: process.env.GIT_HASH });
15
- return response;
16
- }
@@ -1,10 +0,0 @@
1
- import { TileMatrixSet } from '@basemaps/geo';
2
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
3
- export declare function vectorTileServer(req: LambdaHttpRequest, layerId: string, tms: TileMatrixSet): Promise<LambdaHttpResponse>;
4
- /**
5
- * /v1/esri/services/:layerId/VectorTileServer
6
- *
7
- * @example http://localhost:5000/v1/esri/services/topographic/VectorTileServer
8
- */
9
- export declare function Esri(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
10
- //# sourceMappingURL=rest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../../src/routes/esri/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKvE,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC,kBAAkB,CAAC,CAiD7B;AAED;;;;GAIG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsB9E"}