@ibicash/geolayers-sdk 1.0.2 → 1.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/dist/index.d.cts CHANGED
@@ -2,11 +2,27 @@ import { AxiosInstance } from 'axios';
2
2
  import { z } from 'zod';
3
3
  import { EventEmitter } from 'events';
4
4
 
5
+ type ApiVersion = 'v1' | 'v2';
5
6
  interface GeoLayersConfig {
7
+ /**
8
+ * Base URL of the geo-layers service (host only, no /api path).
9
+ * Example: 'http://localhost:3000' or 'https://geo.example.com'
10
+ */
6
11
  baseUrl: string;
7
12
  apiKey: string;
8
13
  timeout?: number;
9
14
  retries?: number;
15
+ /**
16
+ * Preferred API version. Default: 'v1'
17
+ * When set to 'v2', the SDK will use v2 endpoints where available,
18
+ * falling back to v1 for endpoints not yet migrated.
19
+ */
20
+ apiVersion?: ApiVersion;
21
+ /**
22
+ * Base path for API routes. Default: '/api'
23
+ * The SDK builds URLs as: baseUrl + apiBasePath + /v1 or /v2 + endpoint
24
+ */
25
+ apiBasePath?: string;
10
26
  }
11
27
  declare const DEFAULT_CONFIG: Partial<GeoLayersConfig>;
12
28
 
@@ -569,10 +585,58 @@ declare const ObservationStatsResultSchema: z.ZodObject<{
569
585
  }, z.core.$strip>;
570
586
  type ObservationStatsResult = z.infer<typeof ObservationStatsResultSchema>;
571
587
 
588
+ /**
589
+ * URL mapping for endpoints that differ between API versions.
590
+ * Use null to indicate an endpoint is not available in that version.
591
+ */
592
+ interface VersionedEndpoint {
593
+ /** v1 endpoint path (without /api/v1 prefix). Use null if not available in v1. */
594
+ v1: string | null;
595
+ /** v2 endpoint path (without /api/v2 prefix). Use null if not available in v2. */
596
+ v2: string | null;
597
+ }
598
+ /**
599
+ * Result of URL resolution, includes which version was actually selected.
600
+ */
601
+ interface ResolvedUrl {
602
+ /** Full URL path including version prefix */
603
+ url: string;
604
+ /** The API version that was selected */
605
+ version: ApiVersion;
606
+ }
572
607
  declare abstract class BaseClient {
573
608
  protected readonly http: AxiosInstance;
574
- protected readonly config: GeoLayersConfig;
609
+ protected readonly config: Required<Pick<GeoLayersConfig, 'baseUrl' | 'apiKey' | 'apiBasePath' | 'apiVersion'>> & GeoLayersConfig;
610
+ private readonly preferredVersion;
575
611
  constructor(config: GeoLayersConfig);
612
+ /**
613
+ * Returns true if the SDK prefers API v2.
614
+ */
615
+ protected get isV2(): boolean;
616
+ /**
617
+ * Returns the preferred API version.
618
+ */
619
+ protected get apiVersion(): ApiVersion;
620
+ /**
621
+ * Builds a versioned URL path.
622
+ * @param version API version to use
623
+ * @param endpoint Endpoint path (without version prefix)
624
+ */
625
+ private buildVersionedPath;
626
+ /**
627
+ * Resolves the appropriate URL based on API version and availability.
628
+ * Falls back to the other version if preferred is not available.
629
+ *
630
+ * @param endpoints Object with v1 and v2 URL paths (use null if unavailable)
631
+ * @returns ResolvedUrl with full path and selected version
632
+ * @throws Error if no endpoint is available for either version
633
+ */
634
+ protected resolveEndpoint(endpoints: VersionedEndpoint): ResolvedUrl;
635
+ /**
636
+ * Resolves URL - convenience method that returns just the URL string.
637
+ * Use resolveEndpoint() if you need to know which version was selected.
638
+ */
639
+ protected resolveUrl(endpoints: VersionedEndpoint): string;
576
640
  private setupInterceptors;
577
641
  private isRetryableError;
578
642
  private delay;
@@ -584,6 +648,17 @@ declare abstract class BaseClient {
584
648
  * Eliminates repetitive schema creation across domains.
585
649
  */
586
650
  protected parseGeoJSON<T extends z.ZodTypeAny>(data: unknown, propsSchema: T): LayerResponse<FeatureCollection<z.infer<T>>>;
651
+ /**
652
+ * Normalizes API responses to a consistent LayerResponse format.
653
+ * Handles both:
654
+ * - v1 responses: LayerResponse envelope with data field
655
+ * - v2 responses: Direct FeatureCollection
656
+ *
657
+ * @param data Raw response data from the API
658
+ * @param propsSchema Zod schema for feature properties
659
+ * @param provider Provider name to use when wrapping v2 responses
660
+ */
661
+ protected normalizeGeoJSONResponse<T extends z.ZodTypeAny>(data: unknown, propsSchema: T, provider: string): LayerResponse<FeatureCollection<z.infer<T>>>;
587
662
  }
588
663
 
589
664
  /**
@@ -742,8 +817,6 @@ declare class WeatherDomain extends BaseClient {
742
817
  /**
743
818
  * Get active stations that have reported data in the last 24 hours.
744
819
  * @param type The station network type ('iem' or 'wis2').
745
- *
746
- * Note: This endpoint returns FeatureCollection directly (not LayerResponse envelope).
747
820
  */
748
821
  getActiveStations(type: 'iem' | 'wis2'): Promise<LayerResponse<FeatureCollection<WeatherStationProps>>>;
749
822
  }
