@wherabouts/sdk 0.2.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.
@@ -0,0 +1,480 @@
1
+ declare const WHERABOUTS_API_VERSION: "v1";
2
+ declare const WHERABOUTS_SDK_VERSION: "0.2.0";
3
+ /**
4
+ * Error codes the API may return. The server currently emits a subset; the full
5
+ * union is declared for forward-compatibility with the Phase 2 error envelope
6
+ * (see docs/CONTRACT.md §4). Unknown codes fall back to `unknown_error`.
7
+ */
8
+ type WheraboutsErrorCode = "bad_request" | "conflict" | "forbidden" | "internal_error" | "not_found" | "rate_limited" | "timeout" | "unauthorized" | "unprocessable";
9
+ interface WheraboutsFieldError {
10
+ message: string;
11
+ path: string;
12
+ }
13
+ interface WheraboutsApiErrorPayload {
14
+ error: {
15
+ code: WheraboutsErrorCode;
16
+ message: string;
17
+ /** Correlation id; also sent as the `X-Request-Id` response header. */
18
+ request_id?: string;
19
+ /** Link to documentation for this error code. */
20
+ doc_url?: string;
21
+ /** Field-level validation detail (validation errors only). */
22
+ fields?: WheraboutsFieldError[];
23
+ };
24
+ }
25
+ interface WheraboutsClientConfig {
26
+ apiKey: string;
27
+ baseUrl?: string;
28
+ fetch?: typeof fetch;
29
+ headers?: Record<string, string>;
30
+ /** Max automatic retries for transient failures. Default 2. */
31
+ maxRetries?: number;
32
+ /** Per-request timeout in milliseconds. Default 30000. */
33
+ timeoutMs?: number;
34
+ }
35
+ /**
36
+ * Per-call overrides. Every resource method accepts an optional trailing
37
+ * `options` argument of this shape.
38
+ */
39
+ interface CallOptions {
40
+ /** Extra headers merged over (not replacing) the client headers. */
41
+ headers?: Record<string, string>;
42
+ /** Idempotency key for write requests. Auto-generated on writes if omitted. */
43
+ idempotencyKey?: string;
44
+ /** Override the client's `maxRetries` for this call. */
45
+ maxRetries?: number;
46
+ /** Abort signal — aborting rejects the call (and is not retried). */
47
+ signal?: AbortSignal;
48
+ /** Override the client's `timeoutMs` for this call. */
49
+ timeoutMs?: number;
50
+ }
51
+ type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
52
+ interface RequestOptions extends CallOptions {
53
+ body?: unknown;
54
+ method: HttpMethod;
55
+ path: string;
56
+ query?: Record<string, number | string | undefined>;
57
+ }
58
+ type Requester = <T>(opts: RequestOptions) => Promise<T>;
59
+
60
+ interface AddressSuggestion {
61
+ country: string;
62
+ formattedAddress: string;
63
+ id: number;
64
+ latitude: number;
65
+ locality: string;
66
+ longitude: number;
67
+ postcode: string;
68
+ state: string;
69
+ streetAddress: string;
70
+ }
71
+ interface AddressRecord {
72
+ buildingName: string | null;
73
+ confidence: number | null;
74
+ country: string;
75
+ flatNumber: string | null;
76
+ flatType: string | null;
77
+ gnafPid: string | null;
78
+ id: number;
79
+ latitude: number;
80
+ levelNumber: string | null;
81
+ levelType: string | null;
82
+ locality: string;
83
+ longitude: number;
84
+ numberFirst: string | null;
85
+ numberLast: string | null;
86
+ postcode: string;
87
+ state: string;
88
+ streetName: string;
89
+ streetSuffix: string | null;
90
+ streetType: string | null;
91
+ }
92
+ interface NearbyAddress {
93
+ buildingName: string | null;
94
+ country: string;
95
+ distance: number;
96
+ flatNumber: string | null;
97
+ flatType: string | null;
98
+ id: number;
99
+ latitude: number;
100
+ locality: string;
101
+ longitude: number;
102
+ numberFirst: string | null;
103
+ numberLast: string | null;
104
+ postcode: string;
105
+ state: string;
106
+ streetName: string;
107
+ streetType: string | null;
108
+ }
109
+ interface ReverseGeocodeAddress {
110
+ confidence: number | null;
111
+ country: string;
112
+ formattedAddress: string;
113
+ id: number;
114
+ latitude: number;
115
+ locality: string;
116
+ longitude: number;
117
+ postcode: string;
118
+ state: string;
119
+ streetAddress: string;
120
+ }
121
+ interface AutocompleteParams {
122
+ country?: string;
123
+ limit?: number;
124
+ q: string;
125
+ state?: string;
126
+ }
127
+ interface NearbyParams {
128
+ country?: string;
129
+ lat: number;
130
+ limit?: number;
131
+ lng: number;
132
+ radius?: number;
133
+ }
134
+ interface ReverseParams {
135
+ lat: number;
136
+ lng: number;
137
+ }
138
+ interface AutocompleteResponse {
139
+ count: number;
140
+ results: AddressSuggestion[];
141
+ }
142
+ interface NearbyResponse {
143
+ count: number;
144
+ query: {
145
+ lat: number;
146
+ lng: number;
147
+ radius: number;
148
+ };
149
+ results: NearbyAddress[];
150
+ }
151
+ interface ReverseResponse {
152
+ address: ReverseGeocodeAddress;
153
+ distance: number;
154
+ query: {
155
+ lat: number;
156
+ lng: number;
157
+ };
158
+ }
159
+ interface AddressesResource {
160
+ autocomplete(params: AutocompleteParams, options?: CallOptions): Promise<AutocompleteResponse>;
161
+ getById(id: number, options?: CallOptions): Promise<AddressRecord>;
162
+ nearby(params: NearbyParams, options?: CallOptions): Promise<NearbyResponse>;
163
+ reverse(params: ReverseParams, options?: CallOptions): Promise<ReverseResponse>;
164
+ }
165
+ declare const createAddresses: (request: Requester) => AddressesResource;
166
+
167
+ interface BoundaryCrossing {
168
+ event: "entry" | "exit";
169
+ zoneId: number;
170
+ zoneName: string;
171
+ }
172
+ interface PushLocationBody {
173
+ lat: number;
174
+ lng: number;
175
+ }
176
+ interface PushLocationResponse {
177
+ crossings: BoundaryCrossing[];
178
+ zones: number[];
179
+ }
180
+ interface DeviceZonesResponse {
181
+ deviceId: string;
182
+ latitude: number | null;
183
+ longitude: number | null;
184
+ updatedAt: string | null;
185
+ zoneIds: number[];
186
+ }
187
+ interface DevicesResource {
188
+ pushLocation(deviceId: string, body: PushLocationBody, options?: CallOptions): Promise<PushLocationResponse>;
189
+ zones(deviceId: string, options?: CallOptions): Promise<DeviceZonesResponse>;
190
+ }
191
+ declare const createDevices: (request: Requester) => DevicesResource;
192
+
193
+ /**
194
+ * Params for forward geocoding. Provide `q` for unstructured free-text search,
195
+ * OR `street` + `locality` (plus optional `state`, `postcode`, `country`) for
196
+ * structured mode. Set `structured: "true"` when using structured fields.
197
+ */
198
+ interface ForwardGeocodeParams {
199
+ /** ISO 3166-1 alpha-2 country code, e.g. "AU". */
200
+ country?: string;
201
+ /** Suburb / locality (structured mode). */
202
+ locality?: string;
203
+ /** Postcode / ZIP. */
204
+ postcode?: string;
205
+ /** Free-text address query (unstructured mode). */
206
+ q?: string;
207
+ /** State abbreviation, e.g. "NSW". */
208
+ state?: string;
209
+ /** Street address (structured mode). */
210
+ street?: string;
211
+ /** Pass `"true"` to enable structured mode. */
212
+ structured?: "true" | "false";
213
+ }
214
+ interface GeocodeAddress {
215
+ country: string;
216
+ formattedAddress: string;
217
+ id: number;
218
+ latitude: number;
219
+ locality: string;
220
+ longitude: number;
221
+ postcode: string;
222
+ state: string;
223
+ streetAddress: string;
224
+ }
225
+ interface ForwardGeocodeResponse {
226
+ address: GeocodeAddress;
227
+ matchType: "structured" | "fuzzy";
228
+ }
229
+ interface BatchSubmitBody {
230
+ addresses: string[];
231
+ }
232
+ interface BatchSubmitResponse {
233
+ inputCount: number;
234
+ jobId: string;
235
+ status: "pending" | "processing";
236
+ }
237
+ interface BatchJobStatus {
238
+ completedAt: string | null;
239
+ downloadUrl: string | null;
240
+ error: string | null;
241
+ inputCount: number;
242
+ jobId: string;
243
+ processedCount: number | null;
244
+ status: "pending" | "processing" | "completed" | "failed";
245
+ }
246
+ interface BatchResultsResponse {
247
+ count: number;
248
+ results: unknown[];
249
+ }
250
+ interface GeocodeResource {
251
+ batch: {
252
+ submit(body: BatchSubmitBody, options?: CallOptions): Promise<BatchSubmitResponse>;
253
+ poll(jobId: string, options?: CallOptions): Promise<BatchJobStatus>;
254
+ results(jobId: string, options?: CallOptions): Promise<BatchResultsResponse>;
255
+ };
256
+ forward(params: ForwardGeocodeParams, options?: CallOptions): Promise<ForwardGeocodeResponse>;
257
+ }
258
+ declare const createGeocode: (request: Requester) => GeocodeResource;
259
+
260
+ interface RegionsClassifyParams {
261
+ lat: number;
262
+ layers?: string;
263
+ lng: number;
264
+ }
265
+ interface RegionMatch {
266
+ code: string;
267
+ name: string;
268
+ }
269
+ interface RegionsClassifyResponse {
270
+ query: {
271
+ lat: number;
272
+ lng: number;
273
+ };
274
+ regions: Record<string, RegionMatch>;
275
+ }
276
+ interface RegionsResource {
277
+ classify(params: RegionsClassifyParams, options?: CallOptions): Promise<RegionsClassifyResponse>;
278
+ }
279
+ declare const createRegions: (request: Requester) => RegionsResource;
280
+
281
+ interface DirectionsParams {
282
+ from?: string;
283
+ fromAddressId?: number;
284
+ profile?: "driving";
285
+ to?: string;
286
+ toAddressId?: number;
287
+ }
288
+ interface DirectionsGeometry {
289
+ coordinates: [number, number][];
290
+ type: "LineString";
291
+ }
292
+ interface DirectionsResponse {
293
+ distance_m: number;
294
+ duration_s: number;
295
+ geometry: DirectionsGeometry;
296
+ query: {
297
+ from: {
298
+ lat: number;
299
+ lng: number;
300
+ };
301
+ profile: string;
302
+ to: {
303
+ lat: number;
304
+ lng: number;
305
+ };
306
+ };
307
+ }
308
+ interface RoutingResource {
309
+ directions(params: DirectionsParams, options?: CallOptions): Promise<DirectionsResponse>;
310
+ }
311
+ declare const createRouting: (request: Requester) => RoutingResource;
312
+
313
+ type WebhookEvent = "entry" | "exit";
314
+ interface CreateWebhookBody {
315
+ events?: WebhookEvent[];
316
+ url: string;
317
+ zoneId?: number;
318
+ }
319
+ interface WebhookSubscription {
320
+ active: boolean;
321
+ createdAt: string;
322
+ events: WebhookEvent[];
323
+ id: number;
324
+ url: string;
325
+ zoneId: number | null;
326
+ }
327
+ interface CreateWebhookResponse extends WebhookSubscription {
328
+ secret: string;
329
+ }
330
+ interface WebhookListItem extends WebhookSubscription {
331
+ failing: boolean;
332
+ }
333
+ interface ListWebhooksResponse {
334
+ count: number;
335
+ results: WebhookListItem[];
336
+ }
337
+ interface DeleteWebhookResponse {
338
+ deleted: true;
339
+ id: number;
340
+ }
341
+ interface ReactivateWebhookResponse {
342
+ id: number;
343
+ reactivated: true;
344
+ }
345
+ interface WebhooksResource {
346
+ create(body: CreateWebhookBody, options?: CallOptions): Promise<CreateWebhookResponse>;
347
+ delete(id: number, options?: CallOptions): Promise<DeleteWebhookResponse>;
348
+ list(options?: CallOptions): Promise<ListWebhooksResponse>;
349
+ reactivate(id: number, options?: CallOptions): Promise<ReactivateWebhookResponse>;
350
+ }
351
+ declare const createWebhooks: (request: Requester) => WebhooksResource;
352
+
353
+ interface ZoneRecord {
354
+ createdAt: string;
355
+ description: string | null;
356
+ id: number;
357
+ metadata: Record<string, unknown> | null;
358
+ name: string;
359
+ projectId: string;
360
+ updatedAt: string;
361
+ }
362
+ interface ZoneWithGeometry extends ZoneRecord {
363
+ geometry: {
364
+ type: string;
365
+ coordinates: number[][][];
366
+ };
367
+ }
368
+ interface GeoJsonPolygon {
369
+ coordinates: number[][][];
370
+ type: "Polygon";
371
+ }
372
+ interface ZoneListParams {
373
+ limit?: number;
374
+ page?: number;
375
+ }
376
+ interface ZoneContainsParams {
377
+ lat: number;
378
+ lng: number;
379
+ }
380
+ interface ZoneAddressesParams {
381
+ limit?: number;
382
+ page?: number;
383
+ }
384
+ interface ZoneCreateBody {
385
+ description?: string;
386
+ geometry: GeoJsonPolygon;
387
+ metadata?: Record<string, unknown>;
388
+ name: string;
389
+ }
390
+ interface ZoneUpdateBody {
391
+ description?: string;
392
+ geometry?: GeoJsonPolygon;
393
+ metadata?: Record<string, unknown>;
394
+ name?: string;
395
+ }
396
+ interface ZoneListResponse {
397
+ count: number;
398
+ page: number;
399
+ zones: ZoneRecord[];
400
+ }
401
+ interface ZoneDeleteResponse {
402
+ success: true;
403
+ }
404
+ interface ZoneContainsResponse {
405
+ count: number;
406
+ query: {
407
+ lat: number;
408
+ lng: number;
409
+ };
410
+ zones: ZoneRecord[];
411
+ }
412
+ interface ZoneAddressesResponse {
413
+ count: number;
414
+ query: {
415
+ id: number;
416
+ limit: number;
417
+ page: number;
418
+ };
419
+ results: Array<{
420
+ buildingName: string | null;
421
+ country: string;
422
+ flatNumber: string | null;
423
+ flatType: string | null;
424
+ id: number;
425
+ latitude: number;
426
+ locality: string;
427
+ longitude: number;
428
+ numberFirst: string | null;
429
+ numberLast: string | null;
430
+ postcode: string;
431
+ state: string;
432
+ streetName: string;
433
+ streetType: string | null;
434
+ }>;
435
+ truncated: boolean;
436
+ }
437
+ interface ZonesResource {
438
+ addresses(id: number, params?: ZoneAddressesParams, options?: CallOptions): Promise<ZoneAddressesResponse>;
439
+ contains(params: ZoneContainsParams, options?: CallOptions): Promise<ZoneContainsResponse>;
440
+ create(body: ZoneCreateBody, options?: CallOptions): Promise<ZoneRecord>;
441
+ delete(id: number, options?: CallOptions): Promise<ZoneDeleteResponse>;
442
+ get(id: number, options?: CallOptions): Promise<ZoneWithGeometry>;
443
+ list(params?: ZoneListParams, options?: CallOptions): Promise<ZoneListResponse>;
444
+ update(id: number, body: ZoneUpdateBody, options?: CallOptions): Promise<ZoneRecord>;
445
+ }
446
+ declare const createZones: (request: Requester) => ZonesResource;
447
+
448
+ interface WheraboutsClient {
449
+ addresses: AddressesResource;
450
+ devices: DevicesResource;
451
+ geocode: GeocodeResource;
452
+ regions: RegionsResource;
453
+ routing: RoutingResource;
454
+ webhooks: WebhooksResource;
455
+ zones: ZonesResource;
456
+ }
457
+ declare const createWheraboutsClient: (config: WheraboutsClientConfig) => WheraboutsClient;
458
+
459
+ declare class WheraboutsApiError extends Error {
460
+ readonly code: WheraboutsErrorCode | "unknown_error";
461
+ readonly payload: WheraboutsApiErrorPayload | null;
462
+ readonly status: number;
463
+ /** Correlation id from the `X-Request-Id` header or error body, if present. */
464
+ readonly requestId: string | null;
465
+ /** Documentation link for this error, if the API provided one. */
466
+ readonly docUrl: string | null;
467
+ /** Field-level validation detail, if the API provided any. */
468
+ readonly fields: WheraboutsFieldError[] | null;
469
+ constructor(options: {
470
+ code?: WheraboutsApiError["code"];
471
+ docUrl?: string | null;
472
+ fields?: WheraboutsFieldError[] | null;
473
+ message: string;
474
+ payload?: WheraboutsApiErrorPayload | null;
475
+ requestId?: string | null;
476
+ status: number;
477
+ });
478
+ }
479
+
480
+ export { type AddressRecord, type AddressSuggestion, type AddressesResource, type AutocompleteParams, type AutocompleteResponse, type BatchJobStatus, type BatchResultsResponse, type BatchSubmitBody, type BatchSubmitResponse, type BoundaryCrossing, type CallOptions, type CreateWebhookBody, type CreateWebhookResponse, type DeleteWebhookResponse, type DeviceZonesResponse, type DevicesResource, type DirectionsGeometry, type DirectionsParams, type DirectionsResponse, type ForwardGeocodeParams, type ForwardGeocodeResponse, type GeoJsonPolygon, type GeocodeAddress, type GeocodeResource, type ListWebhooksResponse, type NearbyAddress, type NearbyParams, type NearbyResponse, type PushLocationBody, type PushLocationResponse, type ReactivateWebhookResponse, type RegionMatch, type RegionsClassifyParams, type RegionsClassifyResponse, type RegionsResource, type ReverseGeocodeAddress, type ReverseParams, type ReverseResponse, type RoutingResource, WHERABOUTS_API_VERSION, WHERABOUTS_SDK_VERSION, type WebhookEvent, type WebhookListItem, type WebhookSubscription, type WebhooksResource, WheraboutsApiError, type WheraboutsApiErrorPayload, type WheraboutsClient, type WheraboutsClientConfig, type WheraboutsErrorCode, type WheraboutsFieldError, type ZoneAddressesParams, type ZoneAddressesResponse, type ZoneContainsParams, type ZoneContainsResponse, type ZoneCreateBody, type ZoneDeleteResponse, type ZoneListParams, type ZoneListResponse, type ZoneRecord, type ZoneUpdateBody, type ZoneWithGeometry, type ZonesResource, createAddresses, createDevices, createGeocode, createRegions, createRouting, createWebhooks, createWheraboutsClient, createZones };