geo-engine-node 2.0.0 → 2.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.cjs CHANGED
@@ -21,31 +21,50 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  APIError: () => APIError,
24
+ APIServiceError: () => APIServiceError,
24
25
  AsyncIngester: () => AsyncIngester,
25
26
  AuthenticationError: () => AuthenticationError,
26
27
  Client: () => GeoEngine,
27
28
  ClientClosedError: () => ClientClosedError,
28
29
  DeviceIDRequiredError: () => DeviceIDRequiredError,
30
+ EmailRequiredError: () => EmailRequiredError,
29
31
  ForbiddenError: () => ForbiddenError,
30
32
  GeneralGeofenceCheck: () => GeneralGeofenceCheck,
31
33
  GeoEngine: () => GeoEngine,
32
34
  GeoEngineError: () => GeoEngineError,
35
+ GeoIdentityService: () => GeoIdentityService,
33
36
  GeofenceIDRequiredError: () => GeofenceIDRequiredError,
34
37
  GeofenceNotFoundError: () => GeofenceNotFoundError,
35
38
  InvalidCoordinatesError: () => InvalidCoordinatesError,
36
39
  InvalidLatitudeError: () => InvalidLatitudeError,
37
40
  InvalidLongitudeError: () => InvalidLongitudeError,
41
+ InvitationPendingError: () => InvitationPendingError,
42
+ LastAdminError: () => LastAdminError,
43
+ LastSubjectError: () => LastSubjectError,
38
44
  QuotaExceededError: () => QuotaExceededError,
45
+ RoleRequiredError: () => RoleRequiredError,
46
+ Roles: () => Roles,
47
+ RuleActions: () => RuleActions,
48
+ RuleIDRequiredError: () => RuleIDRequiredError,
49
+ RuleNameRequiredError: () => RuleNameRequiredError,
50
+ RuleNotFoundError: () => RuleNotFoundError,
39
51
  SingleGeofenceCheck: () => SingleGeofenceCheck,
40
52
  SpatialAPIError: () => SpatialAPIError,
41
53
  SpatialCheckBuilder: () => SpatialCheckBuilder,
42
54
  SpatialGeneralResult: () => SpatialGeneralResult,
43
55
  SpatialService: () => SpatialService,
44
56
  SpatialValidationResult: () => SpatialValidationResult,
57
+ SubjectTypes: () => SubjectTypes,
45
58
  TimeoutError: () => TimeoutError,
59
+ UserAlreadyExistsError: () => UserAlreadyExistsError,
60
+ UserIDRequiredError: () => UserIDRequiredError,
61
+ UserNotFoundError: () => UserNotFoundError,
62
+ UserStatus: () => UserStatus,
63
+ UsersService: () => UsersService,
46
64
  ValidationError: () => ValidationError,
47
65
  default: () => index_default,
48
66
  generateHMACSignature: () => generateHMACSignature,
67
+ polygonFromLatLng: () => polygonFromLatLng,
49
68
  validateAndNormalizePolygon: () => validateAndNormalizePolygon,
50
69
  validateCoordinates: () => validateCoordinates,
51
70
  validateDeviceId: () => validateDeviceId,
@@ -178,6 +197,393 @@ var TimeoutError = class extends GeoEngineError {
178
197
  this.name = "TimeoutError";
179
198
  }
180
199
  };
