@kerekit/magyar-posta-partner-extra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v24
package/dist/main.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export type ZipCode = {
2
+ city: string;
3
+ code: string;
4
+ timeWindowId: string;
5
+ };
6
+ export declare function zipCodes(): Promise<{
7
+ timestamp: Date;
8
+ zipCodes: ZipCode[];
9
+ }>;
10
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,wBAAsB,QAAQ;;cAmBnB,OAAO,EAAE;GAGnB"}
package/dist/main.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zipCodes = zipCodes;
4
+ const fast_xml_parser_1 = require("fast-xml-parser");
5
+ const ROOT = 'http://httpmegosztas.posta.hu/PartnerExtra/Out';
6
+ const xmlParser = new fast_xml_parser_1.XMLParser({
7
+ attributeNamePrefix: '@',
8
+ ignoreAttributes: false,
9
+ parseAttributeValue: false,
10
+ parseTagValue: false,
11
+ });
12
+ async function zipCodes() {
13
+ const url = `${ROOT}/ZipCodes.xml`;
14
+ const res = await fetch(url);
15
+ if (!res.ok) {
16
+ throw new Error(`Request to URL ${url} failed with HTTP status ${res.status}`);
17
+ }
18
+ const body = await res.text();
19
+ const xml = xmlParser.parse(body);
20
+ const timestampStr = xml.zipCodes['@timestamp'];
21
+ const timestamp = new Date(timestampStr);
22
+ if (isNaN(timestamp.getTime())) {
23
+ throw new Error(`Invalid timestamp: ${timestampStr}`);
24
+ }
25
+ const data = {
26
+ timestamp,
27
+ zipCodes: xml.zipCodes.zipCode.map((zipCode) => ({
28
+ city: zipCode.city,
29
+ code: zipCode.Code,
30
+ timeWindowId: zipCode.TimeWindowID,
31
+ })),
32
+ };
33
+ return data;
34
+ }
35
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAiBA,4BAsBC;AAvCD,qDAA2C;AAE3C,MAAM,IAAI,GAAG,gDAAgD,CAAA;AAE7D,MAAM,SAAS,GAAG,IAAI,2BAAS,CAAC;IAC9B,mBAAmB,EAAG,GAAG;IACzB,gBAAgB,EAAE,KAAK;IACvB,mBAAmB,EAAE,KAAK;IAC1B,aAAa,EAAE,KAAK;CACrB,CAAC,CAAA;AAQK,KAAK,UAAU,QAAQ;IAC5B,MAAM,GAAG,GAAG,GAAG,IAAI,eAAe,CAAA;IAClC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,4BAA4B,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;IAC/C,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAA;IACxC,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,sBAAsB,YAAY,EAAE,CAAC,CAAA;IACvD,CAAC;IACD,MAAM,IAAI,GAAG;QACX,SAAS;QACT,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC;YACpD,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC,CAAc;KACjB,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@kerekit/magyar-posta-partner-extra",
3
+ "version": "0.1.0",
4
+ "description": "Library for fetching data from Magyar Posta Partner Extra service",
5
+ "main": "dist/main.js",
6
+ "types": "dist/main.d.ts",
7
+ "author": "Márton Tamás <marton.tamas@webhelyesarcu.hu>",
8
+ "license": "ISC",
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch",
12
+ "test": "vitest run"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^24.3.0",
16
+ "typescript": "^5.9.2",
17
+ "vitest": "^4.1.9"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "fast-xml-parser": "^5.9.3"
24
+ }
25
+ }
package/src/main.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { XMLParser } from 'fast-xml-parser'
2
+
3
+ const ROOT = 'http://httpmegosztas.posta.hu/PartnerExtra/Out'
4
+
5
+ const xmlParser = new XMLParser({
6
+ attributeNamePrefix : '@',
7
+ ignoreAttributes: false,
8
+ parseAttributeValue: false,
9
+ parseTagValue: false,
10
+ })
11
+
12
+ export type ZipCode = {
13
+ city: string
14
+ code: string
15
+ timeWindowId: string
16
+ }
17
+
18
+ export async function zipCodes() {
19
+ const url = `${ROOT}/ZipCodes.xml`
20
+ const res = await fetch(url)
21
+ if (!res.ok) {
22
+ throw new Error(`Request to URL ${url} failed with HTTP status ${res.status}`)
23
+ }
24
+ const body = await res.text()
25
+ const xml = xmlParser.parse(body)
26
+ const timestampStr = xml.zipCodes['@timestamp']
27
+ const timestamp = new Date(timestampStr)
28
+ if (isNaN(timestamp.getTime())) {
29
+ throw new Error(`Invalid timestamp: ${timestampStr}`)
30
+ }
31
+ const data = {
32
+ timestamp,
33
+ zipCodes: xml.zipCodes.zipCode.map((zipCode: any) => ({
34
+ city: zipCode.city,
35
+ code: zipCode.Code,
36
+ timeWindowId: zipCode.TimeWindowID,
37
+ })) as ZipCode[],
38
+ }
39
+ return data
40
+ }
@@ -0,0 +1,26 @@
1
+ import { describe, it, expect, beforeAll } from 'vitest'
2
+ import posta from '../dist/main.js'
3
+
4
+ describe('zipCodes', async () => {
5
+ let timestamp
6
+ let zipCodes
7
+
8
+ beforeAll(async () => {
9
+ ({ timestamp, zipCodes } = await posta.zipCodes())
10
+ })
11
+
12
+ test('Has valid timestamp', () => {
13
+ expect(timestamp).toBeInstanceOf(Date)
14
+ expect(timestamp.getTime()).not.toBeNaN()
15
+ })
16
+
17
+ test('Has valid zipCode objects', () => {
18
+ for (const zipCode of zipCodes) {
19
+ expect(zipCode.city).toBeTypeOf('string')
20
+ expect(zipCode.city).toBeTruthy()
21
+ expect(zipCode.code).toBeTypeOf('string')
22
+ expect(zipCode.code).toBeTruthy()
23
+ expect(zipCode.timeWindowId).toBeTypeOf('string')
24
+ }
25
+ })
26
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./src",
4
+ "outDir": "./dist",
5
+
6
+ "module": "nodenext",
7
+ "target": "esnext",
8
+ "lib": ["esnext"],
9
+ "types": ["node"],
10
+
11
+ "sourceMap": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+
15
+ "noUncheckedIndexedAccess": true,
16
+ "exactOptionalPropertyTypes": true,
17
+
18
+ "noImplicitReturns": true,
19
+ "noImplicitOverride": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noPropertyAccessFromIndexSignature": true,
24
+
25
+ "strict": true,
26
+ "jsx": "react-jsx",
27
+ "isolatedModules": true,
28
+ "noUncheckedSideEffectImports": true,
29
+ "moduleDetection": "force",
30
+ "skipLibCheck": true
31
+ }
32
+ }