geo-engine-node 1.1.3 → 2.0.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/Readme.md +222 -66
- package/dist/index.cjs +975 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +640 -0
- package/dist/index.d.ts +640 -0
- package/dist/index.js +920 -0
- package/dist/index.js.map +1 -0
- package/package.json +20 -9
- package/.idea/modules.xml +0 -8
- package/.idea/node.js.iml +0 -8
- package/index.js +0 -110
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,975 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
APIError: () => APIError,
|
|
24
|
+
AsyncIngester: () => AsyncIngester,
|
|
25
|
+
AuthenticationError: () => AuthenticationError,
|
|
26
|
+
Client: () => GeoEngine,
|
|
27
|
+
ClientClosedError: () => ClientClosedError,
|
|
28
|
+
DeviceIDRequiredError: () => DeviceIDRequiredError,
|
|
29
|
+
ForbiddenError: () => ForbiddenError,
|
|
30
|
+
GeneralGeofenceCheck: () => GeneralGeofenceCheck,
|
|
31
|
+
GeoEngine: () => GeoEngine,
|
|
32
|
+
GeoEngineError: () => GeoEngineError,
|
|
33
|
+
GeofenceIDRequiredError: () => GeofenceIDRequiredError,
|
|
34
|
+
GeofenceNotFoundError: () => GeofenceNotFoundError,
|
|
35
|
+
InvalidCoordinatesError: () => InvalidCoordinatesError,
|
|
36
|
+
InvalidLatitudeError: () => InvalidLatitudeError,
|
|
37
|
+
InvalidLongitudeError: () => InvalidLongitudeError,
|
|
38
|
+
QuotaExceededError: () => QuotaExceededError,
|
|
39
|
+
SingleGeofenceCheck: () => SingleGeofenceCheck,
|
|
40
|
+
SpatialAPIError: () => SpatialAPIError,
|
|
41
|
+
SpatialCheckBuilder: () => SpatialCheckBuilder,
|
|
42
|
+
SpatialGeneralResult: () => SpatialGeneralResult,
|
|
43
|
+
SpatialService: () => SpatialService,
|
|
44
|
+
SpatialValidationResult: () => SpatialValidationResult,
|
|
45
|
+
TimeoutError: () => TimeoutError,
|
|
46
|
+
ValidationError: () => ValidationError,
|
|
47
|
+
default: () => index_default,
|
|
48
|
+
generateHMACSignature: () => generateHMACSignature,
|
|
49
|
+
validateAndNormalizePolygon: () => validateAndNormalizePolygon,
|
|
50
|
+
validateCoordinates: () => validateCoordinates,
|
|
51
|
+
validateDeviceId: () => validateDeviceId,
|
|
52
|
+
validateGeofenceId: () => validateGeofenceId
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(index_exports);
|
|
55
|
+
|
|
56
|
+
// src/errors.ts
|
|
57
|
+
var GeoEngineError = class extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "GeoEngineError";
|
|
61
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var ClientClosedError = class extends GeoEngineError {
|
|
65
|
+
constructor(message = "geoengine: client is closed") {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "ClientClosedError";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var ValidationError = class extends GeoEngineError {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "ValidationError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var DeviceIDRequiredError = class extends ValidationError {
|
|
77
|
+
constructor(message = "geoengine: device_id is required") {
|
|
78
|
+
super(message);
|
|
79
|
+
this.name = "DeviceIDRequiredError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var GeofenceIDRequiredError = class extends ValidationError {
|
|
83
|
+
constructor(message = "geoengine: geofence_id is required") {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = "GeofenceIDRequiredError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var InvalidLatitudeError = class extends ValidationError {
|
|
89
|
+
constructor(message = "geoengine: latitude must be between -90 and 90 degrees") {
|
|
90
|
+
super(message);
|
|
91
|
+
this.name = "InvalidLatitudeError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var InvalidLongitudeError = class extends ValidationError {
|
|
95
|
+
constructor(message = "geoengine: longitude must be between -180 and 180 degrees") {
|
|
96
|
+
super(message);
|
|
97
|
+
this.name = "InvalidLongitudeError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var InvalidCoordinatesError = class extends ValidationError {
|
|
101
|
+
constructor(message = "geoengine: at least 3 coordinate pairs are required for a polygon") {
|
|
102
|
+
super(message);
|
|
103
|
+
this.name = "InvalidCoordinatesError";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var APIError = class extends GeoEngineError {
|
|
107
|
+
statusCode;
|
|
108
|
+
constructor(statusCode, message) {
|
|
109
|
+
super(`geoengine: API error (status ${statusCode}): ${message}`);
|
|
110
|
+
this.name = "APIError";
|
|
111
|
+
this.statusCode = statusCode;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var SpatialAPIError = class extends APIError {
|
|
115
|
+
code;
|
|
116
|
+
statusText;
|
|
117
|
+
details;
|
|
118
|
+
constructor(statusCode, code, message, statusText, details = []) {
|
|
119
|
+
const formattedMessage = code ? `geoengine: spatial API error (status ${statusCode}, code ${code}): ${message}` : `geoengine: spatial API error (status ${statusCode}): ${message}`;
|
|
120
|
+
super(statusCode, formattedMessage);
|
|
121
|
+
this.name = "SpatialAPIError";
|
|
122
|
+
this.code = code;
|
|
123
|
+
this.statusText = statusText;
|
|
124
|
+
this.details = details;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns true if the error indicates the geofence or resource was not found.
|
|
128
|
+
*/
|
|
129
|
+
isNotFound() {
|
|
130
|
+
return this.statusCode === 204 || this.statusCode === 404 || this.code === "NOT_FOUND";
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns true if the error indicates quota limit was hit.
|
|
134
|
+
*/
|
|
135
|
+
isQuotaExceeded() {
|
|
136
|
+
return this.statusCode === 402 || this.code === "QUOTA_EXCEEDED";
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns true if authentication failed.
|
|
140
|
+
*/
|
|
141
|
+
isUnauthorized() {
|
|
142
|
+
return this.statusCode === 401 || this.code === "UNAUTHORIZED" || this.code === "MISSING_API_KEY" || this.code === "MISSING_ORGANIZATION";
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns true if access to the requested resource is forbidden.
|
|
146
|
+
*/
|
|
147
|
+
isForbidden() {
|
|
148
|
+
return this.statusCode === 403 || this.code === "FORBIDDEN";
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var GeofenceNotFoundError = class extends SpatialAPIError {
|
|
152
|
+
constructor(message = "geofence not found", statusCode = 204, details = []) {
|
|
153
|
+
super(statusCode, "NOT_FOUND", message, "Not Found", details);
|
|
154
|
+
this.name = "GeofenceNotFoundError";
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var QuotaExceededError = class extends SpatialAPIError {
|
|
158
|
+
constructor(message = "request quota exceeded", statusCode = 402, details = []) {
|
|
159
|
+
super(statusCode, "QUOTA_EXCEEDED", message, "Payment Required", details);
|
|
160
|
+
this.name = "QuotaExceededError";
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var AuthenticationError = class extends SpatialAPIError {
|
|
164
|
+
constructor(message = "unauthorized API request", statusCode = 401, details = []) {
|
|
165
|
+
super(statusCode, "UNAUTHORIZED", message, "Unauthorized", details);
|
|
166
|
+
this.name = "AuthenticationError";
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var ForbiddenError = class extends SpatialAPIError {
|
|
170
|
+
constructor(message = "access forbidden", statusCode = 403, details = []) {
|
|
171
|
+
super(statusCode, "FORBIDDEN", message, "Forbidden", details);
|
|
172
|
+
this.name = "ForbiddenError";
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var TimeoutError = class extends GeoEngineError {
|
|
176
|
+
constructor(timeoutMs) {
|
|
177
|
+
super(`geoengine: request exceeded the timeout limit of ${timeoutMs}ms`);
|
|
178
|
+
this.name = "TimeoutError";
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/crypto.ts
|
|
183
|
+
var import_node_crypto = require("crypto");
|
|
184
|
+
function generateHMACSignature(key, timestamp) {
|
|
185
|
+
if (!key) {
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
return (0, import_node_crypto.createHmac)("sha256", key).update(timestamp.toString()).digest("hex");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/http.ts
|
|
192
|
+
var USER_AGENT = "GeoEngineNodeSDK/2.0.0";
|
|
193
|
+
function parseHttpError(statusCode, bodyText, isSpatial = false) {
|
|
194
|
+
let parsedErrorContainer = null;
|
|
195
|
+
try {
|
|
196
|
+
parsedErrorContainer = JSON.parse(bodyText);
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
const container = parsedErrorContainer?.error;
|
|
200
|
+
let code = container?.status ?? "";
|
|
201
|
+
let message = container?.message ?? parsedErrorContainer?.message ?? bodyText.trim();
|
|
202
|
+
const details = container?.details ?? [];
|
|
203
|
+
if (container?.details && container.details.length > 0) {
|
|
204
|
+
for (const detail of container.details) {
|
|
205
|
+
if (detail.reason) {
|
|
206
|
+
code = detail.reason;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!code) {
|
|
212
|
+
switch (statusCode) {
|
|
213
|
+
case 204:
|
|
214
|
+
case 404:
|
|
215
|
+
code = "NOT_FOUND";
|
|
216
|
+
break;
|
|
217
|
+
case 402:
|
|
218
|
+
code = "QUOTA_EXCEEDED";
|
|
219
|
+
break;
|
|
220
|
+
case 401:
|
|
221
|
+
code = "UNAUTHORIZED";
|
|
222
|
+
break;
|
|
223
|
+
case 403:
|
|
224
|
+
code = "FORBIDDEN";
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
code = "";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!message) {
|
|
231
|
+
message = `HTTP ${statusCode}`;
|
|
232
|
+
}
|
|
233
|
+
if (statusCode === 204 || statusCode === 404 || code === "NOT_FOUND") {
|
|
234
|
+
return new GeofenceNotFoundError(message, statusCode, details);
|
|
235
|
+
}
|
|
236
|
+
if (statusCode === 402 || code === "QUOTA_EXCEEDED") {
|
|
237
|
+
return new QuotaExceededError(message, statusCode, details);
|
|
238
|
+
}
|
|
239
|
+
if (statusCode === 401 || code === "UNAUTHORIZED" || code === "MISSING_API_KEY" || code === "MISSING_ORGANIZATION") {
|
|
240
|
+
return new AuthenticationError(message, statusCode, details);
|
|
241
|
+
}
|
|
242
|
+
if (statusCode === 403 || code === "FORBIDDEN") {
|
|
243
|
+
return new ForbiddenError(message, statusCode, details);
|
|
244
|
+
}
|
|
245
|
+
if (isSpatial) {
|
|
246
|
+
return new SpatialAPIError(statusCode, code, message, void 0, details);
|
|
247
|
+
}
|
|
248
|
+
return new APIError(statusCode, message);
|
|
249
|
+
}
|
|
250
|
+
var HttpClient = class {
|
|
251
|
+
config;
|
|
252
|
+
constructor(options = {}) {
|
|
253
|
+
const defaultManagement = "https://management.geoengine.dev";
|
|
254
|
+
const defaultIngest = "https://ingest.geoengine.dev";
|
|
255
|
+
const defaultApiService = "https://api.geoengine.dev";
|
|
256
|
+
this.config = {
|
|
257
|
+
apiKey: options.apiKey ?? "",
|
|
258
|
+
jwtToken: options.jwtToken,
|
|
259
|
+
environment: options.environment ?? "live",
|
|
260
|
+
managementUrl: options.baseUrl ?? options.managementUrl ?? defaultManagement,
|
|
261
|
+
ingestUrl: options.baseUrl ?? options.ingestUrl ?? defaultIngest,
|
|
262
|
+
apiServiceUrl: options.baseUrl ?? options.apiServiceUrl ?? defaultApiService,
|
|
263
|
+
timeout: options.timeout ?? 1e4,
|
|
264
|
+
maxRetries: options.maxRetries ?? 2,
|
|
265
|
+
batchSize: options.batchSize ?? 100,
|
|
266
|
+
flushInterval: options.flushInterval ?? 500,
|
|
267
|
+
bufferSize: options.bufferSize ?? 5e3,
|
|
268
|
+
fetch: options.fetch ?? globalThis.fetch
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
get options() {
|
|
272
|
+
return this.config;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Executes an HTTP request with timeout, authentication headers and exponential backoff retry.
|
|
276
|
+
*/
|
|
277
|
+
async request(opts) {
|
|
278
|
+
const method = opts.method ?? "POST";
|
|
279
|
+
const timeoutMs = opts.timeout ?? this.config.timeout;
|
|
280
|
+
const maxRetries = this.config.maxRetries;
|
|
281
|
+
let attempt = 0;
|
|
282
|
+
while (true) {
|
|
283
|
+
attempt++;
|
|
284
|
+
const controller = new globalThis.AbortController();
|
|
285
|
+
const timeoutId = globalThis.setTimeout(() => controller.abort(), timeoutMs);
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
const headers = {
|
|
288
|
+
"Content-Type": "application/json",
|
|
289
|
+
"X-API-Key": this.config.apiKey,
|
|
290
|
+
"X-Geo-Environment": this.config.environment,
|
|
291
|
+
"X-Request-Time": now.toString(),
|
|
292
|
+
"X-Signature": generateHMACSignature(this.config.apiKey, now),
|
|
293
|
+
"User-Agent": USER_AGENT
|
|
294
|
+
};
|
|
295
|
+
if (this.config.jwtToken) {
|
|
296
|
+
headers["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
const response = await this.config.fetch(opts.endpoint, {
|
|
300
|
+
method,
|
|
301
|
+
headers,
|
|
302
|
+
body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0,
|
|
303
|
+
signal: controller.signal
|
|
304
|
+
});
|
|
305
|
+
globalThis.clearTimeout(timeoutId);
|
|
306
|
+
if (response.status === 204) {
|
|
307
|
+
if (opts.isSpatial) {
|
|
308
|
+
throw new GeofenceNotFoundError("geofence not found", 204);
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
if ((response.status === 429 || response.status >= 500) && attempt <= maxRetries) {
|
|
313
|
+
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
314
|
+
await new Promise(
|
|
315
|
+
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
316
|
+
);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const responseText = await response.text();
|
|
320
|
+
if (!response.ok) {
|
|
321
|
+
throw parseHttpError(response.status, responseText, opts.isSpatial);
|
|
322
|
+
}
|
|
323
|
+
if (!responseText || responseText.trim() === "") {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
const json = JSON.parse(responseText);
|
|
327
|
+
if (opts.isSpatial && typeof json === "object" && json !== null && "success" in json) {
|
|
328
|
+
if (!json.success) {
|
|
329
|
+
throw parseHttpError(response.status, responseText, true);
|
|
330
|
+
}
|
|
331
|
+
return json.data;
|
|
332
|
+
}
|
|
333
|
+
return json;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
globalThis.clearTimeout(timeoutId);
|
|
336
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
337
|
+
throw new TimeoutError(timeoutMs);
|
|
338
|
+
}
|
|
339
|
+
if (err instanceof APIError) {
|
|
340
|
+
throw err;
|
|
341
|
+
}
|
|
342
|
+
if (attempt <= maxRetries) {
|
|
343
|
+
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
344
|
+
await new Promise(
|
|
345
|
+
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
346
|
+
);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
throw err;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/ingester.ts
|
|
356
|
+
var import_node_timers = require("timers");
|
|
357
|
+
var AsyncIngester = class {
|
|
358
|
+
client;
|
|
359
|
+
bufferSize;
|
|
360
|
+
batchSize;
|
|
361
|
+
intervalMs;
|
|
362
|
+
queue = [];
|
|
363
|
+
inFlightPromises = /* @__PURE__ */ new Set();
|
|
364
|
+
timer = null;
|
|
365
|
+
isClosed = false;
|
|
366
|
+
constructor(client, bufferSize = 5e3, batchSize = 100, flushIntervalMs = 500) {
|
|
367
|
+
this.client = client;
|
|
368
|
+
this.bufferSize = bufferSize;
|
|
369
|
+
this.batchSize = batchSize;
|
|
370
|
+
this.intervalMs = flushIntervalMs;
|
|
371
|
+
this.timer = (0, import_node_timers.setInterval)(() => {
|
|
372
|
+
void this.flush();
|
|
373
|
+
}, this.intervalMs);
|
|
374
|
+
if (this.timer && typeof this.timer.unref === "function") {
|
|
375
|
+
this.timer.unref();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Non-blockingly appends a location ping to the ingestion buffer queue.
|
|
380
|
+
*
|
|
381
|
+
* @param ping Location ping object
|
|
382
|
+
* @returns true if successfully queued, false if queue is full or ingester is stopped
|
|
383
|
+
*/
|
|
384
|
+
enqueue(ping) {
|
|
385
|
+
if (!ping || this.isClosed) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (this.queue.length >= this.bufferSize) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
this.queue.push(ping);
|
|
392
|
+
if (this.queue.length >= this.batchSize) {
|
|
393
|
+
void this.flush();
|
|
394
|
+
}
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Flushes current queued batch of location telemetry items.
|
|
399
|
+
*/
|
|
400
|
+
async flush() {
|
|
401
|
+
if (this.queue.length === 0) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const batch = this.queue.splice(0, this.batchSize);
|
|
405
|
+
if (batch.length === 0) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const flushPromise = Promise.all(
|
|
409
|
+
batch.map(
|
|
410
|
+
(item) => this.client.sendLocation(item.deviceId, item.latitude, item.longitude).catch(() => {
|
|
411
|
+
})
|
|
412
|
+
)
|
|
413
|
+
).finally(() => {
|
|
414
|
+
this.inFlightPromises.delete(flushPromise);
|
|
415
|
+
});
|
|
416
|
+
this.inFlightPromises.add(flushPromise);
|
|
417
|
+
await flushPromise;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Drains all remaining pending items, halts worker timer, and releases resources.
|
|
421
|
+
* Safe to call multiple times.
|
|
422
|
+
*/
|
|
423
|
+
async stop() {
|
|
424
|
+
if (this.isClosed) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
this.isClosed = true;
|
|
428
|
+
if (this.timer) {
|
|
429
|
+
(0, import_node_timers.clearInterval)(this.timer);
|
|
430
|
+
this.timer = null;
|
|
431
|
+
}
|
|
432
|
+
while (this.queue.length > 0) {
|
|
433
|
+
await this.flush();
|
|
434
|
+
}
|
|
435
|
+
if (this.inFlightPromises.size > 0) {
|
|
436
|
+
await Promise.all(Array.from(this.inFlightPromises));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// src/models.ts
|
|
442
|
+
var SpatialValidationResult = class {
|
|
443
|
+
inside;
|
|
444
|
+
geofenceId;
|
|
445
|
+
geofenceName;
|
|
446
|
+
latitude;
|
|
447
|
+
longitude;
|
|
448
|
+
constructor(data) {
|
|
449
|
+
this.inside = Boolean(data.inside);
|
|
450
|
+
this.geofenceId = data.geofence_id ?? data.geofenceId ?? "";
|
|
451
|
+
this.geofenceName = data.geofence_name ?? data.geofenceName;
|
|
452
|
+
this.latitude = data.latitude;
|
|
453
|
+
this.longitude = data.longitude;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Returns true if the coordinate is inside the geofence.
|
|
457
|
+
*/
|
|
458
|
+
isInside() {
|
|
459
|
+
return this.inside;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Returns true if the coordinate is outside the geofence.
|
|
463
|
+
*/
|
|
464
|
+
isOutside() {
|
|
465
|
+
return !this.inside;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Returns latitude and longitude as a [latitude, longitude] tuple.
|
|
469
|
+
*/
|
|
470
|
+
coordinates() {
|
|
471
|
+
return [this.latitude, this.longitude];
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Formats the result into a clean, human-readable log string matching Go's String().
|
|
475
|
+
*/
|
|
476
|
+
toString() {
|
|
477
|
+
const status = this.inside ? "INSIDE" : "OUTSIDE";
|
|
478
|
+
const name = this.geofenceName || "unnamed";
|
|
479
|
+
return `[${status}] geofence=${this.geofenceId} (${name}) at (${this.latitude.toFixed(6)}, ${this.longitude.toFixed(6)})`;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
var SpatialGeneralResult = class {
|
|
483
|
+
inside;
|
|
484
|
+
totalMatches;
|
|
485
|
+
matchedGeofences;
|
|
486
|
+
latitude;
|
|
487
|
+
longitude;
|
|
488
|
+
constructor(data) {
|
|
489
|
+
this.inside = Boolean(data.inside);
|
|
490
|
+
this.totalMatches = data.total_matches ?? data.totalMatches ?? (data.matched_geofences?.length ?? data.matchedGeofences?.length ?? 0);
|
|
491
|
+
this.matchedGeofences = data.matched_geofences ?? data.matchedGeofences ?? [];
|
|
492
|
+
this.latitude = data.latitude;
|
|
493
|
+
this.longitude = data.longitude;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Returns true if the coordinate falls inside at least one geofence.
|
|
497
|
+
*/
|
|
498
|
+
isInside() {
|
|
499
|
+
return this.inside;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Returns true if one or more geofences matched the point.
|
|
503
|
+
*/
|
|
504
|
+
hasMatches() {
|
|
505
|
+
return this.totalMatches > 0;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Returns the first matched geofence, or null if no matches found.
|
|
509
|
+
*/
|
|
510
|
+
firstMatch() {
|
|
511
|
+
return this.matchedGeofences[0] ?? null;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Returns all matched geofence IDs as a string array.
|
|
515
|
+
*/
|
|
516
|
+
geofenceIds() {
|
|
517
|
+
return this.matchedGeofences.map((m) => m.id);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Returns all matched geofence names as a string array.
|
|
521
|
+
*/
|
|
522
|
+
geofenceNames() {
|
|
523
|
+
return this.matchedGeofences.map((m) => m.name);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Checks whether a specific geofence ID or name is among the matches.
|
|
527
|
+
*/
|
|
528
|
+
containsGeofence(idOrName) {
|
|
529
|
+
return this.findMatch(idOrName) !== null;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Searches for a matched geofence by ID or name and returns it if found, or null.
|
|
533
|
+
*/
|
|
534
|
+
findMatch(idOrName) {
|
|
535
|
+
for (const match of this.matchedGeofences) {
|
|
536
|
+
if (match.id === idOrName || match.name === idOrName) {
|
|
537
|
+
return match;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Returns latitude and longitude as a [latitude, longitude] tuple.
|
|
544
|
+
*/
|
|
545
|
+
coordinates() {
|
|
546
|
+
return [this.latitude, this.longitude];
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Formats the result into a clean, human-readable log string matching Go's String().
|
|
550
|
+
*/
|
|
551
|
+
toString() {
|
|
552
|
+
const status = this.inside ? "INSIDE" : "OUTSIDE";
|
|
553
|
+
const names = this.geofenceNames().join(", ");
|
|
554
|
+
return `[${status}] matches=${this.totalMatches} (${names}) at (${this.latitude.toFixed(6)}, ${this.longitude.toFixed(6)})`;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
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
|
+
// src/spatial.ts
|
|
604
|
+
var SpatialService = class {
|
|
605
|
+
constructor(http) {
|
|
606
|
+
this.http = http;
|
|
607
|
+
}
|
|
608
|
+
http;
|
|
609
|
+
/**
|
|
610
|
+
* Convenience method to check if coordinates fall within a specific geofence.
|
|
611
|
+
*
|
|
612
|
+
* @param geofenceId Unique identifier of the geofence
|
|
613
|
+
* @param lat Decimal latitude [-90, 90]
|
|
614
|
+
* @param lng Decimal longitude [-180, 180]
|
|
615
|
+
* @returns SpatialValidationResult
|
|
616
|
+
*/
|
|
617
|
+
async validatePoint(geofenceId, lat, lng) {
|
|
618
|
+
const validId = validateGeofenceId(geofenceId);
|
|
619
|
+
validateCoordinates(lat, lng);
|
|
620
|
+
return this.validateLocation({
|
|
621
|
+
geofenceId: validId,
|
|
622
|
+
latitude: lat,
|
|
623
|
+
longitude: lng
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Checks if coordinates fall inside the specified geofence using the api-service.
|
|
628
|
+
*
|
|
629
|
+
* @param req SpatialValidationRequest containing geofenceId, latitude, and longitude
|
|
630
|
+
* @returns SpatialValidationResult
|
|
631
|
+
*/
|
|
632
|
+
async validateLocation(req) {
|
|
633
|
+
const validId = validateGeofenceId(req.geofenceId);
|
|
634
|
+
validateCoordinates(req.latitude, req.longitude);
|
|
635
|
+
const endpoint = `${this.http.options.apiServiceUrl.replace(/\/+$/, "")}/api/spatial/validate`;
|
|
636
|
+
const payload = {
|
|
637
|
+
geofence_id: validId,
|
|
638
|
+
latitude: req.latitude,
|
|
639
|
+
longitude: req.longitude
|
|
640
|
+
};
|
|
641
|
+
const rawData = await this.http.request({
|
|
642
|
+
endpoint,
|
|
643
|
+
method: "POST",
|
|
644
|
+
body: payload,
|
|
645
|
+
isSpatial: true
|
|
646
|
+
});
|
|
647
|
+
return new SpatialValidationResult(rawData);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Checks whether coordinates intersect any geofence belonging to the organization.
|
|
651
|
+
*
|
|
652
|
+
* @param lat Decimal latitude [-90, 90]
|
|
653
|
+
* @param lng Decimal longitude [-180, 180]
|
|
654
|
+
* @returns SpatialGeneralResult
|
|
655
|
+
*/
|
|
656
|
+
async validateGeneral(lat, lng) {
|
|
657
|
+
validateCoordinates(lat, lng);
|
|
658
|
+
return this.validateGeneralLocation({
|
|
659
|
+
latitude: lat,
|
|
660
|
+
longitude: lng
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Checks whether coordinates intersect any geofence using the api-service.
|
|
665
|
+
*
|
|
666
|
+
* @param req SpatialGeneralRequest containing latitude and longitude
|
|
667
|
+
* @returns SpatialGeneralResult
|
|
668
|
+
*/
|
|
669
|
+
async validateGeneralLocation(req) {
|
|
670
|
+
validateCoordinates(req.latitude, req.longitude);
|
|
671
|
+
const endpoint = `${this.http.options.apiServiceUrl.replace(/\/+$/, "")}/api/spatial/validate-general`;
|
|
672
|
+
const payload = {
|
|
673
|
+
latitude: req.latitude,
|
|
674
|
+
longitude: req.longitude
|
|
675
|
+
};
|
|
676
|
+
const rawData = await this.http.request({
|
|
677
|
+
endpoint,
|
|
678
|
+
method: "POST",
|
|
679
|
+
body: payload,
|
|
680
|
+
isSpatial: true
|
|
681
|
+
});
|
|
682
|
+
return new SpatialGeneralResult(rawData);
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Initializes a fluent query builder for spatial coordinate validation.
|
|
686
|
+
*
|
|
687
|
+
* @param lat Decimal latitude
|
|
688
|
+
* @param lng Decimal longitude
|
|
689
|
+
* @returns SpatialCheckBuilder
|
|
690
|
+
*/
|
|
691
|
+
check(lat, lng) {
|
|
692
|
+
return new SpatialCheckBuilder(this, lat, lng);
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
var SpatialCheckBuilder = class {
|
|
696
|
+
constructor(service, lat, lng) {
|
|
697
|
+
this.service = service;
|
|
698
|
+
this.lat = lat;
|
|
699
|
+
this.lng = lng;
|
|
700
|
+
}
|
|
701
|
+
service;
|
|
702
|
+
lat;
|
|
703
|
+
lng;
|
|
704
|
+
/**
|
|
705
|
+
* Configures validation targeting a specific geofence ID.
|
|
706
|
+
*/
|
|
707
|
+
inGeofence(geofenceId) {
|
|
708
|
+
return new SingleGeofenceCheck(this.service, geofenceId, this.lat, this.lng);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Configures validation against all organization geofences.
|
|
712
|
+
*/
|
|
713
|
+
inAllGeofences() {
|
|
714
|
+
return new GeneralGeofenceCheck(this.service, this.lat, this.lng);
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
var SingleGeofenceCheck = class {
|
|
718
|
+
constructor(service, geofenceId, lat, lng) {
|
|
719
|
+
this.service = service;
|
|
720
|
+
this.geofenceId = geofenceId;
|
|
721
|
+
this.lat = lat;
|
|
722
|
+
this.lng = lng;
|
|
723
|
+
}
|
|
724
|
+
service;
|
|
725
|
+
geofenceId;
|
|
726
|
+
lat;
|
|
727
|
+
lng;
|
|
728
|
+
/**
|
|
729
|
+
* Performs the single geofence spatial query.
|
|
730
|
+
*/
|
|
731
|
+
async execute() {
|
|
732
|
+
return this.service.validatePoint(this.geofenceId, this.lat, this.lng);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Alias for execute().
|
|
736
|
+
*/
|
|
737
|
+
async executeSingle() {
|
|
738
|
+
return this.execute();
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Alias for execute().
|
|
742
|
+
*/
|
|
743
|
+
async validate() {
|
|
744
|
+
return this.execute();
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
var GeneralGeofenceCheck = class {
|
|
748
|
+
constructor(service, lat, lng) {
|
|
749
|
+
this.service = service;
|
|
750
|
+
this.lat = lat;
|
|
751
|
+
this.lng = lng;
|
|
752
|
+
}
|
|
753
|
+
service;
|
|
754
|
+
lat;
|
|
755
|
+
lng;
|
|
756
|
+
/**
|
|
757
|
+
* Performs the general spatial query against all organization geofences.
|
|
758
|
+
*/
|
|
759
|
+
async execute() {
|
|
760
|
+
return this.service.validateGeneral(this.lat, this.lng);
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Alias for execute().
|
|
764
|
+
*/
|
|
765
|
+
async executeGeneral() {
|
|
766
|
+
return this.execute();
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Alias for execute().
|
|
770
|
+
*/
|
|
771
|
+
async validate() {
|
|
772
|
+
return this.execute();
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// src/client.ts
|
|
777
|
+
var GeoEngine = class {
|
|
778
|
+
http;
|
|
779
|
+
isClosed = false;
|
|
780
|
+
/**
|
|
781
|
+
* Spatial provides point-in-polygon querying and geofence validation capabilities.
|
|
782
|
+
*/
|
|
783
|
+
spatial;
|
|
784
|
+
/**
|
|
785
|
+
* Alias for spatial (to maintain exact casing compatibility with Go client.Spatial).
|
|
786
|
+
*/
|
|
787
|
+
Spatial;
|
|
788
|
+
/**
|
|
789
|
+
* Initializes a new GeoEngine client instance.
|
|
790
|
+
*
|
|
791
|
+
* @param apiKey Your GeoEngine API Key (required)
|
|
792
|
+
* @param options Optional configuration parameters
|
|
793
|
+
*/
|
|
794
|
+
constructor(apiKeyOrOptions, maybeOptions = {}) {
|
|
795
|
+
let resolvedOptions;
|
|
796
|
+
if (typeof apiKeyOrOptions === "string") {
|
|
797
|
+
resolvedOptions = { ...maybeOptions, apiKey: apiKeyOrOptions };
|
|
798
|
+
} else if (typeof apiKeyOrOptions === "object" && apiKeyOrOptions !== null) {
|
|
799
|
+
resolvedOptions = { ...apiKeyOrOptions };
|
|
800
|
+
} else {
|
|
801
|
+
resolvedOptions = {};
|
|
802
|
+
}
|
|
803
|
+
if (!resolvedOptions.apiKey || resolvedOptions.apiKey.trim() === "") {
|
|
804
|
+
throw new ValidationError("GeoEngine: API Key es requerida.");
|
|
805
|
+
}
|
|
806
|
+
this.http = new HttpClient(resolvedOptions);
|
|
807
|
+
this.spatial = new SpatialService(this.http);
|
|
808
|
+
this.Spatial = this.spatial;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Current configuration options.
|
|
812
|
+
*/
|
|
813
|
+
get options() {
|
|
814
|
+
return this.http.options;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Sends device coordinates over HTTP REST.
|
|
818
|
+
* Equivalent to Go's Client.SendLocation.
|
|
819
|
+
*
|
|
820
|
+
* @param deviceId Unique vehicle/device identifier
|
|
821
|
+
* @param lat Decimal latitude
|
|
822
|
+
* @param lng Decimal longitude
|
|
823
|
+
*/
|
|
824
|
+
async sendLocation(deviceId, lat, lng) {
|
|
825
|
+
if (this.isClosed) {
|
|
826
|
+
throw new ClientClosedError();
|
|
827
|
+
}
|
|
828
|
+
const validId = validateDeviceId(deviceId);
|
|
829
|
+
const payload = {
|
|
830
|
+
device_id: validId,
|
|
831
|
+
latitude: lat,
|
|
832
|
+
longitude: lng,
|
|
833
|
+
timestamp: Math.floor(Date.now() / 1e3)
|
|
834
|
+
};
|
|
835
|
+
const endpoint = `${this.http.options.ingestUrl.replace(/\/+$/, "")}/ingest`;
|
|
836
|
+
await this.http.request({
|
|
837
|
+
endpoint,
|
|
838
|
+
method: "POST",
|
|
839
|
+
body: payload
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Creates a spatial geofence polygon in PostGIS via the management REST API.
|
|
844
|
+
* Automatically validates and closes the polygon ring.
|
|
845
|
+
* Equivalent to Go's Client.CreateGeofence.
|
|
846
|
+
*
|
|
847
|
+
* @param name Geofence name
|
|
848
|
+
* @param coordinates Array of [latitude, longitude] pairs (at least 3 coordinates)
|
|
849
|
+
* @param webhookUrl Optional webhook URL triggered upon enter/exit
|
|
850
|
+
*/
|
|
851
|
+
async createGeofence(name, coordinates, webhookUrl) {
|
|
852
|
+
if (this.isClosed) {
|
|
853
|
+
throw new ClientClosedError();
|
|
854
|
+
}
|
|
855
|
+
if (!name || typeof name !== "string" || name.trim() === "") {
|
|
856
|
+
throw new ValidationError("geoengine: name is required");
|
|
857
|
+
}
|
|
858
|
+
const polygon = validateAndNormalizePolygon(coordinates);
|
|
859
|
+
const payload = {
|
|
860
|
+
name: name.trim(),
|
|
861
|
+
webhook_url: webhookUrl,
|
|
862
|
+
geojson: {
|
|
863
|
+
type: "Polygon",
|
|
864
|
+
coordinates: [polygon]
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
const endpoint = `${this.http.options.managementUrl.replace(/\/+$/, "")}/geofences`;
|
|
868
|
+
return this.http.request({
|
|
869
|
+
endpoint,
|
|
870
|
+
method: "POST",
|
|
871
|
+
body: payload
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
// --- Spatial Validation Direct Shortcuts ---
|
|
875
|
+
/**
|
|
876
|
+
* Validates if coordinates fall within a geofence by ID via the Spatial service.
|
|
877
|
+
* Shortcut matching Go's Client.ValidateSpatialPoint.
|
|
878
|
+
*/
|
|
879
|
+
async validateSpatialPoint(geofenceId, lat, lng) {
|
|
880
|
+
if (this.isClosed) {
|
|
881
|
+
throw new ClientClosedError();
|
|
882
|
+
}
|
|
883
|
+
return this.spatial.validatePoint(geofenceId, lat, lng);
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Validates if coordinates fall within a geofence via the Spatial service.
|
|
887
|
+
* Shortcut matching Go's Client.ValidateSpatialLocation.
|
|
888
|
+
*/
|
|
889
|
+
async validateSpatialLocation(req) {
|
|
890
|
+
if (this.isClosed) {
|
|
891
|
+
throw new ClientClosedError();
|
|
892
|
+
}
|
|
893
|
+
return this.spatial.validateLocation(req);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Validates coordinates against all active geofences via the Spatial service.
|
|
897
|
+
* Shortcut matching Go's Client.ValidateSpatialGeneral.
|
|
898
|
+
*/
|
|
899
|
+
async validateSpatialGeneral(lat, lng) {
|
|
900
|
+
if (this.isClosed) {
|
|
901
|
+
throw new ClientClosedError();
|
|
902
|
+
}
|
|
903
|
+
return this.spatial.validateGeneral(lat, lng);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Validates coordinates against all active geofences via the Spatial service.
|
|
907
|
+
* Shortcut matching Go's Client.ValidateSpatialGeneralLocation.
|
|
908
|
+
*/
|
|
909
|
+
async validateSpatialGeneralLocation(req) {
|
|
910
|
+
if (this.isClosed) {
|
|
911
|
+
throw new ClientClosedError();
|
|
912
|
+
}
|
|
913
|
+
return this.spatial.validateGeneralLocation(req);
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Instantiates a new AsyncIngester connected to this client.
|
|
917
|
+
* Matches Go NewAsyncIngester.
|
|
918
|
+
*
|
|
919
|
+
* @param bufferSize Queue buffer capacity (default: options.bufferSize ?? 5000)
|
|
920
|
+
* @param batchSize Batch size before flushing (default: options.batchSize ?? 100)
|
|
921
|
+
* @param flushIntervalMs Flush interval in ms (default: options.flushInterval ?? 500)
|
|
922
|
+
*/
|
|
923
|
+
createAsyncIngester(bufferSize, batchSize, flushIntervalMs) {
|
|
924
|
+
return new AsyncIngester(
|
|
925
|
+
this,
|
|
926
|
+
bufferSize ?? this.http.options.bufferSize,
|
|
927
|
+
batchSize ?? this.http.options.batchSize,
|
|
928
|
+
flushIntervalMs ?? this.http.options.flushInterval
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Closes the client, marking it inactive. Idempotent.
|
|
933
|
+
* Subsequent requests will throw ClientClosedError.
|
|
934
|
+
* Equivalent to Go's Client.Close.
|
|
935
|
+
*/
|
|
936
|
+
close() {
|
|
937
|
+
this.isClosed = true;
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// src/index.ts
|
|
942
|
+
var index_default = GeoEngine;
|
|
943
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
944
|
+
0 && (module.exports = {
|
|
945
|
+
APIError,
|
|
946
|
+
AsyncIngester,
|
|
947
|
+
AuthenticationError,
|
|
948
|
+
Client,
|
|
949
|
+
ClientClosedError,
|
|
950
|
+
DeviceIDRequiredError,
|
|
951
|
+
ForbiddenError,
|
|
952
|
+
GeneralGeofenceCheck,
|
|
953
|
+
GeoEngine,
|
|
954
|
+
GeoEngineError,
|
|
955
|
+
GeofenceIDRequiredError,
|
|
956
|
+
GeofenceNotFoundError,
|
|
957
|
+
InvalidCoordinatesError,
|
|
958
|
+
InvalidLatitudeError,
|
|
959
|
+
InvalidLongitudeError,
|
|
960
|
+
QuotaExceededError,
|
|
961
|
+
SingleGeofenceCheck,
|
|
962
|
+
SpatialAPIError,
|
|
963
|
+
SpatialCheckBuilder,
|
|
964
|
+
SpatialGeneralResult,
|
|
965
|
+
SpatialService,
|
|
966
|
+
SpatialValidationResult,
|
|
967
|
+
TimeoutError,
|
|
968
|
+
ValidationError,
|
|
969
|
+
generateHMACSignature,
|
|
970
|
+
validateAndNormalizePolygon,
|
|
971
|
+
validateCoordinates,
|
|
972
|
+
validateDeviceId,
|
|
973
|
+
validateGeofenceId
|
|
974
|
+
});
|
|
975
|
+
//# sourceMappingURL=index.cjs.map
|