200
+ var UserIDRequiredError = class extends ValidationError {
201
+ constructor(message = "geoengine: user_id is required") {
202
+ super(message);
203
+ this.name = "UserIDRequiredError";
204
+ }
205
+ };
206
+ var RuleIDRequiredError = class extends ValidationError {
207
+ constructor(message = "geoengine: rule_id is required") {
208
+ super(message);
209
+ this.name = "RuleIDRequiredError";
210
+ }
211
+ };
212
+ var RuleNameRequiredError = class extends ValidationError {
213
+ constructor(message = "geoengine: rule name is required") {
214
+ super(message);
215
+ this.name = "RuleNameRequiredError";
216
+ }
217
+ };
218
+ var EmailRequiredError = class extends ValidationError {
219
+ constructor(message = "geoengine: email is required") {
220
+ super(message);
221
+ this.name = "EmailRequiredError";
222
+ }
223
+ };
224
+ var RoleRequiredError = class extends ValidationError {
225
+ constructor(message = "geoengine: role is required") {
226
+ super(message);
227
+ this.name = "RoleRequiredError";
228
+ }
229
+ };
230
+ var APIServiceError = class extends APIError {
231
+ /** Machine-readable reason, e.g. "USER_NOT_FOUND". Empty when the API sent none. */
232
+ code;
233
+ /** Message returned by the API, without the SDK prefix. */
234
+ apiMessage;
235
+ details;
236
+ constructor(statusCode, code, message, details = []) {
237
+ super(statusCode, message);
238
+ this.message = code ? `geoengine: api-service error (status ${statusCode}, code ${code}): ${message}` : `geoengine: api-service error (status ${statusCode}): ${message}`;
239
+ this.name = "APIServiceError";
240
+ this.code = code;
241
+ this.apiMessage = message;
242
+ this.details = details;
243
+ }
244
+ };
245
+ var UserNotFoundError = class extends APIServiceError {
246
+ constructor(message = "user not found in organization", statusCode = 404, code = "USER_NOT_FOUND", details = []) {
247
+ super(statusCode, code, message, details);
248
+ this.name = "UserNotFoundError";
249
+ }
250
+ };
251
+ var RuleNotFoundError = class extends APIServiceError {
252
+ constructor(message = "geoidentity rule not found", statusCode = 404, code = "RULE_NOT_FOUND", details = []) {
253
+ super(statusCode, code, message, details);
254
+ this.name = "RuleNotFoundError";
255
+ }
256
+ };
257
+ var UserAlreadyExistsError = class extends APIServiceError {
258
+ constructor(message = "user already belongs to the organization", statusCode = 409, code = "USER_ALREADY_EXISTS", details = []) {
259
+ super(statusCode, code, message, details);
260
+ this.name = "UserAlreadyExistsError";
261
+ }
262
+ };
263
+ var InvitationPendingError = class extends APIServiceError {
264
+ constructor(message = "a pending invitation already exists for this email", statusCode = 409, code = "INVITATION_PENDING", details = []) {
265
+ super(statusCode, code, message, details);
266
+ this.name = "InvitationPendingError";
267
+ }
268
+ };
269
+ var LastAdminError = class extends APIServiceError {
270
+ constructor(message = "organization must keep at least one admin", statusCode = 409, code = "LAST_ADMIN", details = []) {
271
+ super(statusCode, code, message, details);
272
+ this.name = "LastAdminError";
273
+ }
274
+ };
275
+ var LastSubjectError = class extends APIServiceError {
276
+ constructor(message = "rule must keep at least one assigned subject", statusCode = 409, code = "LAST_SUBJECT", details = []) {
277
+ super(statusCode, code, message, details);
278
+ this.name = "LastSubjectError";
279
+ }
280
+ };
281
+
282
+ // src/users.ts
283
+ var Roles = {
284
+ Admin: "roles/geoengine.admin",
285
+ Dispatcher: "roles/geoengine.dispatcher",
286
+ Billing: "roles/geoengine.billing",
287
+ Viewer: "roles/geoengine.viewer",
288
+ Device: "roles/geoengine.device"
289
+ };
290
+ var UserStatus = {
291
+ Active: "active",
292
+ Pending: "pending",
293
+ Revoked: "revoked"
294
+ };
295
+ function toUser(raw) {
296
+ return {
297
+ id: raw.id,
298
+ email: raw.email,
299
+ name: raw.name,
300
+ role: raw.role,
301
+ status: raw.status,
302
+ permissions: raw.permissions ?? [],
303
+ createdAt: raw.created_at,
304
+ lastLoginAt: raw.last_login_at
305
+ };
306
+ }
307
+ function isBlank(value) {
308
+ return typeof value !== "string" || value.trim() === "";
309
+ }
310
+ function userPath(userId, suffix = "") {
311
+ if (isBlank(userId)) {
312
+ throw new UserIDRequiredError();
313
+ }
314
+ return `/api/users/${encodeURIComponent(userId.trim())}${suffix}`;
315
+ }
316
+ async function apiServiceRequest(http, isClosed, method, path, body) {
317
+ if (isClosed()) {
318
+ throw new ClientClosedError();
319
+ }
320
+ return http.request({
321
+ endpoint: `${http.options.apiServiceUrl.replace(/\/+$/, "")}${path}`,
322
+ method,
323
+ body,
324
+ isApiService: true
325
+ });
326
+ }
327
+ var UsersService = class {
328
+ constructor(http, isClosed = () => false) {
329
+ this.http = http;
330
+ this.isClosed = isClosed;
331
+ }
332
+ http;
333
+ isClosed;
334
+ /** Returns the members of the organization. */
335
+ async list() {
336
+ const raw = await this.send("GET", "/api/users");
337
+ return (raw ?? []).map(toUser);
338
+ }
339
+ /** Returns a single member of the organization. */
340
+ async get(userId) {
341
+ return toUser(await this.send("GET", userPath(userId)));
342
+ }
343
+ /** Returns the roles available to the organization and their permissions. */
344
+ async listRoles() {
345
+ const raw = await this.send(
346
+ "GET",
347
+ "/api/users/roles"
348
+ );
349
+ return (raw ?? []).map((r) => ({ id: r.id, permissions: r.permissions ?? [] }));
350
+ }
351
+ /**
352
+ * Creates an invitation and emails it to the recipient.
353
+ * Throws InvitationPendingError if a pending invitation already exists for the email,
354
+ * and UserAlreadyExistsError if the email already belongs to the organization.
355
+ */
356
+ async invite(req) {
357
+ if (isBlank(req?.email)) {
358
+ throw new EmailRequiredError();
359
+ }
360
+ if (isBlank(req.role)) {
361
+ throw new RoleRequiredError();
362
+ }
363
+ const raw = await this.send("POST", "/api/users/invite", {
364
+ email: req.email,
365
+ role: req.role,
366
+ inviter_name: req.inviterName || void 0,
367
+ lang: req.lang || void 0
368
+ });
369
+ return {
370
+ email: raw.email,
371
+ role: raw.role,
372
+ status: raw.status,
373
+ inviteUrl: raw.invite_url,
374
+ expiresAt: raw.expires_at
375
+ };
376
+ }
377
+ /**
378
+ * Changes the role of a member. The new permissions apply on the user's next sign-in.
379
+ * Throws LastAdminError if the change would leave the organization without an admin.
380
+ */
381
+ async updateRole(userId, role) {
382
+ if (isBlank(role)) {
383
+ throw new RoleRequiredError();
384
+ }
385
+ return toUser(await this.send("PATCH", userPath(userId, "/role"), { role }));
386
+ }
387
+ /**
388
+ * Revokes a member's access to the organization.
389
+ * Throws LastAdminError if the member is the last admin.
390
+ */
391
+ async remove(userId) {
392
+ await this.send("DELETE", userPath(userId));
393
+ }
394
+ send(method, path, body) {
395
+ return apiServiceRequest(this.http, this.isClosed, method, path, body);
396
+ }
397
+ };
398
+
399
+ // src/validation.ts
400
+ function validateCoordinates(lat, lng) {
401
+ if (typeof lat !== "number" || Number.isNaN(lat) || lat < -90 || lat > 90) {
402
+ throw new InvalidLatitudeError();
403
+ }
404
+ if (typeof lng !== "number" || Number.isNaN(lng) || lng < -180 || lng > 180) {
405
+ throw new InvalidLongitudeError();
406
+ }
407
+ }
408
+ function validateDeviceId(deviceId) {
409
+ if (!deviceId || typeof deviceId !== "string" || deviceId.trim() === "") {
410
+ throw new DeviceIDRequiredError();
411
+ }
412
+ return deviceId.trim();
413
+ }
414
+ function validateGeofenceId(geofenceId) {
415
+ if (!geofenceId || typeof geofenceId !== "string" || geofenceId.trim() === "") {
416
+ throw new GeofenceIDRequiredError();
417
+ }
418
+ return geofenceId.trim();
419
+ }
420
+ function validateAndNormalizePolygon(coordinates) {
421
+ if (!Array.isArray(coordinates) || coordinates.length < 3) {
422
+ throw new InvalidCoordinatesError();
423
+ }
424
+ const polygon = [];
425
+ for (const p of coordinates) {
426
+ if (!Array.isArray(p) || p.length !== 2) {
427
+ throw new ValidationError(
428
+ `geoengine: invalid coordinate format: ${JSON.stringify(p)} (expected [lat, lng])`
429
+ );
430
+ }
431
+ const lat = p[0];
432
+ const lng = p[1];
433
+ validateCoordinates(lat, lng);
434
+ polygon.push([lng, lat]);
435
+ }
436
+ const first = polygon[0];
437
+ const last = polygon[polygon.length - 1];
438
+ if (first[0] !== last[0] || first[1] !== last[1]) {
439
+ polygon.push([first[0], first[1]]);
440
+ }
441
+ return polygon;
442
+ }
443
+
444
+ // src/geoidentity.ts
445
+ var RuleActions = {
446
+ Allow: "ALLOW",
447
+ Block: "BLOCK",
448
+ Challenge: "CHALLENGE"
449
+ };
450
+ var SubjectTypes = {
451
+ User: "USER",
452
+ Role: "ROLE",
453
+ Device: "DEVICE",
454
+ All: "ALL"
455
+ };
456
+ function toRule(raw) {
457
+ return {
458
+ id: raw.id,
459
+ orgId: raw.org_id,
460
+ name: raw.name,
461
+ description: raw.description,
462
+ priority: raw.priority ?? 0,
463
+ action: raw.action,
464
+ isActive: Boolean(raw.is_active),
465
+ whiteIpList: raw.white_ip_list ?? [],
466
+ blackIpList: raw.black_ip_list ?? [],
467
+ blockDatacenter: Boolean(raw.block_datacenter),
468
+ blockTor: Boolean(raw.block_tor),
469
+ riskAccepted: raw.risk_accepted ?? 0,
470
+ geoLimit: raw.geo_limit,
471
+ assignedSubjects: (raw.assigned_subjects ?? []).map((s) => ({
472
+ subjectType: s.subject_type,
473
+ subjectId: s.subject_id
474
+ })),
475
+ subjectsCount: raw.subjects_count ?? 0,
476
+ createdAt: raw.created_at,
477
+ updatedAt: raw.updated_at
478
+ };
479
+ }
480
+ function toWire(req) {
481
+ return {
482
+ name: req.name,
483
+ description: req.description,
484
+ priority: req.priority,
485
+ action: req.action,
486
+ is_active: req.isActive,
487
+ white_ip_list: req.whiteIpList,
488
+ black_ip_list: req.blackIpList,
489
+ block_datacenter: req.blockDatacenter,
490
+ block_tor: req.blockTor,
491
+ risk_accepted: req.riskAccepted,
492
+ geo_limit: req.geoLimit,
493
+ assigned_subjects: req.assignedSubjects?.map((s) => ({
494
+ subject_type: s.subjectType,
495
+ subject_id: s.subjectId
496
+ }))
497
+ };
498
+ }
499
+ var RULES_PATH = "/api/users/geoidentity/rules";
500
+ function rulePath(ruleId, suffix = "") {
501
+ if (typeof ruleId !== "string" || ruleId.trim() === "") {
502
+ throw new RuleIDRequiredError();
503
+ }
504
+ return `${RULES_PATH}/${encodeURIComponent(ruleId.trim())}${suffix}`;
505
+ }
506
+ function requireUserId(userId) {
507
+ if (typeof userId !== "string" || userId.trim() === "") {
508
+ throw new UserIDRequiredError();
509
+ }
510
+ return userId.trim();
511
+ }
512
+ var GeoIdentityService = class {
513
+ constructor(http, isClosed = () => false) {
514
+ this.http = http;
515
+ this.isClosed = isClosed;
516
+ }
517
+ http;
518
+ isClosed;
519
+ /** Creates a GeoIdentity rule. */
520
+ async createRule(req) {
521
+ if (typeof req?.name !== "string" || req.name.trim() === "") {
522
+ throw new RuleNameRequiredError();
523
+ }
524
+ return toRule(await this.send("POST", RULES_PATH, toWire(req)));
525
+ }
526
+ /**
527
+ * Returns the organization's rules ordered by priority.
528
+ * Use getRule to load a rule's assigned subjects.
529
+ */
530
+ async listRules(opts = {}) {
531
+ const query = typeof opts.isActive === "boolean" ? `?is_active=${opts.isActive}` : "";
532
+ const raw = await this.send("GET", RULES_PATH + query);
533
+ return (raw ?? []).map(toRule);
534
+ }
535
+ /** Returns a rule including its assigned subjects. */
536
+ async getRule(ruleId) {
537
+ return toRule(await this.send("GET", rulePath(ruleId)));
538
+ }
539
+ /** Partially updates a rule. */
540
+ async updateRule(ruleId, req) {
541
+ return toRule(await this.send("PATCH", rulePath(ruleId), toWire(req ?? {})));
542
+ }
543
+ /** Deletes a rule and all of its assignments. */
544
+ async deleteRule(ruleId) {
545
+ await this.send("DELETE", rulePath(ruleId));
546
+ }
547
+ /** Applies the rule to a member of the organization. Assigning twice is a no-op. */
548
+ async assignToUser(ruleId, userId) {
549
+ return this.changeAssignment("POST", ruleId, { scope: "user", user_id: requireUserId(userId) });
550
+ }
551
+ /** Applies the rule to every member of the organization. */
552
+ async assignToOrganization(ruleId) {
553
+ return this.changeAssignment("POST", ruleId, { scope: "organization" });
554
+ }
555
+ /**
556
+ * Removes a user assignment from the rule.
557
+ * Throws LastSubjectError if it is the rule's only subject; deactivate or delete the rule instead.
558
+ */
559
+ async unassignFromUser(ruleId, userId) {
560
+ return this.changeAssignment("DELETE", ruleId, { scope: "user", user_id: requireUserId(userId) });
561
+ }
562
+ /**
563
+ * Removes the organization-wide assignment from the rule.
564
+ * Throws LastSubjectError if it is the rule's only subject.
565
+ */
566
+ async unassignFromOrganization(ruleId) {
567
+ return this.changeAssignment("DELETE", ruleId, { scope: "organization" });
568
+ }
569
+ /**
570
+ * Returns the rules that apply to a user: assigned directly, through the user's role,
571
+ * or to the whole organization.
572
+ */
573
+ async listUserRules(userId) {
574
+ const raw = await this.send("GET", userPath(userId, "/geoidentity/rules"));
575
+ return (raw ?? []).map(toRule);
576
+ }
577
+ async changeAssignment(method, ruleId, payload) {
578
+ return toRule(await this.send(method, rulePath(ruleId, "/assignments"), payload));
579
+ }
580
+ send(method, path, body) {
581
+ return apiServiceRequest(this.http, this.isClosed, method, path, body);
582
+ }
583
+ };
584
+ function polygonFromLatLng(coordinates) {
585
+ return { type: "Polygon", coordinates: [validateAndNormalizePolygon(coordinates)] };
586
+ }
181
587
 
