@panneau/protocol 5.0.0-alpha.15 → 5.0.0-alpha.16
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/dist/addresses.d.ts +23 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +52 -0
- package/dist/addresses.js.map +1 -0
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +109 -0
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +23 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +51 -3
- package/dist/constants.js.map +1 -1
- package/dist/currencies.d.ts +22 -0
- package/dist/currencies.d.ts.map +1 -0
- package/dist/currencies.js +231 -0
- package/dist/currencies.js.map +1 -0
- package/dist/index.js +7 -4
- package/dist/links.d.ts +38 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +65 -0
- package/dist/links.js.map +1 -0
- package/dist/lint.js +6 -2
- package/dist/lint.js.map +1 -1
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +11 -2
- package/dist/mock/index.js.map +1 -1
- package/dist/query.d.ts +4 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +23 -7
- package/dist/query.js.map +1 -1
- package/dist/rules.d.ts +4 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +165 -7
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -2
- package/dist/schemas/action.d.ts +46 -1
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/api.d.ts +43 -3
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +35 -1
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/definition.d.ts +93 -3
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/field.d.ts +193 -2
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +91 -7
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +445 -14
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +14 -4
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/list.d.ts +2 -2
- package/dist/schemas/resource.d.ts +93 -3
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/validate.d.ts +2 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +18 -4
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
- package/schema/boot.schema.json +164 -2
- package/schema/definition.schema.json +164 -2
- package/schema/openapi.json +611 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AddressPart } from './constants.js';
|
|
2
|
+
import type { Field } from './schemas/field.js';
|
|
3
|
+
/** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */
|
|
4
|
+
export declare const POSTAL_CODE_COUNTRIES: readonly string[];
|
|
5
|
+
/**
|
|
6
|
+
* A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for
|
|
7
|
+
* the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the
|
|
8
|
+
* code in capitals, its spaces collapsed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizePostalCode(code: string, country?: string | null): string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a postal code is one of its country, once normalized. Postal codes of countries whose
|
|
13
|
+
* format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isPostalCode(code: string, country?: string | null): boolean;
|
|
16
|
+
/** Whether a value is one of the parts of an address. */
|
|
17
|
+
export declare function isAddressPart(value: unknown): value is AddressPart;
|
|
18
|
+
/**
|
|
19
|
+
* The parts a filled address of a field must have: those of `settings.required`, or `street`,
|
|
20
|
+
* `city` and `country`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAddressRequiredParts(field: Pick<Field, 'settings'>): AddressPart[];
|
|
23
|
+
//# sourceMappingURL=addresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../src/addresses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,WAAW,EAAkC,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAS7C,mGAAmG;AACnG,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAyB,CAAC;AAO7E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAiBjF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAI3E;AAED,yDAAyD;AACzD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,WAAW,EAAE,CAKrF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ADDRESS_PARTS, DEFAULT_ADDRESS_REQUIRED_PARTS } from "./constants.js";
|
|
2
|
+
//#region src/addresses.ts
|
|
3
|
+
/** The formats of normalized postal codes, for the countries whose postal codes are checked. */
|
|
4
|
+
var FORMATS = {
|
|
5
|
+
CA: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] \d[ABCEGHJ-NPRSTV-Z]\d$/,
|
|
6
|
+
US: /^\d{5}(-\d{4})?$/
|
|
7
|
+
};
|
|
8
|
+
/** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */
|
|
9
|
+
var POSTAL_CODE_COUNTRIES = Object.keys(FORMATS);
|
|
10
|
+
/** Capitals, with the spaces trimmed and collapsed: the postal codes of other countries. */
|
|
11
|
+
function normalizeText(code) {
|
|
12
|
+
return code.trim().replace(/\s+/g, " ").toUpperCase();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for
|
|
16
|
+
* the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the
|
|
17
|
+
* code in capitals, its spaces collapsed.
|
|
18
|
+
*/
|
|
19
|
+
function normalizePostalCode(code, country) {
|
|
20
|
+
const compact = code.replace(/[\s-]+/g, "").toUpperCase();
|
|
21
|
+
switch (country?.toUpperCase()) {
|
|
22
|
+
case "CA": return /^[A-Z]\d[A-Z]\d[A-Z]\d$/.test(compact) ? `${compact.slice(0, 3)} ${compact.slice(3)}` : normalizeText(code);
|
|
23
|
+
case "US":
|
|
24
|
+
if (/^\d{5}$/.test(compact)) return compact;
|
|
25
|
+
return /^\d{9}$/.test(compact) ? `${compact.slice(0, 5)}-${compact.slice(5)}` : normalizeText(code);
|
|
26
|
+
default: return normalizeText(code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a postal code is one of its country, once normalized. Postal codes of countries whose
|
|
31
|
+
* format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.
|
|
32
|
+
*/
|
|
33
|
+
function isPostalCode(code, country) {
|
|
34
|
+
const format = country !== void 0 && country !== null ? FORMATS[country.toUpperCase()] : void 0;
|
|
35
|
+
return format === void 0 || format.test(normalizePostalCode(code, country));
|
|
36
|
+
}
|
|
37
|
+
/** Whether a value is one of the parts of an address. */
|
|
38
|
+
function isAddressPart(value) {
|
|
39
|
+
return typeof value === "string" && ADDRESS_PARTS.includes(value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The parts a filled address of a field must have: those of `settings.required`, or `street`,
|
|
43
|
+
* `city` and `country`.
|
|
44
|
+
*/
|
|
45
|
+
function getAddressRequiredParts(field) {
|
|
46
|
+
const setting = field.settings?.required;
|
|
47
|
+
return Array.isArray(setting) ? setting.filter(isAddressPart) : [...DEFAULT_ADDRESS_REQUIRED_PARTS];
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=addresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.js","names":[],"sources":["../src/addresses.ts"],"sourcesContent":["// Addresses (decision 0054): their required parts, and postal codes by country, which clients and\n// backends normalize, and whose formats the `postalCode` rule checks. This module doesn't import\n// zod.\nimport { ADDRESS_PARTS, type AddressPart, DEFAULT_ADDRESS_REQUIRED_PARTS } from './constants';\nimport type { Field } from './schemas/field';\n\n/** The formats of normalized postal codes, for the countries whose postal codes are checked. */\nconst FORMATS: Readonly<Record<string, RegExp>> = {\n // Letters that Canada Post doesn't use (D, F, I, O, Q, U, and W or Z first) are refused\n CA: /^[ABCEGHJ-NPRSTVXY]\\d[ABCEGHJ-NPRSTV-Z] \\d[ABCEGHJ-NPRSTV-Z]\\d$/,\n US: /^\\d{5}(-\\d{4})?$/,\n};\n\n/** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */\nexport const POSTAL_CODE_COUNTRIES: readonly string[] = Object.keys(FORMATS);\n\n/** Capitals, with the spaces trimmed and collapsed: the postal codes of other countries. */\nfunction normalizeText(code: string): string {\n return code.trim().replace(/\\s+/g, ' ').toUpperCase();\n}\n\n/**\n * A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for\n * the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the\n * code in capitals, its spaces collapsed.\n */\nexport function normalizePostalCode(code: string, country?: string | null): string {\n const compact = code.replace(/[\\s-]+/g, '').toUpperCase();\n switch (country?.toUpperCase()) {\n case 'CA':\n return /^[A-Z]\\d[A-Z]\\d[A-Z]\\d$/.test(compact)\n ? `${compact.slice(0, 3)} ${compact.slice(3)}`\n : normalizeText(code);\n case 'US':\n if (/^\\d{5}$/.test(compact)) {\n return compact;\n }\n return /^\\d{9}$/.test(compact)\n ? `${compact.slice(0, 5)}-${compact.slice(5)}`\n : normalizeText(code);\n default:\n return normalizeText(code);\n }\n}\n\n/**\n * Whether a postal code is one of its country, once normalized. Postal codes of countries whose\n * format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.\n */\nexport function isPostalCode(code: string, country?: string | null): boolean {\n const format =\n country !== undefined && country !== null ? FORMATS[country.toUpperCase()] : undefined;\n return format === undefined || format.test(normalizePostalCode(code, country));\n}\n\n/** Whether a value is one of the parts of an address. */\nexport function isAddressPart(value: unknown): value is AddressPart {\n return typeof value === 'string' && (ADDRESS_PARTS as readonly string[]).includes(value);\n}\n\n/**\n * The parts a filled address of a field must have: those of `settings.required`, or `street`,\n * `city` and `country`.\n */\nexport function getAddressRequiredParts(field: Pick<Field, 'settings'>): AddressPart[] {\n const setting = field.settings?.required;\n return Array.isArray(setting)\n ? setting.filter(isAddressPart)\n : [...DEFAULT_ADDRESS_REQUIRED_PARTS];\n}\n"],"mappings":";;;AAOA,IAAM,UAA4C;CAE9C,IAAI;CACJ,IAAI;AACR;;AAGA,IAAa,wBAA2C,OAAO,KAAK,OAAO;;AAG3E,SAAS,cAAc,MAAsB;CACzC,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,YAAY;AACxD;;;;;;AAOA,SAAgB,oBAAoB,MAAc,SAAiC;CAC/E,MAAM,UAAU,KAAK,QAAQ,WAAW,EAAE,CAAC,CAAC,YAAY;CACxD,QAAQ,SAAS,YAAY,GAA7B;EACI,KAAK,MACD,OAAO,0BAA0B,KAAK,OAAO,IACvC,GAAG,QAAQ,MAAM,GAAG,CAAC,EAAE,GAAG,QAAQ,MAAM,CAAC,MACzC,cAAc,IAAI;EAC5B,KAAK;GACD,IAAI,UAAU,KAAK,OAAO,GACtB,OAAO;GAEX,OAAO,UAAU,KAAK,OAAO,IACvB,GAAG,QAAQ,MAAM,GAAG,CAAC,EAAE,GAAG,QAAQ,MAAM,CAAC,MACzC,cAAc,IAAI;EAC5B,SACI,OAAO,cAAc,IAAI;CACjC;AACJ;;;;;AAMA,SAAgB,aAAa,MAAc,SAAkC;CACzE,MAAM,SACF,YAAY,KAAA,KAAa,YAAY,OAAO,QAAQ,QAAQ,YAAY,KAAK,KAAA;CACjF,OAAO,WAAW,KAAA,KAAa,OAAO,KAAK,oBAAoB,MAAM,OAAO,CAAC;AACjF;;AAGA,SAAgB,cAAc,OAAsC;CAChE,OAAO,OAAO,UAAU,YAAa,cAAoC,SAAS,KAAK;AAC3F;;;;;AAMA,SAAgB,wBAAwB,OAA+C;CACnF,MAAM,UAAU,MAAM,UAAU;CAChC,OAAO,MAAM,QAAQ,OAAO,IACtB,QAAQ,OAAO,aAAa,IAC5B,CAAC,GAAG,8BAA8B;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"AA+BA,MAAM,WAAW,kBAAkB;IAC/B,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjE,wEAAwE;IACxE,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE;QACL,mCAAmC;QACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,kCAAkC;QAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,2FAA2F;QAC3F,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACL;AAED,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhE,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,iBAAiB,CAAC;IAC1B,qDAAqD;IACrD,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAsFD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAm5C5F;AAED,oDAAoD;AACpD,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAU9D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PROBLEM_CONTENT_TYPE } from "../version.js";
|
|
2
2
|
import { CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE } from "../constants.js";
|
|
3
3
|
import { isEqual, isFilled } from "../values.js";
|
|
4
|
+
import { getLinkTypes } from "../links.js";
|
|
4
5
|
import { isCursorPage, toSearchParams } from "../query.js";
|
|
5
6
|
import { isSearchableResource, toSearchQueryParams } from "../search.js";
|
|
6
7
|
import { formatContextHeader } from "../context.js";
|
|
@@ -704,6 +705,57 @@ async function runConformance(options) {
|
|
|
704
705
|
const failure = check.expectProblem(reply, 422);
|
|
705
706
|
if (failure !== null) check.expect(failure.errors !== void 0 && Object.keys(failure.errors).length > 0, "A 422 problem must list the invalid values in `errors`.");
|
|
706
707
|
});
|
|
708
|
+
await run("create.implied-rules", "A reversed date range and an invalid amount are refused with a 422 problem", async (check) => {
|
|
709
|
+
if (writes === void 0 || resource === null) {
|
|
710
|
+
check.skip("Write checks are disabled.");
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const cases = resource.fields.flatMap((field) => {
|
|
714
|
+
if (field.localized === true || field.readOnly === true) return [];
|
|
715
|
+
if (field.type === "daterange") {
|
|
716
|
+
const time = field.settings?.time === true;
|
|
717
|
+
return [[
|
|
718
|
+
field.name,
|
|
719
|
+
time ? {
|
|
720
|
+
start: "2026-11-06T10:00:00Z",
|
|
721
|
+
end: "2026-11-04T10:00:00Z"
|
|
722
|
+
} : {
|
|
723
|
+
start: "2026-11-06",
|
|
724
|
+
end: "2026-11-04"
|
|
725
|
+
},
|
|
726
|
+
"a range that ends before it starts"
|
|
727
|
+
]];
|
|
728
|
+
}
|
|
729
|
+
if (field.type === "money") {
|
|
730
|
+
const currencies = field.settings?.currencies;
|
|
731
|
+
const currency = typeof field.settings?.currency === "string" ? field.settings.currency : Array.isArray(currencies) && typeof currencies[0] === "string" ? currencies[0] : "CAD";
|
|
732
|
+
return [[
|
|
733
|
+
field.name,
|
|
734
|
+
{
|
|
735
|
+
amount: 12.5,
|
|
736
|
+
currency
|
|
737
|
+
},
|
|
738
|
+
"an amount in major units"
|
|
739
|
+
]];
|
|
740
|
+
}
|
|
741
|
+
return [];
|
|
742
|
+
});
|
|
743
|
+
if (cases.length === 0) {
|
|
744
|
+
check.skip("The resource has no daterange or money field.");
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
for (const [name, value, label] of cases) {
|
|
748
|
+
const reply = await request(resourcePath(), {
|
|
749
|
+
method: "POST",
|
|
750
|
+
body: JSON.stringify({
|
|
751
|
+
...writes.create,
|
|
752
|
+
[name]: value
|
|
753
|
+
})
|
|
754
|
+
});
|
|
755
|
+
const failure = check.expectProblem(reply, 422);
|
|
756
|
+
if (failure !== null) check.expect(Object.keys(failure.errors ?? {}).some((key) => key === name || key.startsWith(`${name}.`)), `${name}: ${label} is refused, but not in errors.${name}.`);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
707
759
|
await run("create", "POST /resources/{resource} creates an item", async (check) => {
|
|
708
760
|
if (writes === void 0 || resource === null) {
|
|
709
761
|
check.skip("Write checks are disabled.");
|
|
@@ -751,6 +803,63 @@ async function runConformance(options) {
|
|
|
751
803
|
});
|
|
752
804
|
check.expect(reply.status === 200, `An update with ${names.join(", ")} set to null got status ${reply.status}, expected 200.`);
|
|
753
805
|
});
|
|
806
|
+
await run("update.parts", "Addresses and links are refused at the path of their invalid part", async (check) => {
|
|
807
|
+
if (createdId === null || writes === void 0 || resource === null) {
|
|
808
|
+
check.skip("No item was created.");
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const editable = resource.fields.filter((field) => field.readOnly !== true && field.createOnly !== true && field.localized !== true && field.abilities?.update !== false && field.visibleWhen === void 0);
|
|
812
|
+
const address = editable.find((field) => {
|
|
813
|
+
const countries = field.settings?.countries;
|
|
814
|
+
return field.type === "address" && (!Array.isArray(countries) || countries.includes("CA") || countries.includes("US"));
|
|
815
|
+
});
|
|
816
|
+
const link = editable.find((field) => field.type === "link" && getLinkTypes(field).some((type) => type.id === "email" || type.id === "url"));
|
|
817
|
+
if (address === void 0 && link === void 0) {
|
|
818
|
+
check.skip("The resource has no address nor link field.");
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
const values = {};
|
|
822
|
+
const paths = [];
|
|
823
|
+
if (address !== void 0) {
|
|
824
|
+
const countries = address.settings?.countries;
|
|
825
|
+
const canada = !Array.isArray(countries) || countries.includes("CA");
|
|
826
|
+
values[address.name] = {
|
|
827
|
+
street: "1234 Main Street",
|
|
828
|
+
city: canada ? "Montreal" : "Springfield",
|
|
829
|
+
region: canada ? "QC" : "IL",
|
|
830
|
+
postalCode: canada ? "12345" : "H2X 1Y4",
|
|
831
|
+
country: canada ? "CA" : "US"
|
|
832
|
+
};
|
|
833
|
+
paths.push(`${address.name}.postalCode`);
|
|
834
|
+
}
|
|
835
|
+
if (link !== void 0) {
|
|
836
|
+
const email = getLinkTypes(link).some((type) => type.id === "email");
|
|
837
|
+
values[link.name] = email ? {
|
|
838
|
+
type: "email",
|
|
839
|
+
url: "info@example.com",
|
|
840
|
+
newTab: false
|
|
841
|
+
} : {
|
|
842
|
+
type: "url",
|
|
843
|
+
url: "example",
|
|
844
|
+
newTab: false
|
|
845
|
+
};
|
|
846
|
+
paths.push(`${link.name}.url`);
|
|
847
|
+
}
|
|
848
|
+
const current = await request(itemPath());
|
|
849
|
+
const item = check.expectStatus(current, 200) ? check.expectSchema(ItemResponse, current.body, "The item") : null;
|
|
850
|
+
if (item === null) return;
|
|
851
|
+
const version = item.data.version;
|
|
852
|
+
const reply = await request(itemPath(), {
|
|
853
|
+
method: "PATCH",
|
|
854
|
+
body: JSON.stringify(values),
|
|
855
|
+
headers: version !== null ? { "If-Match": `"${version}"` } : {}
|
|
856
|
+
});
|
|
857
|
+
const failure = check.expectProblem(reply, 422);
|
|
858
|
+
if (failure !== null) {
|
|
859
|
+
const missing = paths.filter((path) => failure.errors?.[path] === void 0);
|
|
860
|
+
check.expect(missing.length === 0, `The 422 problem has no errors at ${missing.join(", ")}: ${Object.keys(failure.errors ?? {}).join(", ") || "none"}.`);
|
|
861
|
+
}
|
|
862
|
+
});
|
|
754
863
|
await run("update.single-field", "A PATCH with a single field and If-Match changes that field alone", async (check) => {
|
|
755
864
|
if (createdId === null || writes === void 0 || resource === null) {
|
|
756
865
|
check.skip("No item was created.");
|