@basemaps/lambda-tiler 7.16.0 → 8.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/__tests__/index.test.js +24 -2
  3. package/build/__tests__/index.test.js.map +1 -1
  4. package/build/routes/version.d.ts +2 -2
  5. package/build/routes/version.js +17 -1
  6. package/build/routes/version.js.map +1 -1
  7. package/build/util/__test__/validate.test.js +15 -0
  8. package/build/util/__test__/validate.test.js.map +1 -1
  9. package/build/util/validate.d.ts +2 -0
  10. package/build/util/validate.js +15 -1
  11. package/build/util/validate.js.map +1 -1
  12. package/dist/index.js +56116 -51565
  13. package/dist/node_modules/.package-lock.json +7 -7
  14. package/dist/node_modules/detect-libc/package.json +3 -2
  15. package/dist/node_modules/semver/bin/semver.js +2 -0
  16. package/dist/node_modules/semver/classes/comparator.js +2 -0
  17. package/dist/node_modules/semver/classes/index.js +2 -0
  18. package/dist/node_modules/semver/classes/range.js +2 -0
  19. package/dist/node_modules/semver/classes/semver.js +4 -3
  20. package/dist/node_modules/semver/functions/clean.js +2 -0
  21. package/dist/node_modules/semver/functions/cmp.js +2 -0
  22. package/dist/node_modules/semver/functions/coerce.js +2 -0
  23. package/dist/node_modules/semver/functions/compare-build.js +2 -0
  24. package/dist/node_modules/semver/functions/compare-loose.js +2 -0
  25. package/dist/node_modules/semver/functions/compare.js +2 -0
  26. package/dist/node_modules/semver/functions/diff.js +2 -0
  27. package/dist/node_modules/semver/functions/eq.js +2 -0
  28. package/dist/node_modules/semver/functions/gt.js +2 -0
  29. package/dist/node_modules/semver/functions/gte.js +2 -0
  30. package/dist/node_modules/semver/functions/inc.js +2 -0
  31. package/dist/node_modules/semver/functions/lt.js +2 -0
  32. package/dist/node_modules/semver/functions/lte.js +2 -0
  33. package/dist/node_modules/semver/functions/major.js +2 -0
  34. package/dist/node_modules/semver/functions/minor.js +2 -0
  35. package/dist/node_modules/semver/functions/neq.js +2 -0
  36. package/dist/node_modules/semver/functions/parse.js +2 -0
  37. package/dist/node_modules/semver/functions/patch.js +2 -0
  38. package/dist/node_modules/semver/functions/prerelease.js +2 -0
  39. package/dist/node_modules/semver/functions/rcompare.js +2 -0
  40. package/dist/node_modules/semver/functions/rsort.js +2 -0
  41. package/dist/node_modules/semver/functions/satisfies.js +2 -0
  42. package/dist/node_modules/semver/functions/sort.js +2 -0
  43. package/dist/node_modules/semver/functions/valid.js +2 -0
  44. package/dist/node_modules/semver/index.js +2 -0
  45. package/dist/node_modules/semver/internal/constants.js +2 -0
  46. package/dist/node_modules/semver/internal/debug.js +2 -0
  47. package/dist/node_modules/semver/internal/identifiers.js +2 -0
  48. package/dist/node_modules/semver/internal/lrucache.js +2 -0
  49. package/dist/node_modules/semver/internal/parse-options.js +2 -0
  50. package/dist/node_modules/semver/internal/re.js +8 -4
  51. package/dist/node_modules/semver/package.json +3 -3
  52. package/dist/node_modules/semver/preload.js +2 -0
  53. package/dist/node_modules/semver/ranges/gtr.js +2 -0
  54. package/dist/node_modules/semver/ranges/intersects.js +2 -0
  55. package/dist/node_modules/semver/ranges/ltr.js +2 -0
  56. package/dist/node_modules/semver/ranges/max-satisfying.js +2 -0
  57. package/dist/node_modules/semver/ranges/min-satisfying.js +2 -0
  58. package/dist/node_modules/semver/ranges/min-version.js +2 -0
  59. package/dist/node_modules/semver/ranges/outside.js +2 -0
  60. package/dist/node_modules/semver/ranges/simplify.js +2 -0
  61. package/dist/node_modules/semver/ranges/subset.js +2 -0
  62. package/dist/node_modules/semver/ranges/to-comparators.js +2 -0
  63. package/dist/node_modules/semver/ranges/valid.js +2 -0
  64. package/dist/package-lock.json +8 -8
  65. package/dist/package.json +1 -1
  66. package/package.json +10 -10
  67. package/src/__tests__/index.test.ts +30 -2
  68. package/src/routes/version.ts +22 -2
  69. package/src/util/__test__/validate.test.ts +18 -0
  70. package/src/util/validate.ts +18 -1
  71. package/tsconfig.tsbuildinfo +1 -1
@@ -1,6 +1,16 @@
1
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
1
+ import { BasemapsConfigProvider, ConfigProviderMemory } from '@basemaps/config';
2
+ import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
3
 