182
588
  // src/crypto.ts
183
589
  var import_node_crypto = require("crypto");
@@ -189,7 +595,7 @@ function generateHMACSignature(key, timestamp) {
189
595
  }
190
596
 
191
597
  // src/http.ts
192
- var USER_AGENT = "GeoEngineNodeSDK/2.0.0";
598
+ var USER_AGENT = "GeoEngineNodeSDK/2.1.0";
193
599
  function parseHttpError(statusCode, bodyText, isSpatial = false) {
194
600
  let parsedErrorContainer = null;
195
601
  try {
@@ -247,6 +653,59 @@ function parseHttpError(statusCode, bodyText, isSpatial = false) {
247
653
  }
248
654
  return new APIError(statusCode, message);
249
655
  }
656
+ function parseApiServiceError(statusCode, bodyText) {
657
+ let parsed = null;
658
+ try {
659
+ parsed = JSON.parse(bodyText);
660
+ } catch {
661
+ }
662
+ const container = parsed && typeof parsed === "object" ? parsed.error : void 0;
663
+ const details = Array.isArray(container?.details) ? container.details : [];
664
+ let code = "";
665
+ let message = "";
666
+ if (container && typeof container === "object") {
667
+ code = container.status ?? "";
668
+ message = container.message ?? "";
669
+ const withReason = details.find((d) => d?.reason);
670
+ if (withReason?.reason) {
671
+ code = withReason.reason;
672
+ }
673
+ } else {
674
+ message = bodyText.trim();
675
+ }
676
+ if (!message) {
677
+ message = `HTTP ${statusCode}`;
678
+ }
679
+ switch (code) {
680
+ case "USER_NOT_FOUND":
681
+ case "USER_REVOKED":
682
+ return new UserNotFoundError(message, statusCode, code, details);
683
+ case "RULE_NOT_FOUND":
684
+ return new RuleNotFoundError(message, statusCode, code, details);
685
+ case "USER_ALREADY_EXISTS":
686
+ return new UserAlreadyExistsError(message, statusCode, code, details);
687
+ case "INVITATION_PENDING":
688
+ return new InvitationPendingError(message, statusCode, code, details);
689
+ case "LAST_ADMIN":
690
+ return new LastAdminError(message, statusCode, code, details);
691
+ case "LAST_SUBJECT":
692
+ return new LastSubjectError(message, statusCode, code, details);
693
+ case "QUOTA_EXCEEDED":
694
+ return new QuotaExceededError(message, statusCode, details);
695
+ case "MISSING_API_KEY":
696
+ case "MISSING_ORGANIZATION":
697
+ return new AuthenticationError(message, statusCode, details);
698
+ }
699
+ switch (statusCode) {
700
+ case 401:
701
+ return new AuthenticationError(message, statusCode, details);
702
+ case 403:
703
+ return new ForbiddenError(message, statusCode, details);
704
+ case 402:
705
+ return new QuotaExceededError(message, statusCode, details);
706
+ }
707
+ return new APIServiceError(statusCode, code, message, details);
708
+ }
250
709
  var HttpClient = class {
251
710
  config;
252
711
  constructor(options = {}) {
@@ -277,7 +736,7 @@ var HttpClient = class {
277
736
  async request(opts) {
278
737
  const method = opts.method ?? "POST";
279
738
  const timeoutMs = opts.timeout ?? this.config.timeout;
280
- const maxRetries = this.config.maxRetries;
739
+ const maxRetries = opts.isApiService && method !== "GET" ? 0 : this.config.maxRetries;
281
740
  let attempt = 0;
282
741
  while (true) {
283
742
  attempt++;
@@ -285,13 +744,16 @@ var HttpClient = class {
285
744
  const timeoutId = globalThis.setTimeout(() => controller.abort(), timeoutMs);
286
745
  const now = Date.now();
287
746
  const headers = {
288
- "Content-Type": "application/json",
747
+ ...opts.isApiService ? { Accept: "application/json" } : { "Content-Type": "application/json" },
289
748
  "X-API-Key": this.config.apiKey,
290
749
  "X-Geo-Environment": this.config.environment,
291
750
  "X-Request-Time": now.toString(),
292
751
  "X-Signature": generateHMACSignature(this.config.apiKey, now),
293
752
  "User-Agent": USER_AGENT
294
753
  };
754
+ if (opts.isApiService && opts.body !== void 0) {
755
+ headers["Content-Type"] = "application/json";
756
+ }
295
757
  if (this.config.jwtToken) {
296
758
  headers["Authorization"] = `Bearer ${this.config.jwtToken}`;
297
759
  }
@@ -318,15 +780,15 @@ var HttpClient = class {
318
780
  }
319
781
  const responseText = await response.text();
320
782
  if (!response.ok) {
321
- throw parseHttpError(response.status, responseText, opts.isSpatial);
783
+ throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, opts.isSpatial);
322
784
  }
323
785
  if (!responseText || responseText.trim() === "") {
324
786
  return null;
325
787
  }
326
788
  const json = JSON.parse(responseText);
327
- if (opts.isSpatial && typeof json === "object" && json !== null && "success" in json) {
789
+ if ((opts.isSpatial || opts.isApiService) && typeof json === "object" && json !== null && "success" in json) {
328
790
  if (!json.success) {
329
- throw parseHttpError(response.status, responseText, true);
791
+ throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, true);
330
792
  }
331
793
  return json.data;
332
794
  }
@@ -555,51 +1017,6 @@ var SpatialGeneralResult = class {
555
1017
  }
556
1018
  };
557
1019
 
558
- // src/validation.ts
559
- function validateCoordinates(lat, lng) {
560
- if (typeof lat !== "number" || Number.isNaN(lat) || lat < -90 || lat > 90) {
561
- throw new InvalidLatitudeError();
562
- }
563
- if (typeof lng !== "number" || Number.isNaN(lng) || lng < -180 || lng > 180) {
564
- throw new InvalidLongitudeError();
565
- }
566
- }
567
- function validateDeviceId(deviceId) {
568
- if (!deviceId || typeof deviceId !== "string" || deviceId.trim() === "") {
569
- throw new DeviceIDRequiredError();
570
- }
571
- return deviceId.trim();
572
- }
573
- function validateGeofenceId(geofenceId) {
574
- if (!geofenceId || typeof geofenceId !== "string" || geofenceId.trim() === "") {
575
- throw new GeofenceIDRequiredError();
576
- }
577
- return geofenceId.trim();
578
- }
579
- function validateAndNormalizePolygon(coordinates) {
580
- if (!Array.isArray(coordinates) || coordinates.length < 3) {
581
- throw new InvalidCoordinatesError();
582
- }
583
- const polygon = [];
584
- for (const p of coordinates) {
585
- if (!Array.isArray(p) || p.length !== 2) {
586
- throw new ValidationError(
587
- `geoengine: invalid coordinate format: ${JSON.stringify(p)} (expected [lat, lng])`
588
- );
589
- }
590
- const lat = p[0];
591
- const lng = p[1];
592
- validateCoordinates(lat, lng);
593
- polygon.push([lng, lat]);
594
- }
595
- const first = polygon[0];
596
- const last = polygon[polygon.length - 1];
597
- if (first[0] !== last[0] || first[1] !== last[1]) {
598
- polygon.push([first[0], first[1]]);
599
- }
600
- return polygon;
601
- }
602
-
603
1020
  // src/spatial.ts
604
1021
  var SpatialService = class {
605
1022
  constructor(http) {
@@ -785,6 +1202,22 @@ var GeoEngine = class {
785
1202
  * Alias for spatial (to maintain exact casing compatibility with Go client.Spatial).
786
1203
  */
787
1204
  Spatial;
1205
+ /**
1206
+ * Users manages organization members, roles and invitations.
1207
+ */
1208
+ users;
1209
+ /**
1210
+ * Alias for users (matches Go client.Users).
1211
+ */
1212
+ Users;
1213
+ /**
1214
+ * GeoIdentity manages GeoIdentity access rules for users and the organization.
1215
+ */
1216
+ geoIdentity;
1217
+ /**
1218
+ * Alias for geoIdentity (matches Go client.GeoIdentity).
1219
+ */
1220
+ GeoIdentity;
788
1221
  /**
789
1222
  * Initializes a new GeoEngine client instance.
790
1223
  *
@@ -806,6 +1239,11 @@ var GeoEngine = class {
806
1239
  this.http = new HttpClient(resolvedOptions);
807
1240
  this.spatial = new SpatialService(this.http);
808
1241
  this.Spatial = this.spatial;
1242
+ const isClosed = () => this.isClosed;
1243
+ this.users = new UsersService(this.http, isClosed);
1244
+ this.Users = this.users;
1245
+ this.geoIdentity = new GeoIdentityService(this.http, isClosed);
1246
+ this.GeoIdentity = this.geoIdentity;
809
1247
  }
810
1248
  /**
811
1249
  * Current configuration options.
@@ -943,30 +1381,49 @@ var index_default = GeoEngine;
943
1381
  // Annotate the CommonJS export names for ESM import in node:
944
1382
  0 && (module.exports = {
945
1383
  APIError,
1384
+ APIServiceError,
946
1385
  AsyncIngester,
947
1386
  AuthenticationError,
948
1387
  Client,
949
1388
  ClientClosedError,
950
1389
  DeviceIDRequiredError,
1390
+ EmailRequiredError,
951
1391
  ForbiddenError,
952
1392
  GeneralGeofenceCheck,
953
1393
  GeoEngine,
954
1394
  GeoEngineError,
1395
+ GeoIdentityService,
955
1396
  GeofenceIDRequiredError,
956
1397
  GeofenceNotFoundError,
957
1398
  InvalidCoordinatesError,
958
1399
  InvalidLatitudeError,
959
1400
  InvalidLongitudeError,
1401
+ InvitationPendingError,
1402
+ LastAdminError,
1403
+ LastSubjectError,
960
1404
  QuotaExceededError,
1405
+ RoleRequiredError,
1406
+ Roles,
1407
+ RuleActions,
1408
+ RuleIDRequiredError,
1409
+ RuleNameRequiredError,
1410
+ RuleNotFoundError,
961
1411
  SingleGeofenceCheck,
962
1412
  SpatialAPIError,
963
1413
  SpatialCheckBuilder,
964
1414
  SpatialGeneralResult,
965
1415
  SpatialService,
966
1416
  SpatialValidationResult,
1417
+ SubjectTypes,
967
1418
  TimeoutError,
1419
+ UserAlreadyExistsError,
1420
+ UserIDRequiredError,
1421
+ UserNotFoundError,
1422
+ UserStatus,
1423
+ UsersService,
968
1424
  ValidationError,
969
1425
  generateHMACSignature,
1426
+ polygonFromLatLng,
970
1427
  validateAndNormalizePolygon,
971
1428
  validateCoordinates,
972
1429
  validateDeviceId,