geo-engine-node 2.0.0 → 3.0.0-rc.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/dist/index.d.ts CHANGED
@@ -1,134 +1,5 @@
1
- /**
2
- * Detailed error metadata returned by GeoEngine api-service.
3
- */
4
- interface SpatialErrorDetail {
5
- '@type'?: string;
6
- reason?: string;
7
- domain?: string;
8
- metadata?: Record<string, string>;
9
- }
10
- /**
11
- * Base error class for all GeoEngine SDK exceptions.
12
- */
13
- declare class GeoEngineError extends Error {
14
- constructor(message: string);
15
- }
16
- /**
17
- * Error thrown when an operation is attempted on a closed client instance.
18
- * Equivalent to Go's ErrClientClosed.
19
- */
20
- declare class ClientClosedError extends GeoEngineError {
21
- constructor(message?: string);
22
- }
23
- /**
24
- * Error thrown when a client-side parameter validation fails.
25
- */
26
- declare class ValidationError extends GeoEngineError {
27
- constructor(message: string);
28
- }
29
- /**
30
- * Error thrown when device_id is missing or empty.
31
- * Equivalent to Go's ErrDeviceIDRequired.
32
- */
33
- declare class DeviceIDRequiredError extends ValidationError {
34
- constructor(message?: string);
35
- }
36
- /**
37
- * Error thrown when a geofence_id is missing or empty.
38
- * Equivalent to Go's ErrGeofenceIDRequired.
39
- */
40
- declare class GeofenceIDRequiredError extends ValidationError {
41
- constructor(message?: string);
42
- }
43
- /**
44
- * Error thrown when latitude falls outside the valid range [-90, 90].
45
- * Equivalent to Go's ErrInvalidLatitude.
46
- */
47
- declare class InvalidLatitudeError extends ValidationError {
48
- constructor(message?: string);
49
- }
50
- /**
51
- * Error thrown when longitude falls outside the valid range [-180, 180].
52
- * Equivalent to Go's ErrInvalidLongitude.
53
- */
54
- declare class InvalidLongitudeError extends ValidationError {
55
- constructor(message?: string);
56
- }
57
- /**
58
- * Error thrown when coordinate polygon validation fails.
59
- * Equivalent to Go's ErrInvalidCoordinates.
60
- */
61
- declare class InvalidCoordinatesError extends ValidationError {
62
- constructor(message?: string);
63
- }
64
- /**
65
- * Represents an HTTP error returned by the GeoEngine REST or Management API.
66
- * Equivalent to Go's APIError.
67
- */
68
- declare class APIError extends GeoEngineError {
69
- readonly statusCode: number;
70
- constructor(statusCode: number, message: string);
71
- }
72
- /**
73
- * Represents a structured error returned by GeoEngine api-service.
74
- * Equivalent to Go's SpatialAPIError.
75
- */
76
- declare class SpatialAPIError extends APIError {
77
- readonly code: string;
78
- readonly statusText?: string;
79
- readonly details: SpatialErrorDetail[];
80
- constructor(statusCode: number, code: string, message: string, statusText?: string, details?: SpatialErrorDetail[]);
81
- /**
82
- * Returns true if the error indicates the geofence or resource was not found.
83
- */
84
- isNotFound(): boolean;
85
- /**
86
- * Returns true if the error indicates quota limit was hit.
87
- */
88
- isQuotaExceeded(): boolean;
89
- /**
90
- * Returns true if authentication failed.
91
- */
92
- isUnauthorized(): boolean;
93
- /**
94
- * Returns true if access to the requested resource is forbidden.
95
- */
96
- isForbidden(): boolean;
97
- }
98
- /**
99
- * Specific error thrown when a geofence is not found (204 or 404).
100
- * Equivalent to Go's ErrGeofenceNotFound.
101
- */
102
- declare class GeofenceNotFoundError extends SpatialAPIError {
103
- constructor(message?: string, statusCode?: number, details?: SpatialErrorDetail[]);
104
- }
105
- /**
106
- * Specific error thrown when request quota limit is exceeded (HTTP 402 or 429).
107
- * Equivalent to Go's ErrQuotaExceeded.
108
- */
109
- declare class QuotaExceededError extends SpatialAPIError {
110
- constructor(message?: string, statusCode?: number, details?: SpatialErrorDetail[]);
111
- }
112
- /**
113
- * Specific error thrown when API authentication fails (HTTP 401).
114
- * Equivalent to Go's ErrUnauthorized.
115
- */
116
- declare class AuthenticationError extends SpatialAPIError {
117
- constructor(message?: string, statusCode?: number, details?: SpatialErrorDetail[]);
118
- }
119
- /**
120
- * Specific error thrown when access is forbidden (HTTP 403).
121
- * Equivalent to Go's ErrForbidden.
122
- */
123
- declare class ForbiddenError extends SpatialAPIError {
124
- constructor(message?: string, statusCode?: number, details?: SpatialErrorDetail[]);
125
- }
126
- /**
127
- * Error thrown when a network request exceeds its deadline or timeout limit.
128
- */
129
- declare class TimeoutError extends GeoEngineError {
130
- constructor(timeoutMs: number);
131
- }
1
+ import { o as IdentityService } from './errors-C5S_d0Ca.js';
2
+ export { A as APIError, w as APIServiceError, x as AuthenticationError, C as Challenge, y as ClientClosedError, D as Decision, z as DeviceIDRequiredError, B as EmailRequiredError, E as EvaluateMeta, b as EvaluateOptions, c as EvaluateReason, d as EvaluateRequest, e as EvaluateResponse, f as EvaluateSignal, F as FallbackDecision, g as FallbackReason, H as ForbiddenError, J as GeoEngineError, O as GeofenceIDRequiredError, P as GeofenceNotFoundError, h as IdentityContext, i as IdentityDecision, j as IdentityErrorFields, l as IdentityIntegrationError, m as IdentityIntegrationReason, n as IdentityLocation, p as IdentityServiceConfig, q as IdentitySubject, r as IdentityTransientError, s as IdentityTransientReason, Q as InvalidCoordinatesError, T as InvalidLatitudeError, U as InvalidLongitudeError, V as InvitationPendingError, K as KnownDecision, t as KnownSignal, W as LastAdminError, X as LastSubjectError, L as LocationSource, M as MetaSource, Y as QuotaExceededError, R as ReputationStatus, Z as RoleRequiredError, _ as RuleIDRequiredError, $ as RuleNameRequiredError, a0 as RuleNotFoundError, u as RuleRef, S as ShadowMatch, a1 as SpatialAPIError, a2 as SpatialErrorDetail, a3 as TimeoutError, a4 as UserAlreadyExistsError, a5 as UserIDRequiredError, a6 as UserNotFoundError, a7 as ValidationError, v as isTransient } from './errors-C5S_d0Ca.js';
132
3
 