@@ -835,11 +908,6 @@ declare class ObservationsDomain extends BaseClient {
835
908
  * Convert time preset to absolute date range parameters.
836
909
  */
837
910
  private buildDateParams;
838
- /**
839
- * Parse active stations response.
840
- * The endpoint may return either a FeatureCollection directly or wrapped in LayerResponse.
841
- */
842
- private parseActiveStationsResponse;
843
911
  }
844
912
 
845
913
  /**
@@ -999,4 +1067,4 @@ declare class GeoLayersSDK {
999
1067
  constructor(config: GeoLayersConfig);
1000
1068
  }
1001
1069
 
1002
- export { type ActiveVolcanoProps, ActiveVolcanoPropsSchema, type BboxObservationsResult, BboxObservationsResultSchema, DEFAULT_CONFIG, type EarthquakeProps, EarthquakePropsSchema, type EventPayload, EventPayloadSchema, type Feature, type FeatureCollection, type FlightProps, FlightPropsSchema, type FlightScheduleResponse, FlightScheduleResponseSchema, GeoLayersApiError, type GeoLayersConfig, GeoLayersError, GeoLayersSDK, GeoLayersValidationError, type Geometry, GeometrySchema, type LatestObservationResult, LatestObservationResultSchema, type LayerMetadata, LayerMetadataSchema, LayerProvider, type LayerResponse, type MeasurementValue, MeasurementValueSchema, type ObservationProvider, ObservationProviderSchema, type ObservationQueryResult, ObservationQueryResultSchema, type ObservationStatsResult, ObservationStatsResultSchema, type StandardMeasurements, StandardMeasurementsSchema, type StandardObservation, StandardObservationSchema, type StationObservationsResult, StationObservationsResultSchema, type StormProps, StormPropsSchema, type VolcanoProps, VolcanoPropsSchema, type WeatherStationProps, WeatherStationPropsSchema, type WildfireProps, WildfirePropsSchema, createFeatureCollectionSchema, createFeatureSchema, createLayerResponseSchema, GeoLayersSDK as default };
1070
+ export { type ActiveVolcanoProps, ActiveVolcanoPropsSchema, type ApiVersion, type BboxObservationsResult, BboxObservationsResultSchema, DEFAULT_CONFIG, type EarthquakeProps, EarthquakePropsSchema, type EventPayload, EventPayloadSchema, type Feature, type FeatureCollection, type FlightProps, FlightPropsSchema, type FlightScheduleResponse, FlightScheduleResponseSchema, GeoLayersApiError, type GeoLayersConfig, GeoLayersError, GeoLayersSDK, GeoLayersValidationError, type Geometry, GeometrySchema, type LatestObservationResult, LatestObservationResultSchema, type LayerMetadata, LayerMetadataSchema, LayerProvider, type LayerResponse, type MeasurementValue, MeasurementValueSchema, type ObservationProvider, ObservationProviderSchema, type ObservationQueryResult, ObservationQueryResultSchema, type ObservationStatsResult, ObservationStatsResultSchema, type StandardMeasurements, StandardMeasurementsSchema, type StandardObservation, StandardObservationSchema, type StationObservationsResult, StationObservationsResultSchema, type StormProps, StormPropsSchema, type VolcanoProps, VolcanoPropsSchema, type WeatherStationProps, WeatherStationPropsSchema, type WildfireProps, WildfirePropsSchema, createFeatureCollectionSchema, createFeatureSchema, createLayerResponseSchema, GeoLayersSDK as default };
package/dist/index.d.ts CHANGED
@@ -2,11 +2,27 @@ import { AxiosInstance } from 'axios';
2
2
  import { z } from 'zod';
3
3
  import { EventEmitter } from 'events';
4
4
 
5
+ type ApiVersion = 'v1' | 'v2';
5
6
  interface GeoLayersConfig {
7
+ /**
8
+ * Base URL of the geo-layers service (host only, no /api path).
9
+ * Example: 'http://localhost:3000' or 'https://geo.example.com'
10
+ */
6
11
  baseUrl: string;
