zet-api 1.0.0 → 1.0.2

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.
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GTFSFeedInfoSchema = exports.GTFSShapePointSchema = exports.GTFSStopTimeSchema = exports.GTFSTripSchema = exports.GTFSStopSchema = exports.GTFSRouteSchema = exports.AgencySchema = void 0;
4
- const constants_1 = require("./constants");
5
- const zod_1 = require("zod");
6
- exports.AgencySchema = zod_1.z.object({
7
- agencyId: zod_1.z.string(),
8
- agencyName: zod_1.z.string(),
9
- agencyUrl: zod_1.z.string().url(),
10
- agencyTimezone: zod_1.z.string(),
11
- agencyLang: zod_1.z.string().optional(),
12
- agencyPhone: zod_1.z.string().optional(),
13
- agencyFareUrl: zod_1.z.string().url().optional(),
14
- });
15
- exports.GTFSRouteSchema = zod_1.z.object({
16
- routeId: zod_1.z.number(),
17
- agencyId: zod_1.z.string(),
18
- routeShortName: zod_1.z.string(),
19
- routeLongName: zod_1.z.string(),
20
- routeDesc: zod_1.z.string().optional(),
21
- routeType: zod_1.z.nativeEnum(constants_1.RouteTypeEnum), // 0 = tram, 3 = bus (GTFS standard)
22
- });
23
- exports.GTFSStopSchema = zod_1.z.object({
24
- stopId: zod_1.z.string(),
25
- stopCode: zod_1.z.string().optional(),
26
- stopName: zod_1.z.string(),
27
- stopDesc: zod_1.z.string().optional(),
28
- stopLat: zod_1.z.number(),
29
- stopLon: zod_1.z.number(),
30
- zoneId: zod_1.z.string().optional(),
31
- stopUrl: zod_1.z.string().optional(),
32
- locationType: zod_1.z.nativeEnum(constants_1.LocationTypeEnum).default(constants_1.LocationTypeEnum.StopPlatform),
33
- parentStation: zod_1.z.string().optional(),
34
- });
35
- exports.GTFSTripSchema = zod_1.z.object({
36
- routeId: zod_1.z.number(),
37
- serviceId: zod_1.z.string(),
38
- tripId: zod_1.z.string(),
39
- tripHeadsign: zod_1.z.string().optional(),
40
- tripShortName: zod_1.z.string().optional(),
41
- directionId: zod_1.z.number().min(0).max(1), // 0 = outbound (to destination), 1 = inbound (return trip)
42
- blockId: zod_1.z.string().optional(),
43
- shapeId: zod_1.z.string(),
44
- });
45
- exports.GTFSStopTimeSchema = zod_1.z.object({
46
- tripId: zod_1.z.string(),
47
- arrivalTime: zod_1.z.string(), // HH:MM:SS format (can exceed 24:00:00 for trips past midnight, e.g., 25:30:00)
48
- departureTime: zod_1.z.string(), // HH:MM:SS format (same rules as arrivalTime),
49
- stopId: zod_1.z.string(),
50
- stopSequence: zod_1.z.number(),
51
- stopHeadsign: zod_1.z.string().optional(),
52
- pickupType: zod_1.z.number().optional().default(0), // 0 = regular pickup, 1 = no pickup, 2 = phone agency, 3 = coordinate with driver
53
- dropOffType: zod_1.z.number().optional().default(0), // 0 = regular drop-off, 1 = no drop-off, 2 = phone agency, 3 = coordinate with driver
54
- shapeDistTraveled: zod_1.z.number().optional(),
55
- });
56
- exports.GTFSShapePointSchema = zod_1.z.object({
57
- shapeId: zod_1.z.string(),
58
- shapePtLat: zod_1.z.number(),
59
- shapePtLon: zod_1.z.number(),
60
- shapePtSequence: zod_1.z.number(),
61
- shapeDistTraveled: zod_1.z.number().optional(),
62
- });
63
- exports.GTFSFeedInfoSchema = zod_1.z.object({
64
- feedPublisherName: zod_1.z.string(),
65
- feedPublisherUrl: zod_1.z.string().url(),
66
- feedLang: zod_1.z.string(), // ISO 639-1 language code, e.g., 'hr' for Croatian
67
- feedStartDate: zod_1.z.string().optional(), // YYYYMMDD format
68
- feedEndDate: zod_1.z.string().optional(), // YYYYMMDD format
69
- feedVersion: zod_1.z.string().optional(),
70
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("./index");
4
- /**
5
- * Example: Live data polling for selected routes
6
- * Similar to how the ZET web/mobile app continuously refreshes trip stop times
7
- */
8
- async function pollLiveData() {
9
- const manager = new index_1.ZetManager(60000); // 1 minute cache for static data
10
- // Example: Monitor tram line 6
11
- const routeId = 6;
12
- let pollInterval;
13
- console.log(`Starting live polling for route ${routeId}...\n`);
14
- // Option 1: Poll all active trips on the route
15
- async function pollFullRoute() {
16
- try {
17
- const liveData = await manager.getLiveTripsForRoute(routeId);
18
- console.log(`[${new Date().toLocaleTimeString()}] Active trips: ${liveData.size}`);
19
- for (const [tripId, stopTimes] of liveData.entries()) {
20
- const firstStop = stopTimes[0];
21
- if (firstStop) {
22
- console.log(` Trip ${tripId}: ${firstStop.trip.headsign}`);
23
- console.log(` Next stop: ${firstStop.stop.stopName}`);
24
- console.log(` ETA: ${firstStop.expectedArrivalDateTime.toLocaleTimeString()}`);
25
- // Extract vehicle positions
26
- for (const vehicle of firstStop.trip.vehicles) {
27
- if (vehicle.position) {
28
- console.log(` Vehicle ${vehicle.id}: ${vehicle.position.latitude}, ${vehicle.position.longitude}`);
29
- }
30
- }
31
- }
32
- }
33
- console.log('');
34
- }
35
- catch (error) {
36
- console.error('Error polling route:', error);
37
- }
38
- }
39
- // Option 2: Poll specific trip IDs (more efficient)
40
- async function pollSpecificTrips() {
41
- try {
42
- // Get active trip IDs first
43
- const tripIds = await manager.getActiveTripIds(routeId);
44
- console.log(`[${new Date().toLocaleTimeString()}] Active trip IDs:`, tripIds);
45
- // Poll each trip individually (like the real app does)
46
- const results = await Promise.allSettled(tripIds.map((tripId) => manager.getTripStopTimes({ tripId, daysFromToday: 0 })));
47
- results.forEach((result, index) => {
48
- if (result.status === 'fulfilled') {
49
- const stopTimes = result.value;
50
- const firstStop = stopTimes[0];
51
- if (firstStop) {
52
- console.log(` Trip ${tripIds[index]}: ${firstStop.stop.stopName} @ ${firstStop.expectedArrivalDateTime.toLocaleTimeString()}`);
53
- }
54
- }
55
- });
56
- console.log('');
57
- }
58
- catch (error) {
59
- console.error('Error polling trips:', error);
60
- }
61
- }
62
- // Start polling every 10 seconds (adjust as needed)
63
- pollInterval = setInterval(pollFullRoute, 10000);
64
- // Initial poll
65
- await pollFullRoute();
66
- // Cleanup after 2 minutes (for demo purposes)
67
- setTimeout(() => {
68
- clearInterval(pollInterval);
69
- console.log('Polling stopped.');
70
- process.exit(0);
71
- }, 120000);
72
- }
73
- // Example: Monitor multiple routes simultaneously
74
- async function pollMultipleRoutes() {
75
- const manager = new index_1.ZetManager(60000);
76
- const routeIds = [6, 11, 13]; // Multiple tram lines
77
- console.log(`Monitoring routes: ${routeIds.join(', ')}\n`);
78
- async function pollAll() {
79
- const timestamp = new Date().toLocaleTimeString();
80
- console.log(`[${timestamp}] Polling ${routeIds.length} routes...`);
81
- const results = await Promise.allSettled(routeIds.map((routeId) => manager.getLiveTripsForRoute(routeId)));
82
- results.forEach((result, index) => {
83
- if (result.status === 'fulfilled') {
84
- const routeId = routeIds[index];
85
- const liveData = result.value;
86
- console.log(` Route ${routeId}: ${liveData.size} active trips`);
87
- }
88
- });
89
- console.log('');
90
- }
91
- // Poll every 15 seconds
92
- const interval = setInterval(pollAll, 15000);
93
- await pollAll();
94
- // Cleanup
95
- setTimeout(() => {
96
- clearInterval(interval);
97
- process.exit(0);
98
- }, 60000);
99
- }
100
- // Run the example
101
- if (require.main === module) {
102
- // Choose which example to run:
103
- pollLiveData();
104
- // pollMultipleRoutes();
105
- }
package/dist/test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/test.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const manager_1 = require("./core/manager");
4
- const zet = new manager_1.ZetManager();
5
- const latestAccessToken = '';
6
- const latestRefreshToken = '';
7
- async function main() {
8
- const loginData = await zet.authManager.login({
9
- username: 'robot@crni.xyz',
10
- password: '#NZsIlVQP5IwT#3V5K5%iVS15',
11
- accessToken: latestAccessToken,
12
- refreshToken: latestRefreshToken,
13
- });
14
- console.log('Login successful. Refresh token:', loginData.refreshToken);
15
- const routes = await zet.getRoutes();
16
- console.log(`Fetched ${routes.length} routes.`);
17
- const gkZagreb = routes.find((r) => r.id === 4);
18
- if (!gkZagreb)
19
- throw new Error('Route not found.');
20
- console.log(`Fetching live trips for route: ${gkZagreb.shortName} - ${gkZagreb.longName}`);
21
- const liveData = await zet.getLiveTripsForRoute(gkZagreb.id);
22
- console.log(`There are currently ${liveData.size} active trips on this route.`);
23
- for (const [tripId, stopTimes] of liveData.entries()) {
24
- const nextStop = stopTimes.find((st) => !st.isArrived);
25
- if (nextStop) {
26
- console.log(`Trip ${tripId} next stop: ${nextStop.stopName} at ${new Date(nextStop.expectedArrivalDateTime).toLocaleTimeString()}`);
27
- }
28
- else {
29
- console.log(`Trip ${tripId} has arrived at all stops.`);
30
- }
31
- }
32
- }
33
- main().catch((err) => {
34
- console.error(err);
35
- });
package/dist/text.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/text.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const manager_1 = require("./core/manager");
4
- const zet = new manager_1.ZetManager();
5
- const latestAccessToken = '';
6
- const latestRefreshToken = '';
7
- async function main() {
8
- const loginData = await zet.authManager.login({
9
- username: 'robot@crni.xyz',
10
- password: '#NZsIlVQP5IwT#3V5K5%iVS15',
11
- accessToken: latestAccessToken,
12
- refreshToken: latestRefreshToken,
13
- });
14
- console.log('Login successful. Refresh token:', loginData.refreshToken);
15
- const routes = await zet.getRoutes();
16
- console.log(`Fetched ${routes.length} routes.`);
17
- const gkZagreb = routes.find((r) => r.id === 4);
18
- if (!gkZagreb)
19
- throw new Error('Route not found.');
20
- console.log(`Fetching live trips for route: ${gkZagreb.shortName} - ${gkZagreb.longName}`);
21
- const liveData = await zet.getLiveTripsForRoute(gkZagreb.id);
22
- console.log(`There are currently ${liveData.size} active trips on this route.`);
23
- for (const [tripId, stopTimes] of liveData.entries()) {
24
- const nextStop = stopTimes.find((st) => !st.isArrived);
25
- if (nextStop) {
26
- console.log(`Trip ${tripId} next stop: ${nextStop.stopName} at ${new Date(nextStop.expectedArrivalDateTime).toLocaleTimeString()}`);
27
- }
28
- else {
29
- console.log(`Trip ${tripId} has arrived at all stops.`);
30
- }
31
- }
32
- }
33
- main().catch((err) => {
34
- console.error(err);
35
- });