133
4
  /**
134
5
  * Configuration options for the GeoEngine Client.
@@ -170,6 +41,11 @@ interface GeoEngineOptions {
170
41
  * HTTP request timeout in milliseconds. Default: 10000ms (10 seconds).
171
42
  */
172
43
  timeout?: number;
44
+ /**
45
+ * Total deadline in milliseconds for GeoIdentity `/v1/evaluate` calls (including retry).
46
+ * Default: 500ms.
47
+ */
48
+ identityTimeoutMs?: number;
173
49
  /**
174
50
  * Maximum number of automatic retries on network failures or 429/5xx status codes.
175
51
  * Default: 2.
@@ -351,15 +227,21 @@ interface RequestOptions {
351
227
  body?: unknown;
352
228
  timeout?: number;
353
229
  isSpatial?: boolean;
230
+ /**
231
+ * Marks a Users / GeoIdentity call: the `{ success, data }` envelope is unwrapped,
232
+ * errors are parsed into APIServiceError subclasses, and only GET requests are
233
+ * retried automatically (writes such as invitations must not be sent twice).
234
+ */
235
+ isApiService?: boolean;
354
236
  }
355
237
  interface HttpClientConfig {
356
- apiKey: string;
357
238
  jwtToken?: string;
358
239
  environment: string;
359
240
  managementUrl: string;
360
241
  ingestUrl: string;
361
242
  apiServiceUrl: string;
362
243
  timeout: number;
244
+ identityTimeoutMs: number;
363
245
  maxRetries: number;
364
246
  batchSize: number;
365
247
  flushInterval: number;
@@ -371,15 +253,163 @@ interface HttpClientConfig {
371
253
  * timeouts via AbortController, and exponential backoff retries.
372
254
  */
373
255
  declare class HttpClient {
256
+ #private;
374
257
  private readonly config;
375
258
  constructor(options?: GeoEngineOptions);
376
259
  get options(): Readonly<HttpClientConfig>;
260
+ toJSON(): Record<string, unknown>;
377
261
  /**
378
262
  * Executes an HTTP request with timeout, authentication headers and exponential backoff retry.
379
263
  */
380
264
  request<T>(opts: RequestOptions): Promise<T>;
381
265
  }
382
266
 
267
+ /** Verdict applied when a GeoIdentity rule matches. */
268
+ declare const RuleActions: {
269
+ readonly Allow: "ALLOW";
270
+ readonly Block: "BLOCK";
271
+ readonly Challenge: "CHALLENGE";
272
+ };
273
+ type RuleAction = (typeof RuleActions)[keyof typeof RuleActions];
274
+ /** Who a GeoIdentity rule applies to. `All` applies the rule to every member of the organization. */
275
+ declare const SubjectTypes: {
276
+ readonly User: "USER";
277
+ readonly Role: "ROLE";
278
+ readonly Device: "DEVICE";
279
+ readonly All: "ALL";
280
+ };
281
+ type SubjectType = (typeof SubjectTypes)[keyof typeof SubjectTypes];
282
+ /** Binds a rule to a subject. For SubjectTypes.All the subjectId is "*". */
283
+ interface SubjectAssignment {
284
+ subjectType: SubjectType;
285
+ subjectId: string;
286
+ }
287
+ /** GeoJSON Polygon or MultiPolygon used as a rule's spatial boundary. See polygonFromLatLng. */
288
+ type GeoLimit = {
289
+ type: 'Polygon';
290
+ coordinates: number[][][];
291
+ } | {
292
+ type: 'MultiPolygon';
293
+ coordinates: number[][][][];
294
+ };
295
+ /** A GeoIdentity access policy. */
296
+ interface Rule {
297
+ id: string;
298
+ orgId: string;
299
+ name: string;
300
+ description?: string;
301
+ priority: number;
302
+ action: RuleAction;
303
+ isActive: boolean;
304
+ whiteIpList: string[];
305
+ blackIpList: string[];
306
+ blockDatacenter: boolean;
307
+ blockTor: boolean;
308
+ riskAccepted: number;
309
+ geoLimit?: GeoLimit | null;
310
+ /** Only populated by calls that return a single rule (getRule, createRule, assignments...). */
311
+ assignedSubjects: SubjectAssignment[];
312
+ subjectsCount: number;
313
+ /** ISO 8601 timestamp. */
314
+ createdAt?: string;
315
+ /** ISO 8601 timestamp. */
316
+ updatedAt?: string;
317
+ }
318
+ /**
319
+ * Payload for GeoIdentityService.createRule.
320
+ * When assignedSubjects is empty the rule applies to the whole organization.
321
+ */
322
+ interface CreateRuleRequest {
323
+ name: string;
324
+ description?: string;
325
+ priority?: number;
326
+ action?: RuleAction;
327
+ isActive?: boolean;
328
+ /** IPs or CIDR ranges. */
329
+ whiteIpList?: string[];
330
+ /** IPs or CIDR ranges. */
331
+ blackIpList?: string[];
332
+ blockDatacenter?: boolean;
333
+ blockTor?: boolean;
334
+ riskAccepted?: number;
335
+ geoLimit?: GeoLimit;
336
+ assignedSubjects?: SubjectAssignment[];
337
+ }
338
+ /**
339
+ * Payload for GeoIdentityService.updateRule. Omitted fields are left unchanged.
340
+ * Set geoLimit to null to remove the spatial boundary.
341
+ */
342
+ interface UpdateRuleRequest {
343
+ name?: string;
344
+ description?: string;
345
+ priority?: number;
346
+ action?: RuleAction;
347
+ isActive?: boolean;
348
+ whiteIpList?: string[];
349
+ blackIpList?: string[];
350
+ blockDatacenter?: boolean;
351
+ blockTor?: boolean;
352
+ riskAccepted?: number;
353
+ geoLimit?: GeoLimit | null;
354
+ assignedSubjects?: SubjectAssignment[];
355
+ }
356
+ /** Filters GeoIdentityService.listRules. Omit isActive to return every rule. */
357
+ interface ListRulesOptions {
358
+ isActive?: boolean;
359
+ }
360
+ /**
361
+ * Manages GeoIdentity access rules and assigns them to users or to the whole organization.
362
+ * Equivalent to Go's GeoIdentityService.
363
+ */
364
+ declare class GeoIdentityService {
365
+ private readonly http;
366
+ private readonly isClosed;
367
+ constructor(http: HttpClient, isClosed?: () => boolean);
368
+ /** Creates a GeoIdentity rule. */
369
+ createRule(req: CreateRuleRequest): Promise<Rule>;
370
+ /**
371
+ * Returns the organization's rules ordered by priority.
372
+ * Use getRule to load a rule's assigned subjects.
373
+ */
374
+ listRules(opts?: ListRulesOptions): Promise<Rule[]>;
375
+ /** Returns a rule including its assigned subjects. */
376
+ getRule(ruleId: string): Promise<Rule>;
377
+ /** Partially updates a rule. */
378
+ updateRule(ruleId: string, req: UpdateRuleRequest): Promise<Rule>;
379
+ /** Deletes a rule and all of its assignments. */
380
+ deleteRule(ruleId: string): Promise<void>;
381
+ /** Applies the rule to a member of the organization. Assigning twice is a no-op. */
382
+ assignToUser(ruleId: string, userId: string): Promise<Rule>;
383
+ /** Applies the rule to every member of the organization. */
384
+ assignToOrganization(ruleId: string): Promise<Rule>;
385
+ /**
386
+ * Removes a user assignment from the rule.
387
+ * Throws LastSubjectError if it is the rule's only subject; deactivate or delete the rule instead.
388
+ */
389
+ unassignFromUser(ruleId: string, userId: string): Promise<Rule>;
390
+ /**
391
+ * Removes the organization-wide assignment from the rule.
392
+ * Throws LastSubjectError if it is the rule's only subject.
393
+ */
394
+ unassignFromOrganization(ruleId: string): Promise<Rule>;
395
+ /**
396
+ * Returns the rules that apply to a user: assigned directly, through the user's role,
397
+ * or to the whole organization.
398
+ */
399
+ listUserRules(userId: string): Promise<Rule[]>;
400
+ private changeAssignment;
401
+ private send;
402
+ }
403
+ /**
404
+ * Builds a GeoJSON Polygon for a rule's geoLimit from [lat, lng] pairs, the same order
405
+ * used by GeoEngine.createGeofence. The ring is closed automatically.
406
+ * Equivalent to Go's PolygonFromLatLng.
407
+ */
408
+ declare function polygonFromLatLng(coordinates: Array<[number, number] | number[]>): {
409
+ type: 'Polygon';
410
+ coordinates: number[][][];
411
+ };
412
+
383
413
  interface IngesterClient {
384
414
  sendLocation(deviceId: string, lat: number, lng: number): Promise<void | unknown>;
385
415
  }
@@ -526,11 +556,101 @@ declare class GeneralGeofenceCheck {
526
556
  validate(): Promise<SpatialGeneralResult>;
527
557
  }
528
558
 
559
+ /**
560
+ * Organization roles accepted by the Users service.
561
+ * The short form ("admin", "viewer", ...) is also accepted by the API.
562
+ */
563
+ declare const Roles: {
564
+ readonly Admin: "roles/geoengine.admin";
565
+ readonly Dispatcher: "roles/geoengine.dispatcher";
566
+ readonly Billing: "roles/geoengine.billing";
567
+ readonly Viewer: "roles/geoengine.viewer";
568
+ readonly Device: "roles/geoengine.device";
569
+ };
570
+ /** User status values returned by the API. */
571
+ declare const UserStatus: {
572
+ readonly Active: "active";
573
+ readonly Pending: "pending";
574
+ readonly Revoked: "revoked";
575
+ };
576
+ /** A member of the organization that owns the API key. */
577
+ interface User {
578
+ id: string;
579
+ email: string;
580
+ name: string;
581
+ role: string;
582
+ status: string;
583
+ permissions: string[];
584
+ /** ISO 8601 timestamp. */
585
+ createdAt?: string;
586
+ /** ISO 8601 timestamp. Absent if the user never signed in. */
587
+ lastLoginAt?: string;
588
+ }
589
+ /** An organization role and the permissions it grants. */
590
+ interface Role {
591
+ id: string;
592
+ permissions: string[];
593
+ }
594
+ /** Payload for UsersService.invite. */
595
+ interface InviteUserRequest {
596
+ email: string;
597
+ role: string;
598
+ /** Shown in the invitation email. Optional. */
599
+ inviterName?: string;
600
+ /** Email language: "es" (default), "en" or "pt". Optional. */
601
+ lang?: 'es' | 'en' | 'pt' | (string & {});
602
+ }
603
+ /**
604
+ * Result of UsersService.invite. The invitation email is sent by GeoEngine;
605
+ * inviteUrl is returned as well so it can be delivered through other channels.
606
+ */
607
+ interface Invitation {
608
+ email: string;
609
+ role: string;
610
+ status: string;
611
+ inviteUrl: string;
612
+ /** ISO 8601 timestamp. */
613
+ expiresAt?: string;
614
+ }
615
+ /**
616
+ * Manages organization members, roles and invitations through the api-service.
617
+ * Equivalent to Go's UsersService.
618
+ */
619
+ declare class UsersService {
620
+ private readonly http;
621
+ private readonly isClosed;
622
+ constructor(http: HttpClient, isClosed?: () => boolean);
623
+ /** Returns the members of the organization. */
624
+ list(): Promise<User[]>;
625
+ /** Returns a single member of the organization. */
626
+ get(userId: string): Promise<User>;
627
+ /** Returns the roles available to the organization and their permissions. */
628
+ listRoles(): Promise<Role[]>;
629
+ /**
630
+ * Creates an invitation and emails it to the recipient.
631
+ * Throws InvitationPendingError if a pending invitation already exists for the email,
632
+ * and UserAlreadyExistsError if the email already belongs to the organization.
633
+ */
634
+ invite(req: InviteUserRequest): Promise<Invitation>;
635
+ /**
636
+ * Changes the role of a member. The new permissions apply on the user's next sign-in.
637
+ * Throws LastAdminError if the change would leave the organization without an admin.
638
+ */
639
+ updateRole(userId: string, role: string): Promise<User>;
640
+ /**
641
+ * Revokes a member's access to the organization.
642
+ * Throws LastAdminError if the member is the last admin.
643
+ */
644
+ remove(userId: string): Promise<void>;
645
+ private send;
646
+ }
647
+
529
648
  /**
530
649
  * GeoEngine Client for interacting with GeoEngine APIs over HTTP REST.
531
650
  * Equivalent to Go's Client struct.
532
651
  */
533
652
  declare class GeoEngine {
653
+ #private;
534
654
  private readonly http;
535
655
  private isClosed;
536
656
  /**
@@ -541,6 +661,26 @@ declare class GeoEngine {
541
661
  * Alias for spatial (to maintain exact casing compatibility with Go client.Spatial).
542
662
  */
543
663
  readonly Spatial: SpatialService;
664
+ /**
665
+ * Users manages organization members, roles and invitations.
666
+ */
667
+ readonly users: UsersService;
668
+ /**
669
+ * Alias for users (matches Go client.Users).
670
+ */
671
+ readonly Users: UsersService;
672
+ /**
673
+ * GeoIdentity manages GeoIdentity access rules for users and the organization.
674
+ */
675
+ readonly geoIdentity: GeoIdentityService;
676
+ /**
677
+ * Alias for geoIdentity (matches Go client.GeoIdentity).
678
+ */
679
+ readonly GeoIdentity: GeoIdentityService;
680
+ /**
681
+ * Server-only runtime decision client for `POST /v1/evaluate`.
682
+ */
683
+ readonly identity: IdentityService;
544
684
  /**
545
685
  * Initializes a new GeoEngine client instance.
546
686
  *
@@ -549,9 +689,10 @@ declare class GeoEngine {
549
689
  */
550
690
  constructor(apiKeyOrOptions: string | GeoEngineOptions, maybeOptions?: GeoEngineOptions);
551
691
  /**
552
- * Current configuration options.
692
+ * Current configuration options (without secret apiKey).
553
693
  */
554
694
  get options(): Readonly<HttpClientConfig>;
695
+ toJSON(): Record<string, unknown>;
555
696
  /**
556
697
  * Sends device coordinates over HTTP REST.
557
698
  * Equivalent to Go's Client.SendLocation.
@@ -637,4 +778,4 @@ declare function validateAndNormalizePolygon(coordinates: Array<[number, number]
637
778
  */
638
779
  declare function generateHMACSignature(key: string, timestamp: number): string;
639
780
 
640
- export { APIError, AsyncIngester, AuthenticationError, GeoEngine as Client, ClientClosedError, DeviceIDRequiredError, ForbiddenError, GeneralGeofenceCheck, GeoEngine, GeoEngineError, type GeoEngineOptions, GeofenceIDRequiredError, type GeofenceMatch, GeofenceNotFoundError, type GeofenceRequest, type HttpClientConfig, type IngestResponse, type IngesterClient, InvalidCoordinatesError, InvalidLatitudeError, InvalidLongitudeError, type LocationPing, QuotaExceededError, SingleGeofenceCheck, SpatialAPIError, SpatialCheckBuilder, type SpatialErrorDetail, type SpatialGeneralRequest, SpatialGeneralResult, type SpatialGeneralResultData, SpatialService, type SpatialValidationRequest, SpatialValidationResult, type SpatialValidationResultData, TimeoutError, ValidationError, GeoEngine as default, generateHMACSignature, validateAndNormalizePolygon, validateCoordinates, validateDeviceId, validateGeofenceId };
781
+ export { AsyncIngester, GeoEngine as Client, type CreateRuleRequest, GeneralGeofenceCheck, GeoEngine, type GeoEngineOptions, GeoIdentityService, type GeoLimit, type GeofenceMatch, type GeofenceRequest, type HttpClientConfig, IdentityService, type IngestResponse, type IngesterClient, type Invitation, type InviteUserRequest, type ListRulesOptions, type LocationPing, type Role, Roles, type Rule, type RuleAction, RuleActions, SingleGeofenceCheck, SpatialCheckBuilder, type SpatialGeneralRequest, SpatialGeneralResult, type SpatialGeneralResultData, SpatialService, type SpatialValidationRequest, SpatialValidationResult, type SpatialValidationResultData, type SubjectAssignment, type SubjectType, SubjectTypes, type UpdateRuleRequest, type User, UserStatus, UsersService, GeoEngine as default, generateHMACSignature, polygonFromLatLng, validateAndNormalizePolygon, validateCoordinates, validateDeviceId, validateGeofenceId };