@defra/forms-engine-plugin 4.14.3 → 4.15.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/.public/assets-manifest.json +10 -1
- package/.public/javascripts/im-search-plugin.min.js +2 -0
- package/.public/javascripts/im-search-plugin.min.js.map +1 -0
- package/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.public/javascripts/vendor/@defra.min.js +2 -0
- package/.public/javascripts/vendor/@defra.min.js.map +1 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js +3 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js.LICENSE.txt +4 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js.map +1 -0
- package/.public/javascripts/vendor/preact.min.js +2 -0
- package/.public/javascripts/vendor/preact.min.js.map +1 -0
- package/.public/stylesheets/application.min.css +1 -1
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/javascripts/geospatial-map.js +9 -4
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/map.js +18 -12
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/client/stylesheets/shared.scss +7 -0
- package/.server/server/plugins/engine/components/TelephoneNumberField.js +2 -4
- package/.server/server/plugins/engine/components/TelephoneNumberField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/telephone.d.ts +0 -4
- package/.server/server/plugins/engine/components/helpers/telephone.js +6 -20
- package/.server/server/plugins/engine/components/helpers/telephone.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/telephone.test.js +5 -5
- package/.server/server/plugins/engine/components/helpers/telephone.test.js.map +1 -1
- package/.server/server/plugins/map/routes/index.d.ts +1 -2
- package/.server/server/plugins/map/routes/index.js +2 -32
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/.server/server/plugins/map/service.d.ts +0 -7
- package/.server/server/plugins/map/service.js +0 -12
- package/.server/server/plugins/map/service.js.map +1 -1
- package/.server/server/plugins/map/service.test.js +0 -43
- package/.server/server/plugins/map/service.test.js.map +1 -1
- package/package.json +2 -1
- package/src/client/javascripts/geospatial-map.js +9 -5
- package/src/client/javascripts/map.js +18 -13
- package/src/client/stylesheets/shared.scss +7 -0
- package/src/server/plugins/engine/components/TelephoneNumberField.ts +1 -5
- package/src/server/plugins/engine/components/helpers/telephone.ts +11 -35
- package/src/server/plugins/map/routes/index.js +1 -37
- package/src/server/plugins/map/service.js +0 -13
- package/.server/server/plugins/map/test/__stubs__/nearest.d.ts +0 -37
- package/.server/server/plugins/map/test/__stubs__/nearest.js +0 -38
- package/.server/server/plugins/map/test/__stubs__/nearest.js.map +0 -1
- package/src/server/plugins/map/test/__stubs__/nearest.js +0 -46
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { TelephoneNumberFieldOptionsFormatEnum } from '@defra/forms-model';
|
|
2
1
|
import LibPhoneNumber from 'google-libphonenumber';
|
|
3
2
|
import JoiBase from 'joi';
|
|
4
3
|
export declare const COUNTRY = "GB";
|
|
5
4
|
export declare const INVALID_ERROR_CODE = "phoneNumber.invalid";
|
|
6
|
-
export declare const UK_ERROR_CODE = "phoneNumber.uk";
|
|
7
|
-
export declare const INTERNATIONAL_ERROR_CODE = "phoneNumber.international";
|
|
8
5
|
export declare const isUKNumber: (value: LibPhoneNumber.PhoneNumber) => boolean;
|
|
9
|
-
export declare function getErrorCode(format?: TelephoneNumberFieldOptionsFormatEnum): "phoneNumber.invalid" | "phoneNumber.uk" | "phoneNumber.international";
|
|
10
6
|
export declare const joi: JoiBase.Root;
|
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
import { TelephoneNumberFieldOptionsFormatEnum } from '@defra/forms-model';
|
|
2
2
|
import LibPhoneNumber from 'google-libphonenumber';
|
|
3
3
|
import JoiBase from 'joi';
|
|
4
|
-
import {
|
|
4
|
+
import { messageTemplate } from "../../pageControllers/validationOptions.js";
|
|
5
5
|
const phoneUtil = LibPhoneNumber.PhoneNumberUtil.getInstance();
|
|
6
6
|
export const COUNTRY = 'GB';
|
|
7
7
|
export const INVALID_ERROR_CODE = 'phoneNumber.invalid';
|
|
8
|
-
export const UK_ERROR_CODE = 'phoneNumber.uk';
|
|
9
|
-
export const INTERNATIONAL_ERROR_CODE = 'phoneNumber.international';
|
|
10
8
|
export const isUKNumber = value => {
|
|
11
9
|
return phoneUtil.isValidNumberForRegion(value, COUNTRY);
|
|
12
10
|
};
|
|
13
|
-
export function getErrorCode(format) {
|
|
14
|
-
if (format === TelephoneNumberFieldOptionsFormatEnum.UK) {
|
|
15
|
-
return UK_ERROR_CODE;
|
|
16
|
-
} else if (format === TelephoneNumberFieldOptionsFormatEnum.International) {
|
|
17
|
-
return INTERNATIONAL_ERROR_CODE;
|
|
18
|
-
}
|
|
19
|
-
return INVALID_ERROR_CODE;
|
|
20
|
-
}
|
|
21
11
|
export const joi = JoiBase.extend({
|
|
22
12
|
type: 'string',
|
|
23
13
|
base: JoiBase.string(),
|
|
24
14
|
messages: {
|
|
25
|
-
[INVALID_ERROR_CODE]:
|
|
26
|
-
[UK_ERROR_CODE]: JoiBase.expression('Enter {{lowerFirst(#label)}}, like 01632 960 001, 07700 900 982 or +44 808 157 0192', opts),
|
|
27
|
-
[INTERNATIONAL_ERROR_CODE]: JoiBase.expression('Enter {{lowerFirst(#label)}}, starting with + and the country code, for example +92333 1234567 or 00923331234567', opts)
|
|
15
|
+
[INVALID_ERROR_CODE]: messageTemplate.format
|
|
28
16
|
},
|
|
29
17
|
rules: {
|
|
30
18
|
phoneNumber: {
|
|
@@ -50,19 +38,17 @@ export const joi = JoiBase.extend({
|
|
|
50
38
|
try {
|
|
51
39
|
const parsed = phoneUtil.parse(value, COUNTRY);
|
|
52
40
|
if (!phoneUtil.isValidNumber(parsed)) {
|
|
53
|
-
return error(
|
|
41
|
+
return error(INVALID_ERROR_CODE);
|
|
54
42
|
}
|
|
55
43
|
if (format) {
|
|
56
44
|
const isUK = isUKNumber(parsed);
|
|
57
|
-
if (!isUK && format === TelephoneNumberFieldOptionsFormatEnum.UK) {
|
|
58
|
-
return error(
|
|
59
|
-
} else if (isUK && format === TelephoneNumberFieldOptionsFormatEnum.International) {
|
|
60
|
-
return error(INTERNATIONAL_ERROR_CODE);
|
|
45
|
+
if (!isUK && format === TelephoneNumberFieldOptionsFormatEnum.UK || isUK && format === TelephoneNumberFieldOptionsFormatEnum.International) {
|
|
46
|
+
return error(INVALID_ERROR_CODE);
|
|
61
47
|
}
|
|
62
48
|
}
|
|
63
49
|
return value;
|
|
64
50
|
} catch {
|
|
65
|
-
return error(
|
|
51
|
+
return error(INVALID_ERROR_CODE);
|
|
66
52
|
}
|
|
67
53
|
}
|
|
68
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telephone.js","names":["TelephoneNumberFieldOptionsFormatEnum","LibPhoneNumber","JoiBase","
|
|
1
|
+
{"version":3,"file":"telephone.js","names":["TelephoneNumberFieldOptionsFormatEnum","LibPhoneNumber","JoiBase","messageTemplate","phoneUtil","PhoneNumberUtil","getInstance","COUNTRY","INVALID_ERROR_CODE","isUKNumber","value","isValidNumberForRegion","joi","extend","type","base","string","messages","format","rules","phoneNumber","method","$_addRule","name","args","ref","assert","valid","International","UK","validate","error","parsed","parse","isValidNumber","isUK"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/telephone.ts"],"sourcesContent":["import { TelephoneNumberFieldOptionsFormatEnum } from '@defra/forms-model'\nimport LibPhoneNumber from 'google-libphonenumber'\nimport JoiBase, { type LanguageMessages } from 'joi'\n\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\n\nconst phoneUtil = LibPhoneNumber.PhoneNumberUtil.getInstance()\n\nexport const COUNTRY = 'GB'\nexport const INVALID_ERROR_CODE = 'phoneNumber.invalid'\n\nexport const isUKNumber = (value: LibPhoneNumber.PhoneNumber) => {\n return phoneUtil.isValidNumberForRegion(value, COUNTRY)\n}\n\nexport const joi = JoiBase.extend({\n type: 'string',\n base: JoiBase.string(),\n messages: {\n [INVALID_ERROR_CODE]: messageTemplate.format\n } as LanguageMessages,\n rules: {\n phoneNumber: {\n method({\n format\n }: { format?: TelephoneNumberFieldOptionsFormatEnum } = {}) {\n return this.$_addRule({\n name: 'phoneNumber',\n args: { format }\n })\n },\n args: [\n {\n name: 'format',\n ref: true,\n assert: JoiBase.valid(\n TelephoneNumberFieldOptionsFormatEnum.International,\n TelephoneNumberFieldOptionsFormatEnum.UK\n )\n }\n ],\n validate(value, { error }, args) {\n const format = args.format\n\n try {\n const parsed = phoneUtil.parse(value, COUNTRY)\n\n if (!phoneUtil.isValidNumber(parsed)) {\n return error(INVALID_ERROR_CODE)\n }\n\n if (format) {\n const isUK = isUKNumber(parsed)\n\n if (\n (!isUK && format === TelephoneNumberFieldOptionsFormatEnum.UK) ||\n (isUK &&\n format === TelephoneNumberFieldOptionsFormatEnum.International)\n ) {\n return error(INVALID_ERROR_CODE)\n }\n }\n\n return value\n } catch {\n return error(INVALID_ERROR_CODE)\n }\n }\n }\n }\n}) as JoiBase.Root\n"],"mappings":"AAAA,SAASA,qCAAqC,QAAQ,oBAAoB;AAC1E,OAAOC,cAAc,MAAM,uBAAuB;AAClD,OAAOC,OAAO,MAAiC,KAAK;AAEpD,SAASC,eAAe;AAExB,MAAMC,SAAS,GAAGH,cAAc,CAACI,eAAe,CAACC,WAAW,CAAC,CAAC;AAE9D,OAAO,MAAMC,OAAO,GAAG,IAAI;AAC3B,OAAO,MAAMC,kBAAkB,GAAG,qBAAqB;AAEvD,OAAO,MAAMC,UAAU,GAAIC,KAAiC,IAAK;EAC/D,OAAON,SAAS,CAACO,sBAAsB,CAACD,KAAK,EAAEH,OAAO,CAAC;AACzD,CAAC;AAED,OAAO,MAAMK,GAAG,GAAGV,OAAO,CAACW,MAAM,CAAC;EAChCC,IAAI,EAAE,QAAQ;EACdC,IAAI,EAAEb,OAAO,CAACc,MAAM,CAAC,CAAC;EACtBC,QAAQ,EAAE;IACR,CAACT,kBAAkB,GAAGL,eAAe,CAACe;EACxC,CAAqB;EACrBC,KAAK,EAAE;IACLC,WAAW,EAAE;MACXC,MAAMA,CAAC;QACLH;MACkD,CAAC,GAAG,CAAC,CAAC,EAAE;QAC1D,OAAO,IAAI,CAACI,SAAS,CAAC;UACpBC,IAAI,EAAE,aAAa;UACnBC,IAAI,EAAE;YAAEN;UAAO;QACjB,CAAC,CAAC;MACJ,CAAC;MACDM,IAAI,EAAE,CACJ;QACED,IAAI,EAAE,QAAQ;QACdE,GAAG,EAAE,IAAI;QACTC,MAAM,EAAExB,OAAO,CAACyB,KAAK,CACnB3B,qCAAqC,CAAC4B,aAAa,EACnD5B,qCAAqC,CAAC6B,EACxC;MACF,CAAC,CACF;MACDC,QAAQA,CAACpB,KAAK,EAAE;QAAEqB;MAAM,CAAC,EAAEP,IAAI,EAAE;QAC/B,MAAMN,MAAM,GAAGM,IAAI,CAACN,MAAM;QAE1B,IAAI;UACF,MAAMc,MAAM,GAAG5B,SAAS,CAAC6B,KAAK,CAACvB,KAAK,EAAEH,OAAO,CAAC;UAE9C,IAAI,CAACH,SAAS,CAAC8B,aAAa,CAACF,MAAM,CAAC,EAAE;YACpC,OAAOD,KAAK,CAACvB,kBAAkB,CAAC;UAClC;UAEA,IAAIU,MAAM,EAAE;YACV,MAAMiB,IAAI,GAAG1B,UAAU,CAACuB,MAAM,CAAC;YAE/B,IACG,CAACG,IAAI,IAAIjB,MAAM,KAAKlB,qCAAqC,CAAC6B,EAAE,IAC5DM,IAAI,IACHjB,MAAM,KAAKlB,qCAAqC,CAAC4B,aAAc,EACjE;cACA,OAAOG,KAAK,CAACvB,kBAAkB,CAAC;YAClC;UACF;UAEA,OAAOE,KAAK;QACd,CAAC,CAAC,MAAM;UACN,OAAOqB,KAAK,CAACvB,kBAAkB,CAAC;QAClC;MACF;IACF;EACF;AACF,CAAC,CAAiB","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ describe('Telephone validation helpers', () => {
|
|
|
24
24
|
}).label('Home phone');
|
|
25
25
|
const result = telephoneSchema.validate('ABC');
|
|
26
26
|
expect(result.error).toBeDefined();
|
|
27
|
-
expect(result.error?.message).toBe('Enter home phone
|
|
27
|
+
expect(result.error?.message).toBe('Enter home phone in the correct format');
|
|
28
28
|
expect(result.value).toBe('ABC');
|
|
29
29
|
});
|
|
30
30
|
test('it should have errors for international telephone number', () => {
|
|
@@ -33,7 +33,7 @@ describe('Telephone validation helpers', () => {
|
|
|
33
33
|
}).label('Home phone');
|
|
34
34
|
const result = telephoneSchema.validate('+1-212-456-7890');
|
|
35
35
|
expect(result.error).toBeDefined();
|
|
36
|
-
expect(result.error?.message).toBe('Enter home phone
|
|
36
|
+
expect(result.error?.message).toBe('Enter home phone in the correct format');
|
|
37
37
|
expect(result.value).toBe('+1-212-456-7890');
|
|
38
38
|
});
|
|
39
39
|
});
|
|
@@ -52,7 +52,7 @@ describe('Telephone validation helpers', () => {
|
|
|
52
52
|
}).label('Home phone');
|
|
53
53
|
const result = telephoneSchema.validate('ABC');
|
|
54
54
|
expect(result.error).toBeDefined();
|
|
55
|
-
expect(result.error?.message).toBe('Enter home phone
|
|
55
|
+
expect(result.error?.message).toBe('Enter home phone in the correct format');
|
|
56
56
|
expect(result.value).toBe('ABC');
|
|
57
57
|
});
|
|
58
58
|
test('it should have errors for UK phone number in international format', () => {
|
|
@@ -61,7 +61,7 @@ describe('Telephone validation helpers', () => {
|
|
|
61
61
|
}).label('Home phone');
|
|
62
62
|
const result = telephoneSchema.validate('+44 1606 76477');
|
|
63
63
|
expect(result.error).toBeDefined();
|
|
64
|
-
expect(result.error?.message).toBe('Enter home phone
|
|
64
|
+
expect(result.error?.message).toBe('Enter home phone in the correct format');
|
|
65
65
|
expect(result.value).toBe('+44 1606 76477');
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -82,7 +82,7 @@ describe('Telephone validation helpers', () => {
|
|
|
82
82
|
const telephoneSchema = joi.string().phoneNumber().label('Home phone');
|
|
83
83
|
const result = telephoneSchema.validate('ABC');
|
|
84
84
|
expect(result.error).toBeDefined();
|
|
85
|
-
expect(result.error?.message).toBe('Enter home phone
|
|
85
|
+
expect(result.error?.message).toBe('Enter home phone in the correct format');
|
|
86
86
|
expect(result.value).toBe('ABC');
|
|
87
87
|
});
|
|
88
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telephone.test.js","names":["TelephoneNumberFieldOptionsFormatEnum","joi","describe","test","telephoneSchema","string","phoneNumber","format","UK","label","result","validate","expect","error","toBeUndefined","value","toBe","toBeDefined","message","International"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/telephone.test.js"],"sourcesContent":["import { TelephoneNumberFieldOptionsFormatEnum } from '@defra/forms-model'\n\nimport { joi } from '~/src/server/plugins/engine/components/helpers/telephone.js'\n\ndescribe('Telephone validation helpers', () => {\n describe('UK numbers', () => {\n test('it should not have errors for valid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('0160676477')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('0160676477')\n })\n\n test('it should not have errors for valid UK telephone number in international format', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('+44 1606 76477')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('+44 1606 76477')\n })\n\n test('it should have errors for invalid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('ABC')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone
|
|
1
|
+
{"version":3,"file":"telephone.test.js","names":["TelephoneNumberFieldOptionsFormatEnum","joi","describe","test","telephoneSchema","string","phoneNumber","format","UK","label","result","validate","expect","error","toBeUndefined","value","toBe","toBeDefined","message","International"],"sources":["../../../../../../src/server/plugins/engine/components/helpers/telephone.test.js"],"sourcesContent":["import { TelephoneNumberFieldOptionsFormatEnum } from '@defra/forms-model'\n\nimport { joi } from '~/src/server/plugins/engine/components/helpers/telephone.js'\n\ndescribe('Telephone validation helpers', () => {\n describe('UK numbers', () => {\n test('it should not have errors for valid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('0160676477')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('0160676477')\n })\n\n test('it should not have errors for valid UK telephone number in international format', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('+44 1606 76477')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('+44 1606 76477')\n })\n\n test('it should have errors for invalid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('ABC')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone in the correct format'\n )\n expect(result.value).toBe('ABC')\n })\n\n test('it should have errors for international telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({ format: TelephoneNumberFieldOptionsFormatEnum.UK })\n .label('Home phone')\n\n const result = telephoneSchema.validate('+1-212-456-7890')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone in the correct format'\n )\n expect(result.value).toBe('+1-212-456-7890')\n })\n })\n\n describe('International numbers', () => {\n test('it should not have errors for valid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({\n format: TelephoneNumberFieldOptionsFormatEnum.International\n })\n .label('Home phone')\n\n const result = telephoneSchema.validate('+1-212-456-7890')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('+1-212-456-7890')\n })\n\n test('it should have errors for invalid telephone number', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({\n format: TelephoneNumberFieldOptionsFormatEnum.International\n })\n .label('Home phone')\n\n const result = telephoneSchema.validate('ABC')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone in the correct format'\n )\n expect(result.value).toBe('ABC')\n })\n\n test('it should have errors for UK phone number in international format', () => {\n const telephoneSchema = joi\n .string()\n .phoneNumber({\n format: TelephoneNumberFieldOptionsFormatEnum.International\n })\n .label('Home phone')\n\n const result = telephoneSchema.validate('+44 1606 76477')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone in the correct format'\n )\n expect(result.value).toBe('+44 1606 76477')\n })\n })\n\n describe('Any format', () => {\n test('it should not have errors for valid national telephone number', () => {\n const telephoneSchema = joi.string().phoneNumber().label('Home phone')\n\n const result = telephoneSchema.validate('0160676477')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('0160676477')\n })\n\n test('it should not have errors for valid international telephone number', () => {\n const telephoneSchema = joi.string().phoneNumber().label('Home phone')\n\n const result = telephoneSchema.validate('+1-212-456-7890')\n\n expect(result.error).toBeUndefined()\n expect(result.value).toBe('+1-212-456-7890')\n })\n\n test('it should have errors for invalid telephone number', () => {\n const telephoneSchema = joi.string().phoneNumber().label('Home phone')\n\n const result = telephoneSchema.validate('ABC')\n\n expect(result.error).toBeDefined()\n expect(result.error?.message).toBe(\n 'Enter home phone in the correct format'\n )\n expect(result.value).toBe('ABC')\n })\n })\n})\n"],"mappings":"AAAA,SAASA,qCAAqC,QAAQ,oBAAoB;AAE1E,SAASC,GAAG;AAEZC,QAAQ,CAAC,8BAA8B,EAAE,MAAM;EAC7CA,QAAQ,CAAC,YAAY,EAAE,MAAM;IAC3BC,IAAI,CAAC,sDAAsD,EAAE,MAAM;MACjE,MAAMC,eAAe,GAAGH,GAAG,CACxBI,MAAM,CAAC,CAAC,CACRC,WAAW,C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AC,YAAY,CAAC;IACzC,CAAC,CAAC;IAEFb,IAAI,CAAC,oEAAoE,EAAE,MAAM;MAC/E,MAAMC,eAAe,GAAGH,GAAG,CAACI,MAAM,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAACG,KAAK,CAAC,YAAY,CAAC;MAEtE,MAAMC,MAAM,GAAGN,eAAe,CAACO,QAAQ,CAAC,iBAAiB,CAAC;MAE1DC,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACC,aAAa,CAAC,CAAC;MACpCF,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACC,IAAI,CAAC,iBAAiB,CAAC;IAC9C,CAAC,CAAC;IAEFb,IAAI,CAAC,oDAAoD,EAAE,MAAM;MAC/D,MAAMC,eAAe,GAAGH,GAAG,CAACI,MAAM,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAACG,KAAK,CAAC,YAAY,CAAC;MAEtE,MAAMC,MAAM,GAAGN,eAAe,CAACO,QAAQ,CAAC,KAAK,CAAC;MAE9CC,MAAM,CAACF,MAAM,CAACG,KAAK,CAAC,CAACI,WAAW,CAAC,CAAC;MAClCL,MAAM,CAACF,MAAM,CAACG,KAAK,EAAEK,OAAO,CAAC,CAACF,IAAI,CAChC,wCACF,CAAC;MACDJ,MAAM,CAACF,MAAM,CAACK,KAAK,CAAC,CAACC,IAAI,CAAC,KAAK,CAAC;IAClC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Gets the map support routes
|
|
3
3
|
* @param {MapConfiguration} options - ordnance survey names api key
|
|
4
4
|
*/
|
|
5
|
-
export function getRoutes(options: MapConfiguration): (ServerRoute<MapProxyGetRequestRefs> | ServerRoute<MapGeocodeGetRequestRefs> | ServerRoute<
|
|
5
|
+
export function getRoutes(options: MapConfiguration): (ServerRoute<MapProxyGetRequestRefs> | ServerRoute<MapGeocodeGetRequestRefs> | ServerRoute<GeospatialCountriesGetRequestRefs>)[];
|
|
6
6
|
/**
|
|
7
7
|
* @type {FeatureCollection}
|
|
8
8
|
*/
|
|
@@ -12,7 +12,6 @@ import type { MapConfiguration } from '../../../../server/plugins/map/types.js';
|
|
|
12
12
|
import type { MapProxyGetRequestRefs } from '../../../../server/plugins/map/types.js';
|
|
13
13
|
import type { ServerRoute } from '@hapi/hapi';
|
|
14
14
|
import type { MapGeocodeGetRequestRefs } from '../../../../server/plugins/map/types.js';
|
|
15
|
-
import type { MapReverseGeocodeGetRequestRefs } from '../../../../server/plugins/map/types.js';
|
|
16
15
|
import type { GeospatialCountriesGetRequestRefs } from '../../../../server/plugins/map/types.js';
|
|
17
16
|
import type { FeatureCollection } from 'geojson';
|
|
18
17
|
import Joi from 'joi';
|
|
@@ -4,7 +4,7 @@ import { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model';
|
|
|
4
4
|
import { StatusCodes } from 'http-status-codes';
|
|
5
5
|
import Joi from 'joi';
|
|
6
6
|
import { getAccessToken } from "./get-os-token.js";
|
|
7
|
-
import { find
|
|
7
|
+
import { find } from "../service.js";
|
|
8
8
|
import { get, request as httpRequest } from "../../../services/httpService.js";
|
|
9
9
|
const filePath = resolve(import.meta.dirname, './vts/countries.geojson');
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ export const countrySchema = Joi.string().valid(...Object.values(GeospatialField
|
|
|
20
20
|
* @param {MapConfiguration} options - ordnance survey names api key
|
|
21
21
|
*/
|
|
22
22
|
export function getRoutes(options) {
|
|
23
|
-
return [mapStyleResourceRoutes(), mapProxyRoute(options), tileProxyRoute(options), geocodeProxyRoute(options),
|
|
23
|
+
return [mapStyleResourceRoutes(), mapProxyRoute(options), tileProxyRoute(options), geocodeProxyRoute(options), getGeospatialCountries()];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -134,36 +134,6 @@ function geocodeProxyRoute(options) {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
/**
|
|
138
|
-
* Proxies ordnance survey reverse geocode requests from the front end to api.os.uk
|
|
139
|
-
* Used to find name from easting and northing points.
|
|
140
|
-
* N.B this endpoint is currently not used by the front end but will be soon in "maps V2"
|
|
141
|
-
* @param {MapConfiguration} options - the map options
|
|
142
|
-
* @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}
|
|
143
|
-
*/
|
|
144
|
-
function reverseGeocodeProxyRoute(options) {
|
|
145
|
-
return {
|
|
146
|
-
method: 'GET',
|
|
147
|
-
path: '/api/reverse-geocode-proxy',
|
|
148
|
-
async handler(request, _h) {
|
|
149
|
-
const {
|
|
150
|
-
query
|
|
151
|
-
} = request;
|
|
152
|
-
const data = await nearest(query.easting, query.northing, options.ordnanceSurveyApiKey);
|
|
153
|
-
return data;
|
|
154
|
-
},
|
|
155
|
-
options: {
|
|
156
|
-
auth: false,
|
|
157
|
-
validate: {
|
|
158
|
-
query: Joi.object().keys({
|
|
159
|
-
easting: Joi.number().required(),
|
|
160
|
-
northing: Joi.number().required()
|
|
161
|
-
}).required()
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
137
|
/**
|
|
168
138
|
* Resource routes to return sprites and glyphs
|
|
169
139
|
* @returns {ServerRoute<MapProxyGetRequestRefs>}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","nearest","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","reverseGeocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","auth","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","easting","northing","number","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find, nearest } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n reverseGeocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n },\n options: {\n auth: false\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey reverse geocode requests from the front end to api.os.uk\n * Used to find name from easting and northing points.\n * N.B this endpoint is currently not used by the front end but will be soon in \"maps V2\"\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}\n */\nfunction reverseGeocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/reverse-geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await nearest(\n query.easting,\n query.northing,\n options.ordnanceSurveyApiKey\n )\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n easting: Joi.number().required(),\n northing: Joi.number().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n auth: false,\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SA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uE,IAAI;QAAEC;MAAK,CAAC,GAAGxE,OAAO,CAAC2B,KAAK;MAEpC,IAAI4C,IAAI,EAAE;QACR,OAAO;UACL,GAAGjE,SAAS;UACZmE,QAAQ,EAAEnE,SAAS,CAACmE,QAAQ,CAACC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,EAAE,KAAKL,IAAI;QACtE,CAAC;MACH;MAEA,IAAIC,IAAI,EAAE;QACR,OAAO;UACL,GAAGlE,SAAS;UACZmE,QAAQ,EAAEnE,SAAS,CAACmE,QAAQ,CAACC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,EAAE,KAAKJ,IAAI;QACtE,CAAC;MACH;MAEA,OAAOlE,SAAS;IAClB,CAAC;IACDU,OAAO,EAAE;MACP6B,IAAI,EAAE,KAAK;MACXC,QAAQ,EAAE;QACRnB,KAAK,EAAEhC,GAAG,CAACoD,MAAM,CAAC,CAAC,CAChBC,IAAI,CAAC;UACJuB,IAAI,EAAE7D,aAAa,CAACwC,QAAQ,CAAC,CAAC;UAC9BsB,IAAI,EAAE9D,aAAa,CAACwC,QAAQ,CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","auth","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n },\n options: {\n auth: false\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n auth: false,\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,cAAc;AACvB,SAASC,IAAI;AACb,SACEC,GAAG,EACHC,OAAO,IAAIC,WAAW;AAGxB,MAAMC,QAAQ,GAAGT,OAAO,CAACU,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE,yBAAyB,CAAC;;AAExE;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAAChB,EAAE,CAACiB,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEtE,OAAO,MAAMQ,aAAa,GAAGd,GAAG,CAACe,MAAM,CAAC,CAAC,CAACC,KAAK,CAC7C,GAAGC,MAAM,CAACC,MAAM,CAACpB,iCAAiC,CACpD,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASqB,SAASA,CAACC,OAAO,EAAE;EACjC,OAAO,CACLC,sBAAsB,CAAC,CAAC,EACxBC,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;UACZ+D,QAAQ,EAAE/D,SAAS,CAAC+D,QAAQ,CAACC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,EAAE,KAAKL,IAAI;QACtE,CAAC;MACH;MAEA,IAAIC,IAAI,EAAE;QACR,OAAO;UACL,GAAG9D,SAAS;UACZ+D,QAAQ,EAAE/D,SAAS,CAAC+D,QAAQ,CAACC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,EAAE,KAAKJ,IAAI;QACtE,CAAC;MACH;MAEA,OAAO9D,SAAS;IAClB,CAAC;IACDU,OAAO,EAAE;MACP4B,IAAI,EAAE,KAAK;MACXC,QAAQ,EAAE;QACRnB,KAAK,EAAE9B,GAAG,CAACkD,MAAM,CAAC,CAAC,CAChBC,IAAI,CAAC;UACJoB,IAAI,EAAEzD,aAAa,CAACuC,QAAQ,CAAC,CAAC;UAC9BmB,IAAI,EAAE1D,aAAa,CAACuC,QAAQ,CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -4,11 +4,4 @@
|
|
|
4
4
|
* @param {string} apiKey - the OS api key
|
|
5
5
|
*/
|
|
6
6
|
export function find(query: string, apiKey: string): Promise<OsNamesFindResponse>;
|
|
7
|
-
/**
|
|
8
|
-
* OS names search nearest by E/N
|
|
9
|
-
* @param {number} easting - the easting
|
|
10
|
-
* @param {number} northing - the northing
|
|
11
|
-
* @param {string} apiKey - the OS api key
|
|
12
|
-
*/
|
|
13
|
-
export function nearest(easting: number, northing: number, apiKey: string): Promise<OsNamesFindResponse>;
|
|
14
7
|
import type { OsNamesFindResponse } from '../../../server/plugins/map/types.js';
|
|
@@ -60,18 +60,6 @@ export async function find(query, apiKey) {
|
|
|
60
60
|
return getData(url, endpoint);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* OS names search nearest by E/N
|
|
65
|
-
* @param {number} easting - the easting
|
|
66
|
-
* @param {number} northing - the northing
|
|
67
|
-
* @param {string} apiKey - the OS api key
|
|
68
|
-
*/
|
|
69
|
-
export async function nearest(easting, northing, apiKey) {
|
|
70
|
-
const endpoint = 'nearest';
|
|
71
|
-
const url = `https://api.os.uk/search/names/v1/nearest?key=${apiKey}&point=${easting},${northing}&radius=1000&fq=local_type:Airfield%20local_type:Airport%20local_type:Bus_Station%20local_type:Chemical_Works%20local_type:City%20local_type:Coach_Station%20local_type:Electricity_Distribution%20local_type:Electricity_Production%20local_type:Further_Education%20local_type:Gas_Distribution_or_Storage%20local_type:Hamlet%20local_type:Harbour%20local_type:Helicopter_Station%20local_type:Heliport%20local_type:Higher_or_University_Education%20local_type:Hill_Or_Mountain%20local_type:Hospice%20local_type:Hospital%20local_type:Medical_Care_Accommodation%20local_type:Named_Road%20local_type:Non_State_Primary_Education%20local_type:Non_State_Secondary_Education%20local_type:Other_Settlement%20local_type:Passenger_Ferry_Terminal%20local_type:Port_Consisting_of_Docks_and_Nautical_Berthing%20local_type:Postcode%20local_type:Primary_Education%20local_type:Railway_Station%20local_type:Road_User_Services%20local_type:Secondary_Education%20local_type:Section_Of_Named_Road%20local_type:Section_Of_Numbered_Road%20local_type:Special_Needs_Education%20local_type:Suburban_Area%20local_type:Town%20local_type:Urban_Greenspace%20local_type:Vehicular_Ferry_Terminal%20local_type:Vehicular_Rail_Terminal%20local_type:Village%20local_type:Waterfall%20`;
|
|
72
|
-
return getData(url, endpoint);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
63
|
/**
|
|
76
64
|
* @import { OsNamesFindResponse, OsNamesFindResult } from '../../../server/plugins/map/types.js'
|
|
77
65
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":["getErrorMessage","Boom","logger","getJson","empty","results","header","logErrorAndReturnEmpty","err","endpoint","boomData","isBoom","data","msg","payload","error","message","getData","url","getJsonByType","response","find","query","apiKey"
|
|
1
|
+
{"version":3,"file":"service.js","names":["getErrorMessage","Boom","logger","getJson","empty","results","header","logErrorAndReturnEmpty","err","endpoint","boomData","isBoom","data","msg","payload","error","message","getData","url","getJsonByType","response","find","query","apiKey"],"sources":["../../../../src/server/plugins/map/service.js"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\nimport Boom from '@hapi/boom'\n\nimport { logger } from '~/src/server/common/helpers/logging/logger.js'\nimport { getJson } from '~/src/server/services/httpService.js'\n\n/**\n * Returns an empty result set\n */\nfunction empty() {\n /** @type {OsNamesFindResult[]} */\n const results = []\n\n return /** @type {OsNamesFindResponse} */ ({ header: {}, results })\n}\n\n/**\n * Logs OS names errors\n * @param {unknown} err - the error\n * @param {string} endpoint - the OS api endpoint\n */\nfunction logErrorAndReturnEmpty(err, endpoint) {\n /** @type {{ payload?: { error?: { message?: string } } } | false} */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const boomData = Boom.isBoom(err) && err.data\n const msg = `${getErrorMessage(err)} ${(boomData && boomData.payload?.error?.message) ?? ''}`\n\n logger.error(err, `Exception occured calling OS names ${endpoint} - ${msg}}`)\n\n return empty()\n}\n\n/**\n * Fetch data from OS names API\n * @param {string} url - the url to get address json data from\n * @param {string} endpoint - the url endpoint description for logging\n */\nasync function getData(url, endpoint) {\n const getJsonByType = /** @type {typeof getJson<OsNamesFindResponse>} */ (\n getJson\n )\n\n try {\n const response = await getJsonByType(url)\n\n if (response.error) {\n return logErrorAndReturnEmpty(response.error, endpoint)\n }\n\n const results = response.payload\n\n return results\n } catch (err) {\n return logErrorAndReturnEmpty(err, endpoint)\n }\n}\n\n/**\n * OS names search find by query\n * @param {string} query - the search term\n * @param {string} apiKey - the OS api key\n */\nexport async function find(query, apiKey) {\n const endpoint = 'find'\n const url = `https://api.os.uk/search/names/v1/find?key=${apiKey}&query=${query}&fq=local_type:postcode%20local_type:hamlet%20local_type:village%20local_type:town%20local_type:city%20local_type:other_settlement&maxresults=8`\n\n return getData(url, endpoint)\n}\n\n/**\n * @import { OsN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C9C;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeY,IAAIA,CAACC,KAAK,EAAEC,MAAM,EAAE;EACxC,MAAMd,QAAQ,GAAG,MAAM;EACvB,MAAMS,GAAG,GAAG,8CAA8CK,MAAM,UAAUD,KAAK,iJAAiJ;EAEhO,OAAOL,OAAO,CAACC,GAAG,EAAET,QAAQ,CAAC;AAC/B;;AAEA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Boom from '@hapi/boom';
|
|
2
2
|
import * as service from "./service.js";
|
|
3
3
|
import { result as findResult } from "./test/__stubs__/find.js";
|
|
4
|
-
import { result as nearestResult } from "./test/__stubs__/nearest.js";
|
|
5
4
|
import { getJson } from "../../services/httpService.js";
|
|
6
5
|
jest.mock("../../services/httpService.ts");
|
|
7
6
|
describe('Maps service', () => {
|
|
@@ -70,48 +69,6 @@ describe('Maps service', () => {
|
|
|
70
69
|
expect(results).toEqual([]);
|
|
71
70
|
});
|
|
72
71
|
});
|
|
73
|
-
describe('nearest', () => {
|
|
74
|
-
it('should return entries', async () => {
|
|
75
|
-
jest.mocked(getJson).mockResolvedValueOnce({
|
|
76
|
-
res: (/** @type {IncomingMessage} */{
|
|
77
|
-
statusCode: 200,
|
|
78
|
-
headers: {}
|
|
79
|
-
}),
|
|
80
|
-
payload: nearestResult,
|
|
81
|
-
error: undefined
|
|
82
|
-
});
|
|
83
|
-
const {
|
|
84
|
-
results
|
|
85
|
-
} = await service.nearest(700000, 1300000, 'apikey');
|
|
86
|
-
expect(results).toHaveLength(1);
|
|
87
|
-
expect(results.at(0)).toEqual({
|
|
88
|
-
GAZETTEER_ENTRY: {
|
|
89
|
-
ID: 'NW26XE',
|
|
90
|
-
NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',
|
|
91
|
-
NAME1: 'NW2 6XE',
|
|
92
|
-
TYPE: 'other',
|
|
93
|
-
LOCAL_TYPE: 'Postcode',
|
|
94
|
-
GEOMETRY_X: 523065,
|
|
95
|
-
GEOMETRY_Y: 185795,
|
|
96
|
-
MOST_DETAIL_VIEW_RES: 3500,
|
|
97
|
-
LEAST_DETAIL_VIEW_RES: 18000,
|
|
98
|
-
POPULATED_PLACE: 'London',
|
|
99
|
-
POPULATED_PLACE_URI: 'http://data.ordnancesurvey.co.uk/id/4000000074813508',
|
|
100
|
-
POPULATED_PLACE_TYPE: 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',
|
|
101
|
-
DISTRICT_BOROUGH: 'Brent',
|
|
102
|
-
DISTRICT_BOROUGH_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000011447',
|
|
103
|
-
DISTRICT_BOROUGH_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',
|
|
104
|
-
COUNTY_UNITARY: 'Greater London',
|
|
105
|
-
COUNTY_UNITARY_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041441',
|
|
106
|
-
COUNTY_UNITARY_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',
|
|
107
|
-
REGION: 'London',
|
|
108
|
-
REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',
|
|
109
|
-
COUNTRY: 'England',
|
|
110
|
-
COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
72
|
});
|
|
116
73
|
|
|
117
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.test.js","names":["Boom","service","result","findResult","
|
|
1
|
+
{"version":3,"file":"service.test.js","names":["Boom","service","result","findResult","getJson","jest","mock","describe","it","mocked","mockResolvedValueOnce","res","statusCode","headers","payload","error","undefined","results","find","expect","toHaveLength","at","toEqual","GAZETTEER_ENTRY","ID","NAMES_URI","NAME1","TYPE","LOCAL_TYPE","GEOMETRY_X","GEOMETRY_Y","MOST_DETAIL_VIEW_RES","LEAST_DETAIL_VIEW_RES","POPULATED_PLACE","POPULATED_PLACE_URI","POPULATED_PLACE_TYPE","DISTRICT_BOROUGH","DISTRICT_BOROUGH_URI","DISTRICT_BOROUGH_TYPE","COUNTY_UNITARY","COUNTY_UNITARY_URI","COUNTY_UNITARY_TYPE","REGION","REGION_URI","COUNTRY","COUNTRY_URI","Error","mockRejectedValueOnce","badRequest"],"sources":["../../../../src/server/plugins/map/service.test.js"],"sourcesContent":["import Boom from '@hapi/boom'\n\nimport * as service from '~/src/server/plugins/map/service.js'\nimport { result as findResult } from '~/src/server/plugins/map/test/__stubs__/find.js'\nimport { getJson } from '~/src/server/services/httpService.js'\n\njest.mock('~/src/server/services/httpService.ts')\n\ndescribe('Maps service', () => {\n describe('find', () => {\n it('should return entires', async () => {\n jest.mocked(getJson).mockResolvedValueOnce({\n res: /** @type {IncomingMessage} */ ({\n statusCode: 200,\n headers: {}\n }),\n payload: findResult,\n error: undefined\n })\n\n const { results } = await service.find('NW1 6XE', 'apikey')\n\n expect(results).toHaveLength(8)\n expect(results.at(1)).toEqual({\n GAZETTEER_ENTRY: {\n ID: 'NW26XE',\n NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',\n NAME1: 'NW2 6XE',\n TYPE: 'other',\n LOCAL_TYPE: 'Postcode',\n GEOMETRY_X: 523065,\n GEOMETRY_Y: 185795,\n MOST_DETAIL_VIEW_RES: 3500,\n LEAST_DETAIL_VIEW_RES: 18000,\n POPULATED_PLACE: 'London',\n POPULATED_PLACE_URI:\n 'http://data.ordnancesurvey.co.uk/id/4000000074813508',\n POPULATED_PLACE_TYPE:\n 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',\n DISTRICT_BOROUGH: 'Brent',\n DISTRICT_BOROUGH_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000011447',\n DISTRICT_BOROUGH_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',\n COUNTY_UNITARY: 'Greater London',\n COUNTY_UNITARY_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000041441',\n COUNTY_UNITARY_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',\n REGION: 'London',\n REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',\n COUNTRY: 'England',\n COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'\n }\n })\n })\n\n it('should return an empty response when an error is encountered', async () => {\n jest.mocked(getJson).mockResolvedValueOnce({\n res: /** @type {IncomingMessage} */ ({\n statusCode: 300,\n headers: {}\n }),\n payload: undefined,\n error: new Error('Unknown error')\n })\n\n const { results } = await service.find('NW1 6XE', 'apikey')\n\n expect(results).toHaveLength(0)\n expect(results).toEqual([])\n })\n\n it('should return an empty response when a non 200 response is encountered', async () => {\n jest\n .mocked(getJson)\n .mockRejectedValueOnce(\n Boom.badRequest(\n 'OS API error',\n new Error('Invalid postcode segments')\n )\n )\n\n const { results } = await service.find('invalid postcode', 'apikey')\n\n expect(results).toHaveLength(0)\n expect(results).toEqual([])\n })\n })\n})\n\n/**\n * @import { IncomingMessage } from 'node:http'\n */\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAE7B,OAAO,KAAKC,OAAO;AACnB,SAASC,MAAM,IAAIC,UAAU;AAC7B,SAASC,OAAO;AAEhBC,IAAI,CAACC,IAAI,gCAAuC,CAAC;AAEjDC,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC7BA,QAAQ,CAAC,MAAM,EAAE,MAAM;IACrBC,EAAE,CAAC,uBAAuB,EAAE,YAAY;MACtCH,IAAI,CAACI,MAAM,CAACL,OAAO,CAAC,CAACM,qBAAqB,CAAC;QACzCC,GAAG,GAAE,8BAAgC;UACnCC,UAAU,EAAE,GAAG;UACfC,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;QACFC,OAAO,EAAEX,UAAU;QACnBY,KAAK,EAAEC;MACT,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,GAAG,MAAMhB,OAAO,CAACiB,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC;MAE3DC,MAAM,CAACF,OAAO,CAAC,CAACG,YAAY,CAAC,CAAC,CAAC;MAC/BD,MAAM,CAACF,OAAO,CAAC,CAACK,OAAO,CAAC,EAAE,CAAC;IAC7B,CAAC,CAAC;IAEFd,EAAE,CAAC,wEAAwE,EAAE,YAAY;MACvFH,IAAI,CACDI,MAAM,CAACL,OAAO,CAAC,CACf2C,qBAAqB,CACpB/C,IAAI,CAACgD,UAAU,CACb,cAAc,EACd,IAAIF,KAAK,CAAC,2BAA2B,CACvC,CACF,CAAC;MAEH,MAAM;QAAE7B;MAAQ,CAAC,GAAG,MAAMhB,OAAO,CAACiB,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;MAEpEC,MAAM,CAACF,OAAO,CAAC,CAACG,YAAY,CAAC,CAAC,CAAC;MAC/BD,MAAM,CAACF,OAAO,CAAC,CAACK,OAAO,CAAC,EAAE,CAAC;IAC7B,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC;;AAEF;AACA;AACA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/forms-engine-plugin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "Defra forms engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"joi": "^17.13.3",
|
|
131
131
|
"liquidjs": "^10.24.0",
|
|
132
132
|
"lodash": "^4.17.21",
|
|
133
|
+
"maplibre-gl": "^5.24.0",
|
|
133
134
|
"marked": "^15.0.12",
|
|
134
135
|
"nunjucks": "^3.2.4",
|
|
135
136
|
"obscenity": "^0.4.5",
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// @ts-expect-error - no types
|
|
2
|
+
import createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'
|
|
3
|
+
// @ts-expect-error - no types
|
|
4
|
+
import { maplibreLayerAdapter } from '@defra/interactive-map/plugins/datasets/adapters/maplibre'
|
|
5
|
+
// @ts-expect-error - no types
|
|
6
|
+
import createDrawPlugin from '@defra/interactive-map/plugins/draw-ml'
|
|
1
7
|
import { bbox } from '@turf/bbox'
|
|
2
8
|
|
|
3
9
|
import {
|
|
@@ -151,9 +157,6 @@ export function getBoundingBox(geojson) {
|
|
|
151
157
|
* @param {number} index - the 0-based index
|
|
152
158
|
*/
|
|
153
159
|
export function processGeospatial(config, geospatial, index) {
|
|
154
|
-
// @ts-expect-error - Defra namespace currently comes from UMD support files
|
|
155
|
-
const defra = window.defra
|
|
156
|
-
|
|
157
160
|
if (!(geospatial instanceof HTMLDivElement)) {
|
|
158
161
|
return
|
|
159
162
|
}
|
|
@@ -166,14 +169,15 @@ export function processGeospatial(config, geospatial, index) {
|
|
|
166
169
|
const { listEl, mapId } = createContainers(geospatialInput, index)
|
|
167
170
|
const geojson = getGeoJSON(geospatialInput)
|
|
168
171
|
const bounds = geojson.features.length ? getBoundingBox(geojson) : undefined
|
|
169
|
-
const drawPlugin =
|
|
172
|
+
const drawPlugin = createDrawPlugin()
|
|
170
173
|
const plugins = [drawPlugin]
|
|
171
174
|
const country = geospatial.dataset.country
|
|
172
175
|
|
|
173
176
|
if (country) {
|
|
174
177
|
// Add the country bounds as a dataset plugin to show the valid area on the map
|
|
175
178
|
// and provide feedback to the user when they add features outside of the bounds.
|
|
176
|
-
const datasetsPlugin =
|
|
179
|
+
const datasetsPlugin = createDatasetsPlugin({
|
|
180
|
+
layerAdapter: maplibreLayerAdapter,
|
|
177
181
|
datasets: [
|
|
178
182
|
{
|
|
179
183
|
id: 'invalid-area',
|