7
12
  apiKey: string;
8
13
  timeout?: number;
9
14
  retries?: number;
15
+ /**
16
+ * Preferred API version. Default: 'v1'
17
+ * When set to 'v2', the SDK will use v2 endpoints where available,
18
+ * falling back to v1 for endpoints not yet migrated.
19
+ */
20
+ apiVersion?: ApiVersion;
21
+ /**
22
+ * Base path for API routes. Default: '/api'
23
+ * The SDK builds URLs as: baseUrl + apiBasePath + /v1 or /v2 + endpoint
24
+ */
25
+ apiBasePath?: string;
10
26
  }
11
27
  declare const DEFAULT_CONFIG: Partial<GeoLayersConfig>;
12
28
 
@@ -569,10 +585,58 @@ declare const ObservationStatsResultSchema: z.ZodObject<{
569
585
  }, z.core.$strip>;
570
586
  type ObservationStatsResult = z.infer<typeof ObservationStatsResultSchema>;
571
587
 
588
+ /**
589
+ * URL mapping for endpoints that differ between API versions.
590
+ * Use null to indicate an endpoint is not available in that version.
591
+ */
592
+ interface VersionedEndpoint {
593
+ /** v1 endpoint path (without /api/v1 prefix). Use null if not available in v1. */
594
+ v1: string | null;
595
+ /** v2 endpoint path (without /api/v2 prefix). Use null if not available in v2. */
596
+ v2: string | null;
597
+ }
598
+ /**
599
+ * Result of URL resolution, includes which version was actually selected.
600
+ */
601
+ interface ResolvedUrl {
602
+ /** Full URL path including version prefix */
603
+ url: string;
604
+ /** The API version that was selected */
605
+ version: ApiVersion;
606
+ }
572
607
  declare abstract class BaseClient {
573
608
  protected readonly http: AxiosInstance;
574
- protected readonly config: GeoLayersConfig;
609
+ protected readonly config: Required<Pick<GeoLayersConfig, 'baseUrl' | 'apiKey' | 'apiBasePath' | 'apiVersion'>> & GeoLayersConfig;
610
+ private readonly preferredVersion;
575
611
  constructor(config: GeoLayersConfig);
612
+ /**
613
+ * Returns true if the SDK prefers API v2.
614
+ */
615
+ protected get isV2(): boolean;
616
+ /**
617
+ * Returns the preferred API version.
618
+ */
619
+ protected get apiVersion(): ApiVersion;
620
+ /**
621
+ * Builds a versioned URL path.
622
+ * @param version API version to use
623
+ * @param endpoint Endpoint path (without version prefix)
624
+ */
625
+ private buildVersionedPath;
626
+ /**
627
+ * Resolves the appropriate URL based on API version and availability.
628
+ * Falls back to the other version if preferred is not available.
629
+ *
630
+ * @param endpoints Object with v1 and v2 URL paths (use null if unavailable)
631
+ * @returns ResolvedUrl with full path and selected version
632
+ * @throws Error if no endpoint is available for either version
633
+ */
634
+ protected resolveEndpoint(endpoints: VersionedEndpoint): ResolvedUrl;
635
+ /**
636
+ * Resolves URL - convenience method that returns just the URL string.
637
+ * Use resolveEndpoint() if you need to know which version was selected.
638
+ */
639
+ protected resolveUrl(endpoints: VersionedEndpoint): string;
576
640
  private setupInterceptors;
577
641
  private isRetryableError;
578
642
  private delay;
@@ -584,6 +648,17 @@ declare abstract class BaseClient {
584
648
  * Eliminates repetitive schema creation across domains.
585
649
  */
586
650
  protected parseGeoJSON<T extends z.ZodTypeAny>(data: unknown, propsSchema: T): LayerResponse<FeatureCollection<z.infer<T>>>;
651
+ /**
652
+ * Normalizes API responses to a consistent LayerResponse format.
653
+ * Handles both:
654
+ * - v1 responses: LayerResponse envelope with data field
655
+ * - v2 responses: Direct FeatureCollection
656
+ *
657
+ * @param data Raw response data from the API
658
+ * @param propsSchema Zod schema for feature properties
659
+ * @param provider Provider name to use when wrapping v2 responses
660
+ */
661
+ protected normalizeGeoJSONResponse<T extends z.ZodTypeAny>(data: unknown, propsSchema: T, provider: string): LayerResponse<FeatureCollection<z.infer<T>>>;
587
662
  }
588
663
 
589
664
  /**
@@ -742,8 +817,6 @@ declare class WeatherDomain extends BaseClient {
742
817
  /**
743
818
  * Get active stations that have reported data in the last 24 hours.
744
819
  * @param type The station network type ('iem' or 'wis2').
745
- *
746
- * Note: This endpoint returns FeatureCollection directly (not LayerResponse envelope).
747
820
  */
748
821
  getActiveStations(type: 'iem' | 'wis2'): Promise<LayerResponse<FeatureCollection<WeatherStationProps>>>;
749
822
  }
