geo-engine-node 2.1.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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.es.md +146 -140
- package/Readme.md +149 -91
- package/dist/chunk-425YTEGY.js +1231 -0
- package/dist/chunk-425YTEGY.js.map +1 -0
- package/dist/chunk-A6RGK4MA.cjs +1231 -0
- package/dist/chunk-A6RGK4MA.cjs.map +1 -0
- package/dist/errors-C5S_d0Ca.d.cts +473 -0
- package/dist/errors-C5S_d0Ca.d.ts +473 -0
- package/dist/identity.cjs +196 -0
- package/dist/identity.cjs.map +1 -0
- package/dist/identity.d.cts +10 -0
- package/dist/identity.d.ts +10 -0
- package/dist/identity.js +196 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.cjs +211 -658
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -224
- package/dist/index.d.ts +18 -224
- package/dist/index.js +65 -438
- package/dist/index.js.map +1 -1
- package/package.json +38 -9
package/dist/index.js
CHANGED
|
@@ -1,209 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.name = "InvalidLatitudeError";
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var InvalidLongitudeError = class extends ValidationError {
|
|
40
|
-
constructor(message = "geoengine: longitude must be between -180 and 180 degrees") {
|
|
41
|
-
super(message);
|
|
42
|
-
this.name = "InvalidLongitudeError";
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var InvalidCoordinatesError = class extends ValidationError {
|
|
46
|
-
constructor(message = "geoengine: at least 3 coordinate pairs are required for a polygon") {
|
|
47
|
-
super(message);
|
|
48
|
-
this.name = "InvalidCoordinatesError";
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var APIError = class extends GeoEngineError {
|
|
52
|
-
statusCode;
|
|
53
|
-
constructor(statusCode, message) {
|
|
54
|
-
super(`geoengine: API error (status ${statusCode}): ${message}`);
|
|
55
|
-
this.name = "APIError";
|
|
56
|
-
this.statusCode = statusCode;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
var SpatialAPIError = class extends APIError {
|
|
60
|
-
code;
|
|
61
|
-
statusText;
|
|
62
|
-
details;
|
|
63
|
-
constructor(statusCode, code, message, statusText, details = []) {
|
|
64
|
-
const formattedMessage = code ? `geoengine: spatial API error (status ${statusCode}, code ${code}): ${message}` : `geoengine: spatial API error (status ${statusCode}): ${message}`;
|
|
65
|
-
super(statusCode, formattedMessage);
|
|
66
|
-
this.name = "SpatialAPIError";
|
|
67
|
-
this.code = code;
|
|
68
|
-
this.statusText = statusText;
|
|
69
|
-
this.details = details;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns true if the error indicates the geofence or resource was not found.
|
|
73
|
-
*/
|
|
74
|
-
isNotFound() {
|
|
75
|
-
return this.statusCode === 204 || this.statusCode === 404 || this.code === "NOT_FOUND";
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Returns true if the error indicates quota limit was hit.
|
|
79
|
-
*/
|
|
80
|
-
isQuotaExceeded() {
|
|
81
|
-
return this.statusCode === 402 || this.code === "QUOTA_EXCEEDED";
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns true if authentication failed.
|
|
85
|
-
*/
|
|
86
|
-
isUnauthorized() {
|
|
87
|
-
return this.statusCode === 401 || this.code === "UNAUTHORIZED" || this.code === "MISSING_API_KEY" || this.code === "MISSING_ORGANIZATION";
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns true if access to the requested resource is forbidden.
|
|
91
|
-
*/
|
|
92
|
-
isForbidden() {
|
|
93
|
-
return this.statusCode === 403 || this.code === "FORBIDDEN";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var GeofenceNotFoundError = class extends SpatialAPIError {
|
|
97
|
-
constructor(message = "geofence not found", statusCode = 204, details = []) {
|
|
98
|
-
super(statusCode, "NOT_FOUND", message, "Not Found", details);
|
|
99
|
-
this.name = "GeofenceNotFoundError";
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var QuotaExceededError = class extends SpatialAPIError {
|
|
103
|
-
constructor(message = "request quota exceeded", statusCode = 402, details = []) {
|
|
104
|
-
super(statusCode, "QUOTA_EXCEEDED", message, "Payment Required", details);
|
|
105
|
-
this.name = "QuotaExceededError";
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var AuthenticationError = class extends SpatialAPIError {
|
|
109
|
-
constructor(message = "unauthorized API request", statusCode = 401, details = []) {
|
|
110
|
-
super(statusCode, "UNAUTHORIZED", message, "Unauthorized", details);
|
|
111
|
-
this.name = "AuthenticationError";
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
var ForbiddenError = class extends SpatialAPIError {
|
|
115
|
-
constructor(message = "access forbidden", statusCode = 403, details = []) {
|
|
116
|
-
super(statusCode, "FORBIDDEN", message, "Forbidden", details);
|
|
117
|
-
this.name = "ForbiddenError";
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var TimeoutError = class extends GeoEngineError {
|
|
121
|
-
constructor(timeoutMs) {
|
|
122
|
-
super(`geoengine: request exceeded the timeout limit of ${timeoutMs}ms`);
|
|
123
|
-
this.name = "TimeoutError";
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var UserIDRequiredError = class extends ValidationError {
|
|
127
|
-
constructor(message = "geoengine: user_id is required") {
|
|
128
|
-
super(message);
|
|
129
|
-
this.name = "UserIDRequiredError";
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
var RuleIDRequiredError = class extends ValidationError {
|
|
133
|
-
constructor(message = "geoengine: rule_id is required") {
|
|
134
|
-
super(message);
|
|
135
|
-
this.name = "RuleIDRequiredError";
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var RuleNameRequiredError = class extends ValidationError {
|
|
139
|
-
constructor(message = "geoengine: rule name is required") {
|
|
140
|
-
super(message);
|
|
141
|
-
this.name = "RuleNameRequiredError";
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
var EmailRequiredError = class extends ValidationError {
|
|
145
|
-
constructor(message = "geoengine: email is required") {
|
|
146
|
-
super(message);
|
|
147
|
-
this.name = "EmailRequiredError";
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
var RoleRequiredError = class extends ValidationError {
|
|
151
|
-
constructor(message = "geoengine: role is required") {
|
|
152
|
-
super(message);
|
|
153
|
-
this.name = "RoleRequiredError";
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var APIServiceError = class extends APIError {
|
|
157
|
-
/** Machine-readable reason, e.g. "USER_NOT_FOUND". Empty when the API sent none. */
|
|
158
|
-
code;
|
|
159
|
-
/** Message returned by the API, without the SDK prefix. */
|
|
160
|
-
apiMessage;
|
|
161
|
-
details;
|
|
162
|
-
constructor(statusCode, code, message, details = []) {
|
|
163
|
-
super(statusCode, message);
|
|
164
|
-
this.message = code ? `geoengine: api-service error (status ${statusCode}, code ${code}): ${message}` : `geoengine: api-service error (status ${statusCode}): ${message}`;
|
|
165
|
-
this.name = "APIServiceError";
|
|
166
|
-
this.code = code;
|
|
167
|
-
this.apiMessage = message;
|
|
168
|
-
this.details = details;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
var UserNotFoundError = class extends APIServiceError {
|
|
172
|
-
constructor(message = "user not found in organization", statusCode = 404, code = "USER_NOT_FOUND", details = []) {
|
|
173
|
-
super(statusCode, code, message, details);
|
|
174
|
-
this.name = "UserNotFoundError";
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var RuleNotFoundError = class extends APIServiceError {
|
|
178
|
-
constructor(message = "geoidentity rule not found", statusCode = 404, code = "RULE_NOT_FOUND", details = []) {
|
|
179
|
-
super(statusCode, code, message, details);
|
|
180
|
-
this.name = "RuleNotFoundError";
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var UserAlreadyExistsError = class extends APIServiceError {
|
|
184
|
-
constructor(message = "user already belongs to the organization", statusCode = 409, code = "USER_ALREADY_EXISTS", details = []) {
|
|
185
|
-
super(statusCode, code, message, details);
|
|
186
|
-
this.name = "UserAlreadyExistsError";
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
var InvitationPendingError = class extends APIServiceError {
|
|
190
|
-
constructor(message = "a pending invitation already exists for this email", statusCode = 409, code = "INVITATION_PENDING", details = []) {
|
|
191
|
-
super(statusCode, code, message, details);
|
|
192
|
-
this.name = "InvitationPendingError";
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
var LastAdminError = class extends APIServiceError {
|
|
196
|
-
constructor(message = "organization must keep at least one admin", statusCode = 409, code = "LAST_ADMIN", details = []) {
|
|
197
|
-
super(statusCode, code, message, details);
|
|
198
|
-
this.name = "LastAdminError";
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var LastSubjectError = class extends APIServiceError {
|
|
202
|
-
constructor(message = "rule must keep at least one assigned subject", statusCode = 409, code = "LAST_SUBJECT", details = []) {
|
|
203
|
-
super(statusCode, code, message, details);
|
|
204
|
-
this.name = "LastSubjectError";
|
|
205
|
-
}
|
|
206
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
APIError,
|
|
3
|
+
APIServiceError,
|
|
4
|
+
AuthenticationError,
|
|
5
|
+
ClientClosedError,
|
|
6
|
+
DeviceIDRequiredError,
|
|
7
|
+
EmailRequiredError,
|
|
8
|
+
ForbiddenError,
|
|
9
|
+
GeoEngineError,
|
|
10
|
+
GeofenceIDRequiredError,
|
|
11
|
+
GeofenceNotFoundError,
|
|
12
|
+
HttpClient,
|
|
13
|
+
IdentityIntegrationError,
|
|
14
|
+
IdentityService,
|
|
15
|
+
IdentityTransientError,
|
|
16
|
+
InvalidCoordinatesError,
|
|
17
|
+
InvalidLatitudeError,
|
|
18
|
+
InvalidLongitudeError,
|
|
19
|
+
InvitationPendingError,
|
|
20
|
+
LastAdminError,
|
|
21
|
+
LastSubjectError,
|
|
22
|
+
QuotaExceededError,
|
|
23
|
+
RoleRequiredError,
|
|
24
|
+
RuleIDRequiredError,
|
|
25
|
+
RuleNameRequiredError,
|
|
26
|
+
RuleNotFoundError,
|
|
27
|
+
SpatialAPIError,
|
|
28
|
+
TimeoutError,
|
|
29
|
+
UserAlreadyExistsError,
|
|
30
|
+
UserIDRequiredError,
|
|
31
|
+
UserNotFoundError,
|
|
32
|
+
ValidationError,
|
|
33
|
+
generateHMACSignature,
|
|
34
|
+
isTransient
|
|
35
|
+
} from "./chunk-425YTEGY.js";
|
|
207
36
|
|
|
208
37
|
// src/users.ts
|
|
209
38
|
var Roles = {
|
|
@@ -511,235 +340,6 @@ function polygonFromLatLng(coordinates) {
|
|
|
511
340
|
return { type: "Polygon", coordinates: [validateAndNormalizePolygon(coordinates)] };
|
|
512
341
|
}
|
|
513
342
|
|
|
514
|
-
// src/crypto.ts
|
|
515
|
-
import { createHmac } from "crypto";
|
|
516
|
-
function generateHMACSignature(key, timestamp) {
|
|
517
|
-
if (!key) {
|
|
518
|
-
return "";
|
|
519
|
-
}
|
|
520
|
-
return createHmac("sha256", key).update(timestamp.toString()).digest("hex");
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/http.ts
|
|
524
|
-
var USER_AGENT = "GeoEngineNodeSDK/2.1.0";
|
|
525
|
-
function parseHttpError(statusCode, bodyText, isSpatial = false) {
|
|
526
|
-
let parsedErrorContainer = null;
|
|
527
|
-
try {
|
|
528
|
-
parsedErrorContainer = JSON.parse(bodyText);
|
|
529
|
-
} catch {
|
|
530
|
-
}
|
|
531
|
-
const container = parsedErrorContainer?.error;
|
|
532
|
-
let code = container?.status ?? "";
|
|
533
|
-
let message = container?.message ?? parsedErrorContainer?.message ?? bodyText.trim();
|
|
534
|
-
const details = container?.details ?? [];
|
|
535
|
-
if (container?.details && container.details.length > 0) {
|
|
536
|
-
for (const detail of container.details) {
|
|
537
|
-
if (detail.reason) {
|
|
538
|
-
code = detail.reason;
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (!code) {
|
|
544
|
-
switch (statusCode) {
|
|
545
|
-
case 204:
|
|
546
|
-
case 404:
|
|
547
|
-
code = "NOT_FOUND";
|
|
548
|
-
break;
|
|
549
|
-
case 402:
|
|
550
|
-
code = "QUOTA_EXCEEDED";
|
|
551
|
-
break;
|
|
552
|
-
case 401:
|
|
553
|
-
code = "UNAUTHORIZED";
|
|
554
|
-
break;
|
|
555
|
-
case 403:
|
|
556
|
-
code = "FORBIDDEN";
|
|
557
|
-
break;
|
|
558
|
-
default:
|
|
559
|
-
code = "";
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
if (!message) {
|
|
563
|
-
message = `HTTP ${statusCode}`;
|
|
564
|
-
}
|
|
565
|
-
if (statusCode === 204 || statusCode === 404 || code === "NOT_FOUND") {
|
|
566
|
-
return new GeofenceNotFoundError(message, statusCode, details);
|
|
567
|
-
}
|
|
568
|
-
if (statusCode === 402 || code === "QUOTA_EXCEEDED") {
|
|
569
|
-
return new QuotaExceededError(message, statusCode, details);
|
|
570
|
-
}
|
|
571
|
-
if (statusCode === 401 || code === "UNAUTHORIZED" || code === "MISSING_API_KEY" || code === "MISSING_ORGANIZATION") {
|
|
572
|
-
return new AuthenticationError(message, statusCode, details);
|
|
573
|
-
}
|
|
574
|
-
if (statusCode === 403 || code === "FORBIDDEN") {
|
|
575
|
-
return new ForbiddenError(message, statusCode, details);
|
|
576
|
-
}
|
|
577
|
-
if (isSpatial) {
|
|
578
|
-
return new SpatialAPIError(statusCode, code, message, void 0, details);
|
|
579
|
-
}
|
|
580
|
-
return new APIError(statusCode, message);
|
|
581
|
-
}
|
|
582
|
-
function parseApiServiceError(statusCode, bodyText) {
|
|
583
|
-
let parsed = null;
|
|
584
|
-
try {
|
|
585
|
-
parsed = JSON.parse(bodyText);
|
|
586
|
-
} catch {
|
|
587
|
-
}
|
|
588
|
-
const container = parsed && typeof parsed === "object" ? parsed.error : void 0;
|
|
589
|
-
const details = Array.isArray(container?.details) ? container.details : [];
|
|
590
|
-
let code = "";
|
|
591
|
-
let message = "";
|
|
592
|
-
if (container && typeof container === "object") {
|
|
593
|
-
code = container.status ?? "";
|
|
594
|
-
message = container.message ?? "";
|
|
595
|
-
const withReason = details.find((d) => d?.reason);
|
|
596
|
-
if (withReason?.reason) {
|
|
597
|
-
code = withReason.reason;
|
|
598
|
-
}
|
|
599
|
-
} else {
|
|
600
|
-
message = bodyText.trim();
|
|
601
|
-
}
|
|
602
|
-
if (!message) {
|
|
603
|
-
message = `HTTP ${statusCode}`;
|
|
604
|
-
}
|
|
605
|
-
switch (code) {
|
|
606
|
-
case "USER_NOT_FOUND":
|
|
607
|
-
case "USER_REVOKED":
|
|
608
|
-
return new UserNotFoundError(message, statusCode, code, details);
|
|
609
|
-
case "RULE_NOT_FOUND":
|
|
610
|
-
return new RuleNotFoundError(message, statusCode, code, details);
|
|
611
|
-
case "USER_ALREADY_EXISTS":
|
|
612
|
-
return new UserAlreadyExistsError(message, statusCode, code, details);
|
|
613
|
-
case "INVITATION_PENDING":
|
|
614
|
-
return new InvitationPendingError(message, statusCode, code, details);
|
|
615
|
-
case "LAST_ADMIN":
|
|
616
|
-
return new LastAdminError(message, statusCode, code, details);
|
|
617
|
-
case "LAST_SUBJECT":
|
|
618
|
-
return new LastSubjectError(message, statusCode, code, details);
|
|
619
|
-
case "QUOTA_EXCEEDED":
|
|
620
|
-
return new QuotaExceededError(message, statusCode, details);
|
|
621
|
-
case "MISSING_API_KEY":
|
|
622
|
-
case "MISSING_ORGANIZATION":
|
|
623
|
-
return new AuthenticationError(message, statusCode, details);
|
|
624
|
-
}
|
|
625
|
-
switch (statusCode) {
|
|
626
|
-
case 401:
|
|
627
|
-
return new AuthenticationError(message, statusCode, details);
|
|
628
|
-
case 403:
|
|
629
|
-
return new ForbiddenError(message, statusCode, details);
|
|
630
|
-
case 402:
|
|
631
|
-
return new QuotaExceededError(message, statusCode, details);
|
|
632
|
-
}
|
|
633
|
-
return new APIServiceError(statusCode, code, message, details);
|
|
634
|
-
}
|
|
635
|
-
var HttpClient = class {
|
|
636
|
-
config;
|
|
637
|
-
constructor(options = {}) {
|
|
638
|
-
const defaultManagement = "https://management.geoengine.dev";
|
|
639
|
-
const defaultIngest = "https://ingest.geoengine.dev";
|
|
640
|
-
const defaultApiService = "https://api.geoengine.dev";
|
|
641
|
-
this.config = {
|
|
642
|
-
apiKey: options.apiKey ?? "",
|
|
643
|
-
jwtToken: options.jwtToken,
|
|
644
|
-
environment: options.environment ?? "live",
|
|
645
|
-
managementUrl: options.baseUrl ?? options.managementUrl ?? defaultManagement,
|
|
646
|
-
ingestUrl: options.baseUrl ?? options.ingestUrl ?? defaultIngest,
|
|
647
|
-
apiServiceUrl: options.baseUrl ?? options.apiServiceUrl ?? defaultApiService,
|
|
648
|
-
timeout: options.timeout ?? 1e4,
|
|
649
|
-
maxRetries: options.maxRetries ?? 2,
|
|
650
|
-
batchSize: options.batchSize ?? 100,
|
|
651
|
-
flushInterval: options.flushInterval ?? 500,
|
|
652
|
-
bufferSize: options.bufferSize ?? 5e3,
|
|
653
|
-
fetch: options.fetch ?? globalThis.fetch
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
get options() {
|
|
657
|
-
return this.config;
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Executes an HTTP request with timeout, authentication headers and exponential backoff retry.
|
|
661
|
-
*/
|
|
662
|
-
async request(opts) {
|
|
663
|
-
const method = opts.method ?? "POST";
|
|
664
|
-
const timeoutMs = opts.timeout ?? this.config.timeout;
|
|
665
|
-
const maxRetries = opts.isApiService && method !== "GET" ? 0 : this.config.maxRetries;
|
|
666
|
-
let attempt = 0;
|
|
667
|
-
while (true) {
|
|
668
|
-
attempt++;
|
|
669
|
-
const controller = new globalThis.AbortController();
|
|
670
|
-
const timeoutId = globalThis.setTimeout(() => controller.abort(), timeoutMs);
|
|
671
|
-
const now = Date.now();
|
|
672
|
-
const headers = {
|
|
673
|
-
...opts.isApiService ? { Accept: "application/json" } : { "Content-Type": "application/json" },
|
|
674
|
-
"X-API-Key": this.config.apiKey,
|
|
675
|
-
"X-Geo-Environment": this.config.environment,
|
|
676
|
-
"X-Request-Time": now.toString(),
|
|
677
|
-
"X-Signature": generateHMACSignature(this.config.apiKey, now),
|
|
678
|
-
"User-Agent": USER_AGENT
|
|
679
|
-
};
|
|
680
|
-
if (opts.isApiService && opts.body !== void 0) {
|
|
681
|
-
headers["Content-Type"] = "application/json";
|
|
682
|
-
}
|
|
683
|
-
if (this.config.jwtToken) {
|
|
684
|
-
headers["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
685
|
-
}
|
|
686
|
-
try {
|
|
687
|
-
const response = await this.config.fetch(opts.endpoint, {
|
|
688
|
-
method,
|
|
689
|
-
headers,
|
|
690
|
-
body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0,
|
|
691
|
-
signal: controller.signal
|
|
692
|
-
});
|
|
693
|
-
globalThis.clearTimeout(timeoutId);
|
|
694
|
-
if (response.status === 204) {
|
|
695
|
-
if (opts.isSpatial) {
|
|
696
|
-
throw new GeofenceNotFoundError("geofence not found", 204);
|
|
697
|
-
}
|
|
698
|
-
return null;
|
|
699
|
-
}
|
|
700
|
-
if ((response.status === 429 || response.status >= 500) && attempt <= maxRetries) {
|
|
701
|
-
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
702
|
-
await new Promise(
|
|
703
|
-
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
704
|
-
);
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
const responseText = await response.text();
|
|
708
|
-
if (!response.ok) {
|
|
709
|
-
throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, opts.isSpatial);
|
|
710
|
-
}
|
|
711
|
-
if (!responseText || responseText.trim() === "") {
|
|
712
|
-
return null;
|
|
713
|
-
}
|
|
714
|
-
const json = JSON.parse(responseText);
|
|
715
|
-
if ((opts.isSpatial || opts.isApiService) && typeof json === "object" && json !== null && "success" in json) {
|
|
716
|
-
if (!json.success) {
|
|
717
|
-
throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, true);
|
|
718
|
-
}
|
|
719
|
-
return json.data;
|
|
720
|
-
}
|
|
721
|
-
return json;
|
|
722
|
-
} catch (err) {
|
|
723
|
-
globalThis.clearTimeout(timeoutId);
|
|
724
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
725
|
-
throw new TimeoutError(timeoutMs);
|
|
726
|
-
}
|
|
727
|
-
if (err instanceof APIError) {
|
|
728
|
-
throw err;
|
|
729
|
-
}
|
|
730
|
-
if (attempt <= maxRetries) {
|
|
731
|
-
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
732
|
-
await new Promise(
|
|
733
|
-
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
734
|
-
);
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
throw err;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
|
|
743
343
|
// src/ingester.ts
|
|
744
344
|
import { clearInterval, setInterval } from "timers";
|
|
745
345
|
var AsyncIngester = class {
|
|
@@ -1118,6 +718,7 @@ var GeneralGeofenceCheck = class {
|
|
|
1118
718
|
|
|
1119
719
|
// src/client.ts
|
|
1120
720
|
var GeoEngine = class {
|
|
721
|
+
#apiKey;
|
|
1121
722
|
http;
|
|
1122
723
|
isClosed = false;
|
|
1123
724
|
/**
|
|
@@ -1144,6 +745,10 @@ var GeoEngine = class {
|
|
|
1144
745
|
* Alias for geoIdentity (matches Go client.GeoIdentity).
|
|
1145
746
|
*/
|
|
1146
747
|
GeoIdentity;
|
|
748
|
+
/**
|
|
749
|
+
* Server-only runtime decision client for `POST /v1/evaluate`.
|
|
750
|
+
*/
|
|
751
|
+
identity;
|
|
1147
752
|
/**
|
|
1148
753
|
* Initializes a new GeoEngine client instance.
|
|
1149
754
|
*
|
|
@@ -1162,6 +767,7 @@ var GeoEngine = class {
|
|
|
1162
767
|
if (!resolvedOptions.apiKey || resolvedOptions.apiKey.trim() === "") {
|
|
1163
768
|
throw new ValidationError("GeoEngine: API Key es requerida.");
|
|
1164
769
|
}
|
|
770
|
+
this.#apiKey = resolvedOptions.apiKey;
|
|
1165
771
|
this.http = new HttpClient(resolvedOptions);
|
|
1166
772
|
this.spatial = new SpatialService(this.http);
|
|
1167
773
|
this.Spatial = this.spatial;
|
|
@@ -1170,13 +776,30 @@ var GeoEngine = class {
|
|
|
1170
776
|
this.Users = this.users;
|
|
1171
777
|
this.geoIdentity = new GeoIdentityService(this.http, isClosed);
|
|
1172
778
|
this.GeoIdentity = this.geoIdentity;
|
|
779
|
+
this.identity = new IdentityService({
|
|
780
|
+
getBaseUrl: () => this.http.options.apiServiceUrl,
|
|
781
|
+
getApiKey: () => this.#apiKey,
|
|
782
|
+
getTimeoutMs: () => this.http.options.identityTimeoutMs,
|
|
783
|
+
getFetch: () => this.http.options.fetch,
|
|
784
|
+
isClosed
|
|
785
|
+
});
|
|
1173
786
|
}
|
|
1174
787
|
/**
|
|
1175
|
-
* Current configuration options.
|
|
788
|
+
* Current configuration options (without secret apiKey).
|
|
1176
789
|
*/
|
|
1177
790
|
get options() {
|
|
1178
791
|
return this.http.options;
|
|
1179
792
|
}
|
|
793
|
+
toJSON() {
|
|
794
|
+
return {
|
|
795
|
+
apiKey: "[REDACTED]",
|
|
796
|
+
closed: this.isClosed,
|
|
797
|
+
options: this.http.toJSON()
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
801
|
+
return this.toJSON();
|
|
802
|
+
}
|
|
1180
803
|
/**
|
|
1181
804
|
* Sends device coordinates over HTTP REST.
|
|
1182
805
|
* Equivalent to Go's Client.SendLocation.
|
|
@@ -1303,7 +926,7 @@ var GeoEngine = class {
|
|
|
1303
926
|
};
|
|
1304
927
|
|
|
1305
928
|
// src/index.ts
|
|
1306
|
-
var
|
|
929
|
+
var src_default = GeoEngine;
|
|
1307
930
|
export {
|
|
1308
931
|
APIError,
|
|
1309
932
|
APIServiceError,
|
|
@@ -1320,6 +943,9 @@ export {
|
|
|
1320
943
|
GeoIdentityService,
|
|
1321
944
|
GeofenceIDRequiredError,
|
|
1322
945
|
GeofenceNotFoundError,
|
|
946
|
+
IdentityIntegrationError,
|
|
947
|
+
IdentityService,
|
|
948
|
+
IdentityTransientError,
|
|
1323
949
|
InvalidCoordinatesError,
|
|
1324
950
|
InvalidLatitudeError,
|
|
1325
951
|
InvalidLongitudeError,
|
|
@@ -1347,8 +973,9 @@ export {
|
|
|
1347
973
|
UserStatus,
|
|
1348
974
|
UsersService,
|
|
1349
975
|
ValidationError,
|
|
1350
|
-
|
|
976
|
+
src_default as default,
|
|
1351
977
|
generateHMACSignature,
|
|
978
|
+
isTransient,
|
|
1352
979
|
polygonFromLatLng,
|
|
1353
980
|
validateAndNormalizePolygon,
|
|
1354
981
|
validateCoordinates,
|