@schafevormfenster/rest-commons 0.1.1
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/CONTRIBUTING.md +1190 -0
- package/README.md +275 -0
- package/bin/setup.js +10 -0
- package/dist/api-schemas/error.schema.d.ts +20 -0
- package/dist/api-schemas/error.schema.d.ts.map +1 -0
- package/dist/api-schemas/error.schema.js +17 -0
- package/dist/api-schemas/health.schema.d.ts +497 -0
- package/dist/api-schemas/health.schema.d.ts.map +1 -0
- package/dist/api-schemas/health.schema.js +33 -0
- package/dist/api-schemas/okay.schema.d.ts +13 -0
- package/dist/api-schemas/okay.schema.d.ts.map +1 -0
- package/dist/api-schemas/okay.schema.js +5 -0
- package/dist/api-schemas/paginated-results.schema.d.ts +59 -0
- package/dist/api-schemas/paginated-results.schema.d.ts.map +1 -0
- package/dist/api-schemas/paginated-results.schema.js +10 -0
- package/dist/api-schemas/partial-results.schema.d.ts +30 -0
- package/dist/api-schemas/partial-results.schema.d.ts.map +1 -0
- package/dist/api-schemas/partial-results.schema.js +10 -0
- package/dist/api-schemas/result.schema.d.ts +17 -0
- package/dist/api-schemas/result.schema.d.ts.map +1 -0
- package/dist/api-schemas/result.schema.js +5 -0
- package/dist/api-schemas/results.schema.d.ts +21 -0
- package/dist/api-schemas/results.schema.d.ts.map +1 -0
- package/dist/api-schemas/results.schema.js +5 -0
- package/dist/helpers/correlation/get-correlation-id.d.ts +7 -0
- package/dist/helpers/correlation/get-correlation-id.d.ts.map +1 -0
- package/dist/helpers/correlation/get-correlation-id.js +16 -0
- package/dist/helpers/correlation/get-header.d.ts +7 -0
- package/dist/helpers/correlation/get-header.d.ts.map +1 -0
- package/dist/helpers/correlation/get-header.js +11 -0
- package/dist/helpers/detect-mime-type.d.ts +11 -0
- package/dist/helpers/detect-mime-type.d.ts.map +1 -0
- package/dist/helpers/detect-mime-type.js +40 -0
- package/dist/helpers/detect-suspicious-patterns.d.ts +8 -0
- package/dist/helpers/detect-suspicious-patterns.d.ts.map +1 -0
- package/dist/helpers/detect-suspicious-patterns.js +55 -0
- package/dist/helpers/eventify-constants.types.d.ts +32 -0
- package/dist/helpers/eventify-constants.types.d.ts.map +1 -0
- package/dist/helpers/eventify-constants.types.js +40 -0
- package/dist/helpers/hash-binary.d.ts +21 -0
- package/dist/helpers/hash-binary.d.ts.map +1 -0
- package/dist/helpers/hash-binary.js +28 -0
- package/dist/helpers/mime-types/detect-image-mime-type.d.ts +5 -0
- package/dist/helpers/mime-types/detect-image-mime-type.d.ts.map +1 -0
- package/dist/helpers/mime-types/detect-image-mime-type.js +41 -0
- package/dist/helpers/mime-types/detect-ole-mime-type.d.ts +6 -0
- package/dist/helpers/mime-types/detect-ole-mime-type.d.ts.map +1 -0
- package/dist/helpers/mime-types/detect-ole-mime-type.js +34 -0
- package/dist/helpers/mime-types/detect-pdf-mime-type.d.ts +5 -0
- package/dist/helpers/mime-types/detect-pdf-mime-type.d.ts.map +1 -0
- package/dist/helpers/mime-types/detect-pdf-mime-type.js +13 -0
- package/dist/helpers/mime-types/detect-zip-mime-type.d.ts +6 -0
- package/dist/helpers/mime-types/detect-zip-mime-type.d.ts.map +1 -0
- package/dist/helpers/mime-types/detect-zip-mime-type.js +23 -0
- package/dist/helpers/parameter-validation.d.ts +6 -0
- package/dist/helpers/parameter-validation.d.ts.map +1 -0
- package/dist/helpers/parameter-validation.js +19 -0
- package/dist/helpers/parameter-validation.types.d.ts +16 -0
- package/dist/helpers/parameter-validation.types.d.ts.map +1 -0
- package/dist/helpers/parameter-validation.types.js +38 -0
- package/dist/helpers/response-headers/build-api-unauthorized-headers.d.ts +6 -0
- package/dist/helpers/response-headers/build-api-unauthorized-headers.d.ts.map +1 -0
- package/dist/helpers/response-headers/build-api-unauthorized-headers.js +23 -0
- package/dist/helpers/response-headers/environment.types.d.ts +2 -0
- package/dist/helpers/response-headers/environment.types.d.ts.map +1 -0
- package/dist/helpers/response-headers/environment.types.js +1 -0
- package/dist/helpers/response-headers/resolve-environment.d.ts +8 -0
- package/dist/helpers/response-headers/resolve-environment.d.ts.map +1 -0
- package/dist/helpers/response-headers/resolve-environment.js +18 -0
- package/dist/helpers/slugify.d.ts +15 -0
- package/dist/helpers/slugify.d.ts.map +1 -0
- package/dist/helpers/slugify.js +32 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/normalization/normalize-list.d.ts +11 -0
- package/dist/normalization/normalize-list.d.ts.map +1 -0
- package/dist/normalization/normalize-list.js +19 -0
- package/dist/normalization/normalize-location.d.ts +16 -0
- package/dist/normalization/normalize-location.d.ts.map +1 -0
- package/dist/normalization/normalize-location.js +26 -0
- package/dist/primitives/coordinate-precision.d.ts +10 -0
- package/dist/primitives/coordinate-precision.d.ts.map +1 -0
- package/dist/primitives/coordinate-precision.js +27 -0
- package/dist/primitives/geo-point.schema.d.ts +8 -0
- package/dist/primitives/geo-point.schema.d.ts.map +1 -0
- package/dist/primitives/geo-point.schema.js +10 -0
- package/dist/primitives/geoname-id.schema.d.ts +8 -0
- package/dist/primitives/geoname-id.schema.d.ts.map +1 -0
- package/dist/primitives/geoname-id.schema.js +9 -0
- package/dist/primitives/international-zip.schema.d.ts +76 -0
- package/dist/primitives/international-zip.schema.d.ts.map +1 -0
- package/dist/primitives/international-zip.schema.js +81 -0
- package/dist/primitives/latitude.schema.d.ts +9 -0
- package/dist/primitives/latitude.schema.d.ts.map +1 -0
- package/dist/primitives/latitude.schema.js +13 -0
- package/dist/primitives/location.schema.d.ts +8 -0
- package/dist/primitives/location.schema.d.ts.map +1 -0
- package/dist/primitives/location.schema.js +15 -0
- package/dist/primitives/longitude.schema.d.ts +9 -0
- package/dist/primitives/longitude.schema.d.ts.map +1 -0
- package/dist/primitives/longitude.schema.js +13 -0
- package/dist/primitives/numeric-id.schema.d.ts +8 -0
- package/dist/primitives/numeric-id.schema.d.ts.map +1 -0
- package/dist/primitives/numeric-id.schema.js +10 -0
- package/dist/primitives/slug.schema.d.ts +17 -0
- package/dist/primitives/slug.schema.d.ts.map +1 -0
- package/dist/primitives/slug.schema.js +30 -0
- package/dist/primitives/uuid.schema.d.ts +8 -0
- package/dist/primitives/uuid.schema.d.ts.map +1 -0
- package/dist/primitives/uuid.schema.js +9 -0
- package/dist/primitives/wikidata-id.schema.d.ts +9 -0
- package/dist/primitives/wikidata-id.schema.d.ts.map +1 -0
- package/dist/primitives/wikidata-id.schema.js +10 -0
- package/dist/time/boundary-enforcement.d.ts +11 -0
- package/dist/time/boundary-enforcement.d.ts.map +1 -0
- package/dist/time/boundary-enforcement.js +43 -0
- package/dist/time/bounded-time.schema.d.ts +31 -0
- package/dist/time/bounded-time.schema.d.ts.map +1 -0
- package/dist/time/bounded-time.schema.js +77 -0
- package/dist/time/flexible-time-parser.d.ts +12 -0
- package/dist/time/flexible-time-parser.d.ts.map +1 -0
- package/dist/time/flexible-time-parser.js +94 -0
- package/dist/time/flexible-time.schema.d.ts +31 -0
- package/dist/time/flexible-time.schema.d.ts.map +1 -0
- package/dist/time/flexible-time.schema.js +31 -0
- package/dist/time/get-week-end.d.ts +10 -0
- package/dist/time/get-week-end.d.ts.map +1 -0
- package/dist/time/get-week-end.js +25 -0
- package/dist/time/get-week-start.d.ts +10 -0
- package/dist/time/get-week-start.d.ts.map +1 -0
- package/dist/time/get-week-start.js +25 -0
- package/dist/time/is-relative-time.d.ts +8 -0
- package/dist/time/is-relative-time.d.ts.map +1 -0
- package/dist/time/is-relative-time.js +9 -0
- package/dist/time/iso8601.schema.d.ts +14 -0
- package/dist/time/iso8601.schema.d.ts.map +1 -0
- package/dist/time/iso8601.schema.js +17 -0
- package/dist/time/iso8601.types.d.ts +6 -0
- package/dist/time/iso8601.types.d.ts.map +1 -0
- package/dist/time/iso8601.types.js +11 -0
- package/dist/time/parse-relative-time.d.ts +9 -0
- package/dist/time/parse-relative-time.d.ts.map +1 -0
- package/dist/time/parse-relative-time.js +36 -0
- package/dist/time/relative-time.schema.d.ts +23 -0
- package/dist/time/relative-time.schema.d.ts.map +1 -0
- package/dist/time/relative-time.schema.js +25 -0
- package/dist/time/since-parameter.schema.d.ts +8 -0
- package/dist/time/since-parameter.schema.d.ts.map +1 -0
- package/dist/time/since-parameter.schema.js +56 -0
- package/dist/time/time-helpers.d.ts +19 -0
- package/dist/time/time-helpers.d.ts.map +1 -0
- package/dist/time/time-helpers.js +56 -0
- package/dist/time/time-schemas.d.ts +20 -0
- package/dist/time/time-schemas.d.ts.map +1 -0
- package/dist/time/time-schemas.js +25 -0
- package/dist/time/timezone.types.d.ts +17 -0
- package/dist/time/timezone.types.d.ts.map +1 -0
- package/dist/time/timezone.types.js +15 -0
- package/dist/validation/zod-error-handler.d.ts +3 -0
- package/dist/validation/zod-error-handler.d.ts.map +1 -0
- package/dist/validation/zod-error-handler.js +189 -0
- package/dist/validation/zod-utils.d.ts +9 -0
- package/dist/validation/zod-utils.d.ts.map +1 -0
- package/dist/validation/zod-utils.js +23 -0
- package/eslint.config.mjs +16 -0
- package/package.json +44 -0
- package/src/api-schemas/error.schema.test.ts +27 -0
- package/src/api-schemas/error.schema.ts +23 -0
- package/src/api-schemas/health.schema.test.ts +104 -0
- package/src/api-schemas/health.schema.ts +63 -0
- package/src/api-schemas/okay.schema.test.ts +15 -0
- package/src/api-schemas/okay.schema.ts +8 -0
- package/src/api-schemas/paginated-results.schema.ts +17 -0
- package/src/api-schemas/partial-results.schema.ts +13 -0
- package/src/api-schemas/result.schema.test.ts +19 -0
- package/src/api-schemas/result.schema.ts +9 -0
- package/src/api-schemas/results.schema.test.ts +15 -0
- package/src/api-schemas/results.schema.ts +9 -0
- package/src/helpers/correlation/get-correlation-id.test.ts +126 -0
- package/src/helpers/correlation/get-correlation-id.ts +22 -0
- package/src/helpers/correlation/get-header.test.ts +179 -0
- package/src/helpers/correlation/get-header.ts +21 -0
- package/src/helpers/detect-mime-type.test.ts +100 -0
- package/src/helpers/detect-mime-type.ts +46 -0
- package/src/helpers/detect-suspicious-patterns.test.ts +45 -0
- package/src/helpers/detect-suspicious-patterns.ts +57 -0
- package/src/helpers/eventify-constants.test.ts +52 -0
- package/src/helpers/eventify-constants.types.test.ts +52 -0
- package/src/helpers/eventify-constants.types.ts +51 -0
- package/src/helpers/hash-binary.test.ts +60 -0
- package/src/helpers/hash-binary.ts +30 -0
- package/src/helpers/mime-types/detect-image-mime-type.test.ts +73 -0
- package/src/helpers/mime-types/detect-image-mime-type.ts +50 -0
- package/src/helpers/mime-types/detect-ole-mime-type.test.ts +86 -0
- package/src/helpers/mime-types/detect-ole-mime-type.ts +44 -0
- package/src/helpers/mime-types/detect-pdf-mime-type.test.ts +39 -0
- package/src/helpers/mime-types/detect-pdf-mime-type.ts +15 -0
- package/src/helpers/mime-types/detect-zip-mime-type.test.ts +88 -0
- package/src/helpers/mime-types/detect-zip-mime-type.ts +28 -0
- package/src/helpers/parameter-validation.test.ts +35 -0
- package/src/helpers/parameter-validation.ts +32 -0
- package/src/helpers/process-eventify-request.ts +146 -0
- package/src/helpers/response-headers/build-api-unauthorized-headers.ts +30 -0
- package/src/helpers/response-headers/environment.types.ts +1 -0
- package/src/helpers/response-headers/resolve-environment.ts +17 -0
- package/src/helpers/slugify.test.ts +77 -0
- package/src/helpers/slugify.ts +34 -0
- package/src/index.ts +46 -0
- package/src/normalization/normalize-list.test.ts +43 -0
- package/src/normalization/normalize-list.ts +21 -0
- package/src/normalization/normalize-location.test.ts +91 -0
- package/src/normalization/normalize-location.ts +29 -0
- package/src/primitives/coordinate-precision.test.ts +46 -0
- package/src/primitives/coordinate-precision.ts +30 -0
- package/src/primitives/geo-point.schema.test.ts +70 -0
- package/src/primitives/geo-point.schema.ts +14 -0
- package/src/primitives/geoname-id.schema.test.ts +60 -0
- package/src/primitives/geoname-id.schema.ts +12 -0
- package/src/primitives/international-zip.schema.test.ts +212 -0
- package/src/primitives/international-zip.schema.ts +103 -0
- package/src/primitives/latitude.schema.test.ts +77 -0
- package/src/primitives/latitude.schema.ts +20 -0
- package/src/primitives/location.schema.test.ts +21 -0
- package/src/primitives/location.schema.ts +22 -0
- package/src/primitives/longitude.schema.test.ts +77 -0
- package/src/primitives/longitude.schema.ts +20 -0
- package/src/primitives/numeric-id.schema.test.ts +32 -0
- package/src/primitives/numeric-id.schema.ts +13 -0
- package/src/primitives/slug.schema.test.ts +101 -0
- package/src/primitives/slug.schema.ts +41 -0
- package/src/primitives/uuid.schema.test.ts +45 -0
- package/src/primitives/uuid.schema.ts +12 -0
- package/src/primitives/wikidata-id.schema.test.ts +51 -0
- package/src/primitives/wikidata-id.schema.ts +16 -0
- package/src/time/README.md +220 -0
- package/src/time/boundary-enforcement.test.ts +130 -0
- package/src/time/boundary-enforcement.ts +59 -0
- package/src/time/bounded-time.schema.test.ts +294 -0
- package/src/time/bounded-time.schema.ts +111 -0
- package/src/time/flexible-time-parser.test.ts +586 -0
- package/src/time/flexible-time-parser.ts +122 -0
- package/src/time/flexible-time.schema.test.ts +243 -0
- package/src/time/flexible-time.schema.ts +43 -0
- package/src/time/is-relative-time.test.ts +23 -0
- package/src/time/is-relative-time.ts +9 -0
- package/src/time/iso8601.schema.ts +29 -0
- package/src/time/iso8601.types.test.ts +112 -0
- package/src/time/iso8601.types.ts +21 -0
- package/src/time/parse-relative-time.test.ts +49 -0
- package/src/time/parse-relative-time.ts +50 -0
- package/src/time/relative-time.schema.test.ts +23 -0
- package/src/time/relative-time.schema.ts +38 -0
- package/src/time/since-parameter.schema.test.ts +59 -0
- package/src/time/since-parameter.schema.ts +69 -0
- package/src/time/time-helpers.test.ts +263 -0
- package/src/time/time-helpers.ts +78 -0
- package/src/time/time-schemas.test.ts +181 -0
- package/src/time/time-schemas.ts +42 -0
- package/src/time/time.schema.test.ts +237 -0
- package/src/time/timezone-independence.test.ts +188 -0
- package/src/time/timezone.types.test.ts +55 -0
- package/src/time/timezone.types.ts +22 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.types.d.ts","sourceRoot":"","sources":["../../../src/helpers/response-headers/environment.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Environment } from "./environment.types";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve environment consistently across server/middleware contexts.
|
|
4
|
+
* - VERCEL_ENV: production | preview | development
|
|
5
|
+
* - NODE_ENV: production | development
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveEnvironment(): Environment;
|
|
8
|
+
//# sourceMappingURL=resolve-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-environment.d.ts","sourceRoot":"","sources":["../../../src/helpers/response-headers/resolve-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,CAShD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve environment consistently across server/middleware contexts.
|
|
3
|
+
* - VERCEL_ENV: production | preview | development
|
|
4
|
+
* - NODE_ENV: production | development
|
|
5
|
+
*/
|
|
6
|
+
export function resolveEnvironment() {
|
|
7
|
+
const vercel = process.env.VERCEL_ENV;
|
|
8
|
+
if (vercel === "production")
|
|
9
|
+
return "production";
|
|
10
|
+
if (vercel === "preview")
|
|
11
|
+
return "staging";
|
|
12
|
+
const node = process.env.NODE_ENV;
|
|
13
|
+
if (node === "production")
|
|
14
|
+
return "production";
|
|
15
|
+
if (node === "development")
|
|
16
|
+
return "development";
|
|
17
|
+
return "development";
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a string to a URL-safe slug.
|
|
3
|
+
* Uses the slugify npm package with support for German umlauts and other special characters.
|
|
4
|
+
*
|
|
5
|
+
* @param text - Input string to slugify
|
|
6
|
+
* @returns URL-safe slug (lowercase, hyphens, no special chars)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* slugify("Hello World!") // "hello-world"
|
|
10
|
+
* slugify("Berlin, Germany") // "berlin-germany"
|
|
11
|
+
* slugify("Café in München") // "cafe-in-munchen"
|
|
12
|
+
* slugify("Äpfel und Öl") // "aepfel-und-oel"
|
|
13
|
+
*/
|
|
14
|
+
export declare function slugify(text: string): string;
|
|
15
|
+
//# sourceMappingURL=slugify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/helpers/slugify.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import slugifyPackage from "slugify";
|
|
2
|
+
// Extend slugify to handle German umlauts correctly
|
|
3
|
+
slugifyPackage.extend({
|
|
4
|
+
'ä': 'ae',
|
|
5
|
+
'ö': 'oe',
|
|
6
|
+
'ü': 'ue',
|
|
7
|
+
'ß': 'ss',
|
|
8
|
+
'Ä': 'Ae',
|
|
9
|
+
'Ö': 'Oe',
|
|
10
|
+
'Ü': 'Ue',
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Convert a string to a URL-safe slug.
|
|
14
|
+
* Uses the slugify npm package with support for German umlauts and other special characters.
|
|
15
|
+
*
|
|
16
|
+
* @param text - Input string to slugify
|
|
17
|
+
* @returns URL-safe slug (lowercase, hyphens, no special chars)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* slugify("Hello World!") // "hello-world"
|
|
21
|
+
* slugify("Berlin, Germany") // "berlin-germany"
|
|
22
|
+
* slugify("Café in München") // "cafe-in-munchen"
|
|
23
|
+
* slugify("Äpfel und Öl") // "aepfel-und-oel"
|
|
24
|
+
*/
|
|
25
|
+
export function slugify(text) {
|
|
26
|
+
return slugifyPackage(text, {
|
|
27
|
+
lower: true, // Convert to lowercase
|
|
28
|
+
strict: true, // Strip special characters except replacement
|
|
29
|
+
remove: /[*+~.()'"!:@]/g, // Remove these characters
|
|
30
|
+
trim: true, // Trim leading/trailing replacement chars
|
|
31
|
+
});
|
|
32
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from "./api-schemas/error.schema";
|
|
2
|
+
export * from "./api-schemas/health.schema";
|
|
3
|
+
export * from "./api-schemas/okay.schema";
|
|
4
|
+
export * from "./api-schemas/result.schema";
|
|
5
|
+
export * from "./api-schemas/results.schema";
|
|
6
|
+
export * from "./primitives/location.schema";
|
|
7
|
+
export * from "./primitives/slug.schema";
|
|
8
|
+
export * from "./primitives/numeric-id.schema";
|
|
9
|
+
export * from "./primitives/uuid.schema";
|
|
10
|
+
export * from "./primitives/geoname-id.schema";
|
|
11
|
+
export * from "./primitives/wikidata-id.schema";
|
|
12
|
+
export * from "./primitives/international-zip.schema";
|
|
13
|
+
export * from "./time/timezone.types";
|
|
14
|
+
export * from "./time/iso8601.schema";
|
|
15
|
+
export * from "./time/relative-time.schema";
|
|
16
|
+
export * from "./time/flexible-time.schema";
|
|
17
|
+
export * from "./time/bounded-time.schema";
|
|
18
|
+
export * from "./time/time-helpers";
|
|
19
|
+
export * from "./time/is-relative-time";
|
|
20
|
+
export { parseFlexibleTime as parseFlexibleTimeAdvanced } from "./time/flexible-time-parser";
|
|
21
|
+
export * from "./time/boundary-enforcement";
|
|
22
|
+
/** @deprecated Use flexible-time.schema exports instead */
|
|
23
|
+
export { FlexibleTimeSchema as FlexibleTimeSchemaOld, FlexibleTime as FlexibleTimeOld, TimeUnit, RelativeTimeConfig } from "./time/time-schemas";
|
|
24
|
+
export * from "./helpers/correlation/get-correlation-id";
|
|
25
|
+
export * from "./helpers/correlation/get-header";
|
|
26
|
+
export * from "./helpers/detect-mime-type";
|
|
27
|
+
export * from "./helpers/detect-suspicious-patterns";
|
|
28
|
+
export * from "./helpers/hash-binary";
|
|
29
|
+
export * from "./helpers/parameter-validation";
|
|
30
|
+
export * from "./helpers/slugify";
|
|
31
|
+
export * from "./helpers/response-headers/build-api-unauthorized-headers";
|
|
32
|
+
export * from "./helpers/response-headers/environment.types";
|
|
33
|
+
export * from "./helpers/response-headers/resolve-environment";
|
|
34
|
+
export * from "./normalization/normalize-list";
|
|
35
|
+
export * from "./normalization/normalize-location";
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAG7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAC7F,cAAc,6BAA6B,CAAC;AAG5C,2DAA2D;AAC3D,OAAO,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,YAAY,IAAI,eAAe,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGjJ,cAAc,0CAA0C,CAAC;AACzD,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2DAA2D,CAAC;AAC1E,cAAc,8CAA8C,CAAC;AAC7D,cAAc,gDAAgD,CAAC;AAG/D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Schemas
|
|
2
|
+
export * from "./api-schemas/error.schema";
|
|
3
|
+
export * from "./api-schemas/health.schema";
|
|
4
|
+
export * from "./api-schemas/okay.schema";
|
|
5
|
+
export * from "./api-schemas/result.schema";
|
|
6
|
+
export * from "./api-schemas/results.schema";
|
|
7
|
+
// Primitive schemas
|
|
8
|
+
export * from "./primitives/location.schema";
|
|
9
|
+
export * from "./primitives/slug.schema";
|
|
10
|
+
export * from "./primitives/numeric-id.schema";
|
|
11
|
+
export * from "./primitives/uuid.schema";
|
|
12
|
+
export * from "./primitives/geoname-id.schema";
|
|
13
|
+
export * from "./primitives/wikidata-id.schema";
|
|
14
|
+
export * from "./primitives/international-zip.schema";
|
|
15
|
+
// Time utilities
|
|
16
|
+
export * from "./time/timezone.types";
|
|
17
|
+
export * from "./time/iso8601.schema"; // ISO8601 schemas
|
|
18
|
+
export * from "./time/relative-time.schema"; // Relative time schemas
|
|
19
|
+
export * from "./time/flexible-time.schema"; // Flexible time schemas
|
|
20
|
+
export * from "./time/bounded-time.schema"; // Bounded time schemas
|
|
21
|
+
export * from "./time/time-helpers"; // Helper functions
|
|
22
|
+
export * from "./time/is-relative-time";
|
|
23
|
+
export { parseFlexibleTime as parseFlexibleTimeAdvanced } from "./time/flexible-time-parser";
|
|
24
|
+
export * from "./time/boundary-enforcement";
|
|
25
|
+
// Deprecated exports (for backward compatibility)
|
|
26
|
+
/** @deprecated Use flexible-time.schema exports instead */
|
|
27
|
+
export { FlexibleTimeSchema as FlexibleTimeSchemaOld } from "./time/time-schemas";
|
|
28
|
+
// Helpers
|
|
29
|
+
export * from "./helpers/correlation/get-correlation-id";
|
|
30
|
+
export * from "./helpers/correlation/get-header";
|
|
31
|
+
export * from "./helpers/detect-mime-type";
|
|
32
|
+
export * from "./helpers/detect-suspicious-patterns";
|
|
33
|
+
export * from "./helpers/hash-binary";
|
|
34
|
+
export * from "./helpers/parameter-validation";
|
|
35
|
+
export * from "./helpers/slugify";
|
|
36
|
+
export * from "./helpers/response-headers/build-api-unauthorized-headers";
|
|
37
|
+
export * from "./helpers/response-headers/environment.types";
|
|
38
|
+
export * from "./helpers/response-headers/resolve-environment";
|
|
39
|
+
// Utilities
|
|
40
|
+
export * from "./normalization/normalize-list";
|
|
41
|
+
export * from "./normalization/normalize-location";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize an array of strings by:
|
|
3
|
+
* - sanitizing with whitelist rules (preserving umlauts, removing injections)
|
|
4
|
+
* - trimming whitespace
|
|
5
|
+
* - lowercasing using locale-insensitive toLowerCase
|
|
6
|
+
* - removing duplicates
|
|
7
|
+
* - sorting alphabetically with proper German locale support (umlauts near base letters)
|
|
8
|
+
* - enforcing a maximum count
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeStringList(values?: string[]): string[];
|
|
11
|
+
//# sourceMappingURL=normalize-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-list.d.ts","sourceRoot":"","sources":["../../src/normalization/normalize-list.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE,CASnE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MAX_TAGS_COUNT, sanitizeTag } from "@schafevormfenster/security";
|
|
2
|
+
/**
|
|
3
|
+
* Normalize an array of strings by:
|
|
4
|
+
* - sanitizing with whitelist rules (preserving umlauts, removing injections)
|
|
5
|
+
* - trimming whitespace
|
|
6
|
+
* - lowercasing using locale-insensitive toLowerCase
|
|
7
|
+
* - removing duplicates
|
|
8
|
+
* - sorting alphabetically with proper German locale support (umlauts near base letters)
|
|
9
|
+
* - enforcing a maximum count
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeStringList(values = []) {
|
|
12
|
+
const sanitized = values.map((v) => sanitizeTag(v));
|
|
13
|
+
const normalized = sanitized
|
|
14
|
+
.map((v) => v.trim().toLowerCase())
|
|
15
|
+
.filter((v) => v.length > 0);
|
|
16
|
+
const unique = [...new Set(normalized)].slice(0, MAX_TAGS_COUNT);
|
|
17
|
+
unique.sort((a, b) => a.localeCompare(b, "de-DE"));
|
|
18
|
+
return unique;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes location strings to optimize cache hits.
|
|
3
|
+
*
|
|
4
|
+
* Cleanup operations:
|
|
5
|
+
* - Remove duplicate or multiple spaces and reduce to at most one space character
|
|
6
|
+
* - Ensure that a comma has no space before but one space after
|
|
7
|
+
*
|
|
8
|
+
* @param location - The location string to normalize
|
|
9
|
+
* @returns Normalized location string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* normalizeLocation("Schlatkow , 17390 Schmatzin")
|
|
13
|
+
* // Returns: "Schlatkow, 17390 Schmatzin"
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeLocation(location: string): string;
|
|
16
|
+
//# sourceMappingURL=normalize-location.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-location.d.ts","sourceRoot":"","sources":["../../src/normalization/normalize-location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc1D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes location strings to optimize cache hits.
|
|
3
|
+
*
|
|
4
|
+
* Cleanup operations:
|
|
5
|
+
* - Remove duplicate or multiple spaces and reduce to at most one space character
|
|
6
|
+
* - Ensure that a comma has no space before but one space after
|
|
7
|
+
*
|
|
8
|
+
* @param location - The location string to normalize
|
|
9
|
+
* @returns Normalized location string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* normalizeLocation("Schlatkow , 17390 Schmatzin")
|
|
13
|
+
* // Returns: "Schlatkow, 17390 Schmatzin"
|
|
14
|
+
*/
|
|
15
|
+
export function normalizeLocation(location) {
|
|
16
|
+
return (location
|
|
17
|
+
// First pass: normalize spaces (collapse multiple spaces/tabs/newlines to single space)
|
|
18
|
+
.replaceAll(/[ \t\n\r]+/gu, " ")
|
|
19
|
+
// Trim leading and trailing spaces
|
|
20
|
+
.trim()
|
|
21
|
+
// Fix comma spacing: remove space before comma, ensure one space after comma (but not at end)
|
|
22
|
+
// eslint-disable-next-line sonarjs/slow-regex -- Necessary for comma normalization
|
|
23
|
+
.replaceAll(/ *, */gu, ", ")
|
|
24
|
+
// Remove trailing space after comma if it's at the end of string
|
|
25
|
+
.replace(/, $/u, ","));
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a coordinate value has at most the specified number of decimal places.
|
|
3
|
+
* Handles both standard notation and scientific notation.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The numeric coordinate value to validate
|
|
6
|
+
* @param maxDecimalPlaces - Maximum allowed decimal places (default: 8)
|
|
7
|
+
* @returns true if the value has at most maxDecimalPlaces decimal places
|
|
8
|
+
*/
|
|
9
|
+
export declare function hasValidDecimalPrecision(value: number, maxDecimalPlaces?: number): boolean;
|
|
10
|
+
//# sourceMappingURL=coordinate-precision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinate-precision.d.ts","sourceRoot":"","sources":["../../src/primitives/coordinate-precision.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,MAAM,EACb,gBAAgB,SAAI,GACnB,OAAO,CAkBT"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a coordinate value has at most the specified number of decimal places.
|
|
3
|
+
* Handles both standard notation and scientific notation.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The numeric coordinate value to validate
|
|
6
|
+
* @param maxDecimalPlaces - Maximum allowed decimal places (default: 8)
|
|
7
|
+
* @returns true if the value has at most maxDecimalPlaces decimal places
|
|
8
|
+
*/
|
|
9
|
+
export function hasValidDecimalPrecision(value, maxDecimalPlaces = 8) {
|
|
10
|
+
// Convert to string and handle scientific notation
|
|
11
|
+
const valueString = value.toString();
|
|
12
|
+
if (valueString.includes("e") || valueString.includes("E")) {
|
|
13
|
+
// For scientific notation, convert to fixed notation
|
|
14
|
+
// Use 20 decimal places to ensure we capture all significant digits
|
|
15
|
+
// without losing precision during the conversion
|
|
16
|
+
const fixed = value.toFixed(20);
|
|
17
|
+
const [, decimalPart = ""] = fixed.split(".");
|
|
18
|
+
// Remove trailing zeros without regex
|
|
19
|
+
let decimals = decimalPart;
|
|
20
|
+
while (decimals.endsWith("0")) {
|
|
21
|
+
decimals = decimals.slice(0, -1);
|
|
22
|
+
}
|
|
23
|
+
return decimals.length <= maxDecimalPlaces;
|
|
24
|
+
}
|
|
25
|
+
const decimalPlaces = valueString.split(".")[1]?.length || 0;
|
|
26
|
+
return decimalPlaces <= maxDecimalPlaces;
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating geographic coordinates as a tuple.
|
|
4
|
+
* Geographic coordinates as [latitude, longitude].
|
|
5
|
+
*/
|
|
6
|
+
export declare const GeoPointSchema: z.ZodTuple<[z.ZodEffects<z.ZodNumber, number, number>, z.ZodEffects<z.ZodNumber, number, number>], null>;
|
|
7
|
+
export type GeoPoint = z.infer<typeof GeoPointSchema>;
|
|
8
|
+
//# sourceMappingURL=geo-point.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo-point.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/geo-point.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;GAGG;AACH,eAAO,MAAM,cAAc,0GAEmC,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { LatitudeSchema } from "./latitude.schema";
|
|
3
|
+
import { LongitudeSchema } from "./longitude.schema";
|
|
4
|
+
/**
|
|
5
|
+
* Zod schema for validating geographic coordinates as a tuple.
|
|
6
|
+
* Geographic coordinates as [latitude, longitude].
|
|
7
|
+
*/
|
|
8
|
+
export const GeoPointSchema = z
|
|
9
|
+
.tuple([LatitudeSchema, LongitudeSchema])
|
|
10
|
+
.describe("Geographic coordinates as [latitude, longitude]");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating Geonames.org numeric IDs.
|
|
4
|
+
* Geoname IDs are positive integers, typically 1-10 digits.
|
|
5
|
+
*/
|
|
6
|
+
export declare const GeonameIdSchema: z.ZodString;
|
|
7
|
+
export type GeonameId = z.infer<typeof GeonameIdSchema>;
|
|
8
|
+
//# sourceMappingURL=geoname-id.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geoname-id.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/geoname-id.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,eAAe,aAGmB,CAAC;AAEhD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating Geonames.org numeric IDs.
|
|
4
|
+
* Geoname IDs are positive integers, typically 1-10 digits.
|
|
5
|
+
*/
|
|
6
|
+
export const GeonameIdSchema = z
|
|
7
|
+
.string()
|
|
8
|
+
.regex(/^[1-9]\d{0,9}$/, "Must be a valid Geoname ID (positive integer, max 10 digits)")
|
|
9
|
+
.describe("Geonames.org location identifier");
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating international postal/ZIP codes.
|
|
4
|
+
* Focuses on Central European formats with support for other common formats.
|
|
5
|
+
* - Germany: 12345
|
|
6
|
+
* - Poland: 12-345
|
|
7
|
+
* - France: 12345
|
|
8
|
+
* - Austria: 1234
|
|
9
|
+
* - Netherlands: 1234 AB
|
|
10
|
+
* - And more
|
|
11
|
+
*/
|
|
12
|
+
export declare const InternationalZipSchema: z.ZodString;
|
|
13
|
+
/**
|
|
14
|
+
* Country-specific ZIP code schemas for stricter validation.
|
|
15
|
+
* Focuses on Central European countries (DE, PL, FR, AT, NL) with additional support for common formats.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ZipSchemaByCountry: {
|
|
18
|
+
/**
|
|
19
|
+
* Germany PLZ: 12345 (5 digits)
|
|
20
|
+
* Most important for Central Europe
|
|
21
|
+
*/
|
|
22
|
+
readonly DE: z.ZodString;
|
|
23
|
+
/**
|
|
24
|
+
* Poland kod pocztowy: 12-345 (2 digits, hyphen, 3 digits)
|
|
25
|
+
* Most important for Central Europe
|
|
26
|
+
*/
|
|
27
|
+
readonly PL: z.ZodString;
|
|
28
|
+
/**
|
|
29
|
+
* France code postal: 12345 (5 digits)
|
|
30
|
+
* Most important for Central Europe
|
|
31
|
+
*/
|
|
32
|
+
readonly FR: z.ZodString;
|
|
33
|
+
/**
|
|
34
|
+
* Austria PLZ: 1234 (4 digits)
|
|
35
|
+
* Most important for Central Europe
|
|
36
|
+
*/
|
|
37
|
+
readonly AT: z.ZodString;
|
|
38
|
+
/**
|
|
39
|
+
* Netherlands postcode: 1234 AB (4 digits, space, 2 letters)
|
|
40
|
+
* Most important for Central Europe
|
|
41
|
+
*/
|
|
42
|
+
readonly NL: z.ZodString;
|
|
43
|
+
/**
|
|
44
|
+
* Switzerland PLZ: 1234 (4 digits)
|
|
45
|
+
*/
|
|
46
|
+
readonly CH: z.ZodString;
|
|
47
|
+
/**
|
|
48
|
+
* Italy CAP: 12345 (5 digits)
|
|
49
|
+
*/
|
|
50
|
+
readonly IT: z.ZodString;
|
|
51
|
+
/**
|
|
52
|
+
* Spain código postal: 12345 (5 digits)
|
|
53
|
+
*/
|
|
54
|
+
readonly ES: z.ZodString;
|
|
55
|
+
/**
|
|
56
|
+
* Belgium postcode: 1234 (4 digits)
|
|
57
|
+
*/
|
|
58
|
+
readonly BE: z.ZodString;
|
|
59
|
+
/**
|
|
60
|
+
* Czech Republic PSČ: 123 45 (3 digits, space, 2 digits)
|
|
61
|
+
*/
|
|
62
|
+
readonly CZ: z.ZodString;
|
|
63
|
+
/**
|
|
64
|
+
* UK postcode: SW1A 1AA
|
|
65
|
+
*/
|
|
66
|
+
readonly UK: z.ZodString;
|
|
67
|
+
};
|
|
68
|
+
export type InternationalZip = z.infer<typeof InternationalZipSchema>;
|
|
69
|
+
export type CountryCode = keyof typeof ZipSchemaByCountry;
|
|
70
|
+
/**
|
|
71
|
+
* Helper function to get the appropriate ZIP schema for a country
|
|
72
|
+
* @param countryCode - Two-letter ISO country code
|
|
73
|
+
* @returns Zod schema for the country's postal code format, or InternationalZipSchema as fallback
|
|
74
|
+
*/
|
|
75
|
+
export declare function getZipSchemaForCountry(countryCode: string): z.ZodString;
|
|
76
|
+
//# sourceMappingURL=international-zip.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"international-zip.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/international-zip.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,aAQS,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAKK,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,kBAAkB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAGvE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating international postal/ZIP codes.
|
|
4
|
+
* Focuses on Central European formats with support for other common formats.
|
|
5
|
+
* - Germany: 12345
|
|
6
|
+
* - Poland: 12-345
|
|
7
|
+
* - France: 12345
|
|
8
|
+
* - Austria: 1234
|
|
9
|
+
* - Netherlands: 1234 AB
|
|
10
|
+
* - And more
|
|
11
|
+
*/
|
|
12
|
+
export const InternationalZipSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.min(3, "Postal code must be at least 3 characters long")
|
|
15
|
+
.max(12, "Postal code must not exceed 12 characters")
|
|
16
|
+
.regex(/^[A-Z0-9\s-]+$/i, "Postal code must contain only alphanumeric characters, spaces, and hyphens")
|
|
17
|
+
.describe("International postal/ZIP code");
|
|
18
|
+
/**
|
|
19
|
+
* Country-specific ZIP code schemas for stricter validation.
|
|
20
|
+
* Focuses on Central European countries (DE, PL, FR, AT, NL) with additional support for common formats.
|
|
21
|
+
*/
|
|
22
|
+
export const ZipSchemaByCountry = {
|
|
23
|
+
/**
|
|
24
|
+
* Germany PLZ: 12345 (5 digits)
|
|
25
|
+
* Most important for Central Europe
|
|
26
|
+
*/
|
|
27
|
+
DE: z.string().regex(/^\d{5}$/, "Must be a valid German postal code (12345)"),
|
|
28
|
+
/**
|
|
29
|
+
* Poland kod pocztowy: 12-345 (2 digits, hyphen, 3 digits)
|
|
30
|
+
* Most important for Central Europe
|
|
31
|
+
*/
|
|
32
|
+
PL: z.string().regex(/^\d{2}-\d{3}$/, "Must be a valid Polish postal code (12-345)"),
|
|
33
|
+
/**
|
|
34
|
+
* France code postal: 12345 (5 digits)
|
|
35
|
+
* Most important for Central Europe
|
|
36
|
+
*/
|
|
37
|
+
FR: z.string().regex(/^\d{5}$/, "Must be a valid French postal code (12345)"),
|
|
38
|
+
/**
|
|
39
|
+
* Austria PLZ: 1234 (4 digits)
|
|
40
|
+
* Most important for Central Europe
|
|
41
|
+
*/
|
|
42
|
+
AT: z.string().regex(/^\d{4}$/, "Must be a valid Austrian postal code (1234)"),
|
|
43
|
+
/**
|
|
44
|
+
* Netherlands postcode: 1234 AB (4 digits, space, 2 letters)
|
|
45
|
+
* Most important for Central Europe
|
|
46
|
+
*/
|
|
47
|
+
NL: z.string().regex(/^\d{4}\s?[A-Z]{2}$/i, "Must be a valid Dutch postal code (1234 AB)"),
|
|
48
|
+
/**
|
|
49
|
+
* Switzerland PLZ: 1234 (4 digits)
|
|
50
|
+
*/
|
|
51
|
+
CH: z.string().regex(/^\d{4}$/, "Must be a valid Swiss postal code (1234)"),
|
|
52
|
+
/**
|
|
53
|
+
* Italy CAP: 12345 (5 digits)
|
|
54
|
+
*/
|
|
55
|
+
IT: z.string().regex(/^\d{5}$/, "Must be a valid Italian CAP (12345)"),
|
|
56
|
+
/**
|
|
57
|
+
* Spain código postal: 12345 (5 digits)
|
|
58
|
+
*/
|
|
59
|
+
ES: z.string().regex(/^\d{5}$/, "Must be a valid Spanish postal code (12345)"),
|
|
60
|
+
/**
|
|
61
|
+
* Belgium postcode: 1234 (4 digits)
|
|
62
|
+
*/
|
|
63
|
+
BE: z.string().regex(/^\d{4}$/, "Must be a valid Belgian postal code (1234)"),
|
|
64
|
+
/**
|
|
65
|
+
* Czech Republic PSČ: 123 45 (3 digits, space, 2 digits)
|
|
66
|
+
*/
|
|
67
|
+
CZ: z.string().regex(/^\d{3}\s?\d{2}$/, "Must be a valid Czech postal code (123 45)"),
|
|
68
|
+
/**
|
|
69
|
+
* UK postcode: SW1A 1AA
|
|
70
|
+
*/
|
|
71
|
+
UK: z.string().regex(/^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$/i, "Must be a valid UK postcode (SW1A 1AA)"),
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Helper function to get the appropriate ZIP schema for a country
|
|
75
|
+
* @param countryCode - Two-letter ISO country code
|
|
76
|
+
* @returns Zod schema for the country's postal code format, or InternationalZipSchema as fallback
|
|
77
|
+
*/
|
|
78
|
+
export function getZipSchemaForCountry(countryCode) {
|
|
79
|
+
const upperCode = countryCode.toUpperCase();
|
|
80
|
+
return ZipSchemaByCountry[upperCode] || InternationalZipSchema;
|
|
81
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating latitude coordinates.
|
|
4
|
+
* Latitude must be a number between -90 and 90 degrees inclusive.
|
|
5
|
+
* Maximum precision is 8 decimal places (~1.1mm accuracy).
|
|
6
|
+
*/
|
|
7
|
+
export declare const LatitudeSchema: z.ZodEffects<z.ZodNumber, number, number>;
|
|
8
|
+
export type Latitude = z.infer<typeof LatitudeSchema>;
|
|
9
|
+
//# sourceMappingURL=latitude.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latitude.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/latitude.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,eAAO,MAAM,cAAc,2CAQkB,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { hasValidDecimalPrecision } from "./coordinate-precision";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for validating latitude coordinates.
|
|
5
|
+
* Latitude must be a number between -90 and 90 degrees inclusive.
|
|
6
|
+
* Maximum precision is 8 decimal places (~1.1mm accuracy).
|
|
7
|
+
*/
|
|
8
|
+
export const LatitudeSchema = z
|
|
9
|
+
.number()
|
|
10
|
+
.min(-90, "Latitude must be greater than or equal to -90")
|
|
11
|
+
.max(90, "Latitude must be less than or equal to 90")
|
|
12
|
+
.refine((value) => hasValidDecimalPrecision(value, 8), { message: "Latitude must have at most 8 decimal places" })
|
|
13
|
+
.describe("Latitude coordinate in degrees");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating location parameter in findbyaddress endpoint.
|
|
4
|
+
* Checks for minimum length and suspicious patterns.
|
|
5
|
+
*/
|
|
6
|
+
export declare const LocationSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
+
export type Location = z.infer<typeof LocationSchema>;
|
|
8
|
+
//# sourceMappingURL=location.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/location.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;GAGG;AACH,eAAO,MAAM,cAAc,2CAWxB,CAAC;AAEJ,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { validateNoSuspiciousPatterns } from "../helpers/parameter-validation";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for validating location parameter in findbyaddress endpoint.
|
|
5
|
+
* Checks for minimum length and suspicious patterns.
|
|
6
|
+
*/
|
|
7
|
+
export const LocationSchema = z
|
|
8
|
+
.string()
|
|
9
|
+
.min(2, "Location must be at least 2 characters long")
|
|
10
|
+
.refine((value) => {
|
|
11
|
+
validateNoSuspiciousPatterns(value, "location");
|
|
12
|
+
return true;
|
|
13
|
+
}, {
|
|
14
|
+
message: "Location parameter contains suspicious patterns that are not allowed",
|
|
15
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating longitude coordinates.
|
|
4
|
+
* Longitude must be a number between -180 and 180 degrees inclusive.
|
|
5
|
+
* Maximum precision is 8 decimal places (~1.1mm accuracy).
|
|
6
|
+
*/
|
|
7
|
+
export declare const LongitudeSchema: z.ZodEffects<z.ZodNumber, number, number>;
|
|
8
|
+
export type Longitude = z.infer<typeof LongitudeSchema>;
|
|
9
|
+
//# sourceMappingURL=longitude.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"longitude.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/longitude.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,eAAO,MAAM,eAAe,2CAQkB,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { hasValidDecimalPrecision } from "./coordinate-precision";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for validating longitude coordinates.
|
|
5
|
+
* Longitude must be a number between -180 and 180 degrees inclusive.
|
|
6
|
+
* Maximum precision is 8 decimal places (~1.1mm accuracy).
|
|
7
|
+
*/
|
|
8
|
+
export const LongitudeSchema = z
|
|
9
|
+
.number()
|
|
10
|
+
.min(-180, "Longitude must be greater than or equal to -180")
|
|
11
|
+
.max(180, "Longitude must be less than or equal to 180")
|
|
12
|
+
.refine((value) => hasValidDecimalPrecision(value, 8), { message: "Longitude must have at most 8 decimal places" })
|
|
13
|
+
.describe("Longitude coordinate in degrees");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating ID parameter in community ID endpoint.
|
|
4
|
+
* Checks that ID contains only numbers and is between 3-20 characters long.
|
|
5
|
+
*/
|
|
6
|
+
export declare const NumericIdSchema: z.ZodString;
|
|
7
|
+
export type NumericId = z.infer<typeof NumericIdSchema>;
|
|
8
|
+
//# sourceMappingURL=numeric-id.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-id.schema.d.ts","sourceRoot":"","sources":["../../src/primitives/numeric-id.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,eAAe,aAIgC,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating ID parameter in community ID endpoint.
|
|
4
|
+
* Checks that ID contains only numbers and is between 3-20 characters long.
|
|
5
|
+
*/
|
|
6
|
+
export const NumericIdSchema = z
|
|
7
|
+
.string()
|
|
8
|
+
.min(3, "ID must be at least 3 characters long")
|
|
9
|
+
.max(20, "ID must not exceed 20 characters")
|
|
10
|
+
.regex(/^\d+$/, "ID must contain only numeric characters");
|