3
- export function versionGet(): Promise<LambdaHttpResponse> {
4
+ import { ConfigLoader } from '../util/config.loader.js';
5
+
6
+ function getConfigHash(cfg: BasemapsConfigProvider): { id: string; hash?: string } | undefined {
7
+ if (!ConfigProviderMemory.is(cfg)) return undefined;
8
+ if (cfg.id == null) return undefined;
9
+ return { id: cfg.id, hash: cfg.hash };
10
+ }
11
+
12
+ export async function versionGet(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
13
+ const config = await ConfigLoader.load(req);
4
14
  const response = new LambdaHttpResponse(200, 'ok');
5
15
  response.header(HttpHeader.CacheControl, 'no-store');
6
16
  response.json({
@@ -9,16 +19,26 @@ export function versionGet(): Promise<LambdaHttpResponse> {
9
19
  * @example "v6.42.1"
10
20
  */
11
21
  version: process.env['GIT_VERSION'] ?? 'dev',
22
+
12
23
  /**
13
24
  * Full git commit hash
14
25
  * @example "e4231b1ee62c276c8657c56677ced02681dfe5d6"
15
26
  */
16
27
  hash: process.env['GIT_HASH'],
28
+
17
29
  /**
30
+ *
18
31
  * The exact build that this release was run from
19
32
  * @example "1658821493-3"
20
33
  */
21
34
  buildId: process.env['BUILD_ID'],
35
+
36
+ /**
37
+ * Configuration id that was used to power this config
38
+ * @example { "id": "cb_01JTQ7ZK49F8EY4N5DRJ3XFT73", hash: "HcByZ8WS2zpaTxFJp6wSKg2eUpwahLqAGEQdcDxKxqp6" }
39
+ */
40
+ config: getConfigHash(config),
22
41
  });
42
+
23
43
  return Promise.resolve(response);
24
44
  }
@@ -6,6 +6,24 @@ import { GoogleTms, Nztm2000QuadTms, Nztm2000Tms } from '@basemaps/geo';
6
6
  import { mockUrlRequest } from '../../__tests__/xyz.util.js';
7
7
  import { Validate } from '../validate.js';
8
8
 
9
+ describe('Validate.blockedApiKeys', () => {
10
+ const validApiKey = 'c01jswmpe1yn3mwne7e0ggtp8vg';
11
+ it('should disable api keys', () => {
12
+ const req = mockUrlRequest('/v1/blank', `api=${validApiKey}`);
13
+ const parsedKey = Validate.apiKey(req);
14
+ assert.equal(parsedKey, validApiKey);
15
+ });
16
+
17
+ it('should disable api keys', () => {
18
+ const req = mockUrlRequest('/v1/blank', `api=${validApiKey}`);
19
+ Validate.blockedApiKeys.add(validApiKey);
20
+ assert.throws(() => Validate.apiKey(req));
21
+
22
+ Validate.blockedApiKeys.delete(validApiKey);
23
+ assert.equal(Validate.apiKey(req), validApiKey);
24
+ });
25
+ });
26
+
9
27
  describe('GetImageFormats', () => {
10
28
  it('should parse all formats', () => {
11
29
  const req = mockUrlRequest('/v1/blank', 'format=png&format=jpeg');
@@ -1,6 +1,6 @@
1
1
  import { ConfigTileSetRaster, ConfigTileSetRasterOutput } from '@basemaps/config';
2
2
  import { ImageFormat, LatLon, Projection, TileMatrixSet, TileMatrixSets } from '@basemaps/geo';
3
- import { Const, isValidApiKey, truncateApiKey } from '@basemaps/shared';
3
+ import { Const, Env, isValidApiKey, LogConfig, truncateApiKey } from '@basemaps/shared';
4
4
  import { getImageFormat } from '@basemaps/tiler';
5
5
  import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
6
6
 
@@ -23,7 +23,19 @@ export interface TileMatrixRequest {
23
23
  Params: { tileMatrix?: string };
24
24
  }
25
25
 
26
+ function getBlockedApiKeys(): string[] {
27
+ try {
28
+ return JSON.parse(Env.get(Env.BlockedApiKeys) ?? '[]') as string[];
29
+ } catch (e) {
30
+ LogConfig.get().error(`"$${Env.BlockedApiKeys}" is invalid`);
31
+ return [];
32
+ }
33
+ }
34
+
26
35
  export const Validate = {
36
+ /** list of API Keys that have been disabled */
37
+ blockedApiKeys: new Set<string>(getBlockedApiKeys()),
38
+
27
39
  /**
28
40
  * Validate that the api key exists and is valid
29
41
  *
@@ -36,6 +48,11 @@ export const Validate = {
36
48
  if (!valid.valid) throw new LambdaHttpResponse(400, 'API Key Invalid: ' + valid.message);
37
49
  // Truncate the API Key so we are not logging the full key
38
50
  req.set('api', truncateApiKey(apiKey));
51
+
52
+ if (this.blockedApiKeys.has(apiKey as string)) {
53
+ throw new LambdaHttpResponse(429, 'Too many requests! Please contact basemaps@linz.govt.nz for a developer key');
54
+ }
55
+
39
56
  return apiKey as string;
40
57
  },
41
58