@@ -835,11 +908,6 @@ declare class ObservationsDomain extends BaseClient {
835
908
  * Convert time preset to absolute date range parameters.
836
909
  */
837
910
  private buildDateParams;
838
- /**
839
- * Parse active stations response.
840
- * The endpoint may return either a FeatureCollection directly or wrapped in LayerResponse.
841
- */
842
- private parseActiveStationsResponse;
843
911
  }
844
912
 
845
913
  /**
@@ -999,4 +1067,4 @@ declare class GeoLayersSDK {
999
1067
  constructor(config: GeoLayersConfig);
1000
1068
  }
1001
1069
 
1002
- export { type ActiveVolcanoProps, ActiveVolcanoPropsSchema, type BboxObservationsResult, BboxObservationsResultSchema, DEFAULT_CONFIG, type EarthquakeProps, EarthquakePropsSchema, type EventPayload, EventPayloadSchema, type Feature, type FeatureCollection, type FlightProps, FlightPropsSchema, type FlightScheduleResponse, FlightScheduleResponseSchema, GeoLayersApiError, type GeoLayersConfig, GeoLayersError, GeoLayersSDK, GeoLayersValidationError, type Geometry, GeometrySchema, type LatestObservationResult, LatestObservationResultSchema, type LayerMetadata, LayerMetadataSchema, LayerProvider, type LayerResponse, type MeasurementValue, MeasurementValueSchema, type ObservationProvider, ObservationProviderSchema, type ObservationQueryResult, ObservationQueryResultSchema, type ObservationStatsResult, ObservationStatsResultSchema, type StandardMeasurements, StandardMeasurementsSchema, type StandardObservation, StandardObservationSchema, type StationObservationsResult, StationObservationsResultSchema, type StormProps, StormPropsSchema, type VolcanoProps, VolcanoPropsSchema, type WeatherStationProps, WeatherStationPropsSchema, type WildfireProps, WildfirePropsSchema, createFeatureCollectionSchema, createFeatureSchema, createLayerResponseSchema, GeoLayersSDK as default };
1070
+ export { type ActiveVolcanoProps, ActiveVolcanoPropsSchema, type ApiVersion, type BboxObservationsResult, BboxObservationsResultSchema, DEFAULT_CONFIG, type EarthquakeProps, EarthquakePropsSchema, type EventPayload, EventPayloadSchema, type Feature, type FeatureCollection, type FlightProps, FlightPropsSchema, type FlightScheduleResponse, FlightScheduleResponseSchema, GeoLayersApiError, type GeoLayersConfig, GeoLayersError, GeoLayersSDK, GeoLayersValidationError, type Geometry, GeometrySchema, type LatestObservationResult, LatestObservationResultSchema, type LayerMetadata, LayerMetadataSchema, LayerProvider, type LayerResponse, type MeasurementValue, MeasurementValueSchema, type ObservationProvider, ObservationProviderSchema, type ObservationQueryResult, ObservationQueryResultSchema, type ObservationStatsResult, ObservationStatsResultSchema, type StandardMeasurements, StandardMeasurementsSchema, type StandardObservation, StandardObservationSchema, type StationObservationsResult, StationObservationsResultSchema, type StormProps, StormPropsSchema, type VolcanoProps, VolcanoPropsSchema, type WeatherStationProps, WeatherStationPropsSchema, type WildfireProps, WildfirePropsSchema, createFeatureCollectionSchema, createFeatureSchema, createLayerResponseSchema, GeoLayersSDK as default };