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.cjs
CHANGED
|
@@ -1,283 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
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
|
+
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
AsyncIngester: () => AsyncIngester,
|
|
26
|
-
AuthenticationError: () => AuthenticationError,
|
|
27
|
-
Client: () => GeoEngine,
|
|
28
|
-
ClientClosedError: () => ClientClosedError,
|
|
29
|
-
DeviceIDRequiredError: () => DeviceIDRequiredError,
|
|
30
|
-
EmailRequiredError: () => EmailRequiredError,
|
|
31
|
-
ForbiddenError: () => ForbiddenError,
|
|
32
|
-
GeneralGeofenceCheck: () => GeneralGeofenceCheck,
|
|
33
|
-
GeoEngine: () => GeoEngine,
|
|
34
|
-
GeoEngineError: () => GeoEngineError,
|
|
35
|
-
GeoIdentityService: () => GeoIdentityService,
|
|
36
|
-
GeofenceIDRequiredError: () => GeofenceIDRequiredError,
|
|
37
|
-
GeofenceNotFoundError: () => GeofenceNotFoundError,
|
|
38
|
-
InvalidCoordinatesError: () => InvalidCoordinatesError,
|
|
39
|
-
InvalidLatitudeError: () => InvalidLatitudeError,
|
|
40
|
-
InvalidLongitudeError: () => InvalidLongitudeError,
|
|
41
|
-
InvitationPendingError: () => InvitationPendingError,
|
|
42
|
-
LastAdminError: () => LastAdminError,
|
|
43
|
-
LastSubjectError: () => LastSubjectError,
|
|
44
|
-
QuotaExceededError: () => QuotaExceededError,
|
|
45
|
-
RoleRequiredError: () => RoleRequiredError,
|
|
46
|
-
Roles: () => Roles,
|
|
47
|
-
RuleActions: () => RuleActions,
|
|
48
|
-
RuleIDRequiredError: () => RuleIDRequiredError,
|
|
49
|
-
RuleNameRequiredError: () => RuleNameRequiredError,
|
|
50
|
-
RuleNotFoundError: () => RuleNotFoundError,
|
|
51
|
-
SingleGeofenceCheck: () => SingleGeofenceCheck,
|
|
52
|
-
SpatialAPIError: () => SpatialAPIError,
|
|
53
|
-
SpatialCheckBuilder: () => SpatialCheckBuilder,
|
|
54
|
-
SpatialGeneralResult: () => SpatialGeneralResult,
|
|
55
|
-
SpatialService: () => SpatialService,
|
|
56
|
-
SpatialValidationResult: () => SpatialValidationResult,
|
|
57
|
-
SubjectTypes: () => SubjectTypes,
|
|
58
|
-
TimeoutError: () => TimeoutError,
|
|
59
|
-
UserAlreadyExistsError: () => UserAlreadyExistsError,
|
|
60
|
-
UserIDRequiredError: () => UserIDRequiredError,
|
|
61
|
-
UserNotFoundError: () => UserNotFoundError,
|
|
62
|
-
UserStatus: () => UserStatus,
|
|
63
|
-
UsersService: () => UsersService,
|
|
64
|
-
ValidationError: () => ValidationError,
|
|
65
|
-
default: () => index_default,
|
|
66
|
-
generateHMACSignature: () => generateHMACSignature,
|
|
67
|
-
polygonFromLatLng: () => polygonFromLatLng,
|
|
68
|
-
validateAndNormalizePolygon: () => validateAndNormalizePolygon,
|
|
69
|
-
validateCoordinates: () => validateCoordinates,
|
|
70
|
-
validateDeviceId: () => validateDeviceId,
|
|
71
|
-
validateGeofenceId: () => validateGeofenceId
|
|
72
|
-
});
|
|
73
|
-
module.exports = __toCommonJS(index_exports);
|
|
74
|
-
|
|
75
|
-
// src/errors.ts
|
|
76
|
-
var GeoEngineError = class extends Error {
|
|
77
|
-
constructor(message) {
|
|
78
|
-
super(message);
|
|
79
|
-
this.name = "GeoEngineError";
|
|
80
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var ClientClosedError = class extends GeoEngineError {
|
|
84
|
-
constructor(message = "geoengine: client is closed") {
|
|
85
|
-
super(message);
|
|
86
|
-
this.name = "ClientClosedError";
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
var ValidationError = class extends GeoEngineError {
|
|
90
|
-
constructor(message) {
|
|
91
|
-
super(message);
|
|
92
|
-
this.name = "ValidationError";
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
var DeviceIDRequiredError = class extends ValidationError {
|
|
96
|
-
constructor(message = "geoengine: device_id is required") {
|
|
97
|
-
super(message);
|
|
98
|
-
this.name = "DeviceIDRequiredError";
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var GeofenceIDRequiredError = class extends ValidationError {
|
|
102
|
-
constructor(message = "geoengine: geofence_id is required") {
|
|
103
|
-
super(message);
|
|
104
|
-
this.name = "GeofenceIDRequiredError";
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var InvalidLatitudeError = class extends ValidationError {
|
|
108
|
-
constructor(message = "geoengine: latitude must be between -90 and 90 degrees") {
|
|
109
|
-
super(message);
|
|
110
|
-
this.name = "InvalidLatitudeError";
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var InvalidLongitudeError = class extends ValidationError {
|
|
114
|
-
constructor(message = "geoengine: longitude must be between -180 and 180 degrees") {
|
|
115
|
-
super(message);
|
|
116
|
-
this.name = "InvalidLongitudeError";
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var InvalidCoordinatesError = class extends ValidationError {
|
|
120
|
-
constructor(message = "geoengine: at least 3 coordinate pairs are required for a polygon") {
|
|
121
|
-
super(message);
|
|
122
|
-
this.name = "InvalidCoordinatesError";
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
var APIError = class extends GeoEngineError {
|
|
126
|
-
statusCode;
|
|
127
|
-
constructor(statusCode, message) {
|
|
128
|
-
super(`geoengine: API error (status ${statusCode}): ${message}`);
|
|
129
|
-
this.name = "APIError";
|
|
130
|
-
this.statusCode = statusCode;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var SpatialAPIError = class extends APIError {
|
|
134
|
-
code;
|
|
135
|
-
statusText;
|
|
136
|
-
details;
|
|
137
|
-
constructor(statusCode, code, message, statusText, details = []) {
|
|
138
|
-
const formattedMessage = code ? `geoengine: spatial API error (status ${statusCode}, code ${code}): ${message}` : `geoengine: spatial API error (status ${statusCode}): ${message}`;
|
|
139
|
-
super(statusCode, formattedMessage);
|
|
140
|
-
this.name = "SpatialAPIError";
|
|
141
|
-
this.code = code;
|
|
142
|
-
this.statusText = statusText;
|
|
143
|
-
this.details = details;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns true if the error indicates the geofence or resource was not found.
|
|
147
|
-
*/
|
|
148
|
-
isNotFound() {
|
|
149
|
-
return this.statusCode === 204 || this.statusCode === 404 || this.code === "NOT_FOUND";
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Returns true if the error indicates quota limit was hit.
|
|
153
|
-
*/
|
|
154
|
-
isQuotaExceeded() {
|
|
155
|
-
return this.statusCode === 402 || this.code === "QUOTA_EXCEEDED";
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Returns true if authentication failed.
|
|
159
|
-
*/
|
|
160
|
-
isUnauthorized() {
|
|
161
|
-
return this.statusCode === 401 || this.code === "UNAUTHORIZED" || this.code === "MISSING_API_KEY" || this.code === "MISSING_ORGANIZATION";
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Returns true if access to the requested resource is forbidden.
|
|
165
|
-
*/
|
|
166
|
-
isForbidden() {
|
|
167
|
-
return this.statusCode === 403 || this.code === "FORBIDDEN";
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
var GeofenceNotFoundError = class extends SpatialAPIError {
|
|
171
|
-
constructor(message = "geofence not found", statusCode = 204, details = []) {
|
|
172
|
-
super(statusCode, "NOT_FOUND", message, "Not Found", details);
|
|
173
|
-
this.name = "GeofenceNotFoundError";
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
var QuotaExceededError = class extends SpatialAPIError {
|
|
177
|
-
constructor(message = "request quota exceeded", statusCode = 402, details = []) {
|
|
178
|
-
super(statusCode, "QUOTA_EXCEEDED", message, "Payment Required", details);
|
|
179
|
-
this.name = "QuotaExceededError";
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
var AuthenticationError = class extends SpatialAPIError {
|
|
183
|
-
constructor(message = "unauthorized API request", statusCode = 401, details = []) {
|
|
184
|
-
super(statusCode, "UNAUTHORIZED", message, "Unauthorized", details);
|
|
185
|
-
this.name = "AuthenticationError";
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var ForbiddenError = class extends SpatialAPIError {
|
|
189
|
-
constructor(message = "access forbidden", statusCode = 403, details = []) {
|
|
190
|
-
super(statusCode, "FORBIDDEN", message, "Forbidden", details);
|
|
191
|
-
this.name = "ForbiddenError";
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
var TimeoutError = class extends GeoEngineError {
|
|
195
|
-
constructor(timeoutMs) {
|
|
196
|
-
super(`geoengine: request exceeded the timeout limit of ${timeoutMs}ms`);
|
|
197
|
-
this.name = "TimeoutError";
|
|
198
|
-
}
|
|
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
|
-
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var _chunkA6RGK4MAcjs = require('./chunk-A6RGK4MA.cjs');
|
|
281
36
|
|
|
282
37
|
// src/users.ts
|
|
283
38
|
var Roles = {
|
|
@@ -299,7 +54,7 @@ function toUser(raw) {
|
|
|
299
54
|
name: raw.name,
|
|
300
55
|
role: raw.role,
|
|
301
56
|
status: raw.status,
|
|
302
|
-
permissions: raw.permissions
|
|
57
|
+
permissions: _nullishCoalesce(raw.permissions, () => ( [])),
|
|
303
58
|
createdAt: raw.created_at,
|
|
304
59
|
lastLoginAt: raw.last_login_at
|
|
305
60
|
};
|
|
@@ -309,13 +64,13 @@ function isBlank(value) {
|
|
|
309
64
|
}
|
|
310
65
|
function userPath(userId, suffix = "") {
|
|
311
66
|
if (isBlank(userId)) {
|
|
312
|
-
throw new UserIDRequiredError();
|
|
67
|
+
throw new (0, _chunkA6RGK4MAcjs.UserIDRequiredError)();
|
|
313
68
|
}
|
|
314
69
|
return `/api/users/${encodeURIComponent(userId.trim())}${suffix}`;
|
|
315
70
|
}
|
|
316
71
|
async function apiServiceRequest(http, isClosed, method, path, body) {
|
|
317
72
|
if (isClosed()) {
|
|
318
|
-
throw new ClientClosedError();
|
|
73
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
319
74
|
}
|
|
320
75
|
return http.request({
|
|
321
76
|
endpoint: `${http.options.apiServiceUrl.replace(/\/+$/, "")}${path}`,
|
|
@@ -329,12 +84,12 @@ var UsersService = class {
|
|
|
329
84
|
this.http = http;
|
|
330
85
|
this.isClosed = isClosed;
|
|
331
86
|
}
|
|
332
|
-
|
|
333
|
-
|
|
87
|
+
|
|
88
|
+
|
|
334
89
|
/** Returns the members of the organization. */
|
|
335
90
|
async list() {
|
|
336
91
|
const raw = await this.send("GET", "/api/users");
|
|
337
|
-
return (raw
|
|
92
|
+
return (_nullishCoalesce(raw, () => ( []))).map(toUser);
|
|
338
93
|
}
|
|
339
94
|
/** Returns a single member of the organization. */
|
|
340
95
|
async get(userId) {
|
|
@@ -346,7 +101,7 @@ var UsersService = class {
|
|
|
346
101
|
"GET",
|
|
347
102
|
"/api/users/roles"
|
|
348
103
|
);
|
|
349
|
-
return (raw
|
|
104
|
+
return (_nullishCoalesce(raw, () => ( []))).map((r) => ({ id: r.id, permissions: _nullishCoalesce(r.permissions, () => ( [])) }));
|
|
350
105
|
}
|
|
351
106
|
/**
|
|
352
107
|
* Creates an invitation and emails it to the recipient.
|
|
@@ -354,11 +109,11 @@ var UsersService = class {
|
|
|
354
109
|
* and UserAlreadyExistsError if the email already belongs to the organization.
|
|
355
110
|
*/
|
|
356
111
|
async invite(req) {
|
|
357
|
-
if (isBlank(req
|
|
358
|
-
throw new EmailRequiredError();
|
|
112
|
+
if (isBlank(_optionalChain([req, 'optionalAccess', _ => _.email]))) {
|
|
113
|
+
throw new (0, _chunkA6RGK4MAcjs.EmailRequiredError)();
|
|
359
114
|
}
|
|
360
115
|
if (isBlank(req.role)) {
|
|
361
|
-
throw new RoleRequiredError();
|
|
116
|
+
throw new (0, _chunkA6RGK4MAcjs.RoleRequiredError)();
|
|
362
117
|
}
|
|
363
118
|
const raw = await this.send("POST", "/api/users/invite", {
|
|
364
119
|
email: req.email,
|
|
@@ -380,7 +135,7 @@ var UsersService = class {
|
|
|
380
135
|
*/
|
|
381
136
|
async updateRole(userId, role) {
|
|
382
137
|
if (isBlank(role)) {
|
|
383
|
-
throw new RoleRequiredError();
|
|
138
|
+
throw new (0, _chunkA6RGK4MAcjs.RoleRequiredError)();
|
|
384
139
|
}
|
|
385
140
|
return toUser(await this.send("PATCH", userPath(userId, "/role"), { role }));
|
|
386
141
|
}
|
|
@@ -399,32 +154,32 @@ var UsersService = class {
|
|
|
399
154
|
// src/validation.ts
|
|
400
155
|
function validateCoordinates(lat, lng) {
|
|
401
156
|
if (typeof lat !== "number" || Number.isNaN(lat) || lat < -90 || lat > 90) {
|
|
402
|
-
throw new InvalidLatitudeError();
|
|
157
|
+
throw new (0, _chunkA6RGK4MAcjs.InvalidLatitudeError)();
|
|
403
158
|
}
|
|
404
159
|
if (typeof lng !== "number" || Number.isNaN(lng) || lng < -180 || lng > 180) {
|
|
405
|
-
throw new InvalidLongitudeError();
|
|
160
|
+
throw new (0, _chunkA6RGK4MAcjs.InvalidLongitudeError)();
|
|
406
161
|
}
|
|
407
162
|
}
|
|
408
163
|
function validateDeviceId(deviceId) {
|
|
409
164
|
if (!deviceId || typeof deviceId !== "string" || deviceId.trim() === "") {
|
|
410
|
-
throw new DeviceIDRequiredError();
|
|
165
|
+
throw new (0, _chunkA6RGK4MAcjs.DeviceIDRequiredError)();
|
|
411
166
|
}
|
|
412
167
|
return deviceId.trim();
|
|
413
168
|
}
|
|
414
169
|
function validateGeofenceId(geofenceId) {
|
|
415
170
|
if (!geofenceId || typeof geofenceId !== "string" || geofenceId.trim() === "") {
|
|
416
|
-
throw new GeofenceIDRequiredError();
|
|
171
|
+
throw new (0, _chunkA6RGK4MAcjs.GeofenceIDRequiredError)();
|
|
417
172
|
}
|
|
418
173
|
return geofenceId.trim();
|
|
419
174
|
}
|
|
420
175
|
function validateAndNormalizePolygon(coordinates) {
|
|
421
176
|
if (!Array.isArray(coordinates) || coordinates.length < 3) {
|
|
422
|
-
throw new InvalidCoordinatesError();
|
|
177
|
+
throw new (0, _chunkA6RGK4MAcjs.InvalidCoordinatesError)();
|
|
423
178
|
}
|
|
424
179
|
const polygon = [];
|
|
425
180
|
for (const p of coordinates) {
|
|
426
181
|
if (!Array.isArray(p) || p.length !== 2) {
|
|
427
|
-
throw new ValidationError(
|
|
182
|
+
throw new (0, _chunkA6RGK4MAcjs.ValidationError)(
|
|
428
183
|
`geoengine: invalid coordinate format: ${JSON.stringify(p)} (expected [lat, lng])`
|
|
429
184
|
);
|
|
430
185
|
}
|
|
@@ -459,20 +214,20 @@ function toRule(raw) {
|
|
|
459
214
|
orgId: raw.org_id,
|
|
460
215
|
name: raw.name,
|
|
461
216
|
description: raw.description,
|
|
462
|
-
priority: raw.priority
|
|
217
|
+
priority: _nullishCoalesce(raw.priority, () => ( 0)),
|
|
463
218
|
action: raw.action,
|
|
464
219
|
isActive: Boolean(raw.is_active),
|
|
465
|
-
whiteIpList: raw.white_ip_list
|
|
466
|
-
blackIpList: raw.black_ip_list
|
|
220
|
+
whiteIpList: _nullishCoalesce(raw.white_ip_list, () => ( [])),
|
|
221
|
+
blackIpList: _nullishCoalesce(raw.black_ip_list, () => ( [])),
|
|
467
222
|
blockDatacenter: Boolean(raw.block_datacenter),
|
|
468
223
|
blockTor: Boolean(raw.block_tor),
|
|
469
|
-
riskAccepted: raw.risk_accepted
|
|
224
|
+
riskAccepted: _nullishCoalesce(raw.risk_accepted, () => ( 0)),
|
|
470
225
|
geoLimit: raw.geo_limit,
|
|
471
|
-
assignedSubjects: (raw.assigned_subjects
|
|
226
|
+
assignedSubjects: (_nullishCoalesce(raw.assigned_subjects, () => ( []))).map((s) => ({
|
|
472
227
|
subjectType: s.subject_type,
|
|
473
228
|
subjectId: s.subject_id
|
|
474
229
|
})),
|
|
475
|
-
subjectsCount: raw.subjects_count
|
|
230
|
+
subjectsCount: _nullishCoalesce(raw.subjects_count, () => ( 0)),
|
|
476
231
|
createdAt: raw.created_at,
|
|
477
232
|
updatedAt: raw.updated_at
|
|
478
233
|
};
|
|
@@ -490,22 +245,22 @@ function toWire(req) {
|
|
|
490
245
|
block_tor: req.blockTor,
|
|
491
246
|
risk_accepted: req.riskAccepted,
|
|
492
247
|
geo_limit: req.geoLimit,
|
|
493
|
-
assigned_subjects: req.assignedSubjects
|
|
248
|
+
assigned_subjects: _optionalChain([req, 'access', _2 => _2.assignedSubjects, 'optionalAccess', _3 => _3.map, 'call', _4 => _4((s) => ({
|
|
494
249
|
subject_type: s.subjectType,
|
|
495
250
|
subject_id: s.subjectId
|
|
496
|
-
}))
|
|
251
|
+
}))])
|
|
497
252
|
};
|
|
498
253
|
}
|
|
499
254
|
var RULES_PATH = "/api/users/geoidentity/rules";
|
|
500
255
|
function rulePath(ruleId, suffix = "") {
|
|
501
256
|
if (typeof ruleId !== "string" || ruleId.trim() === "") {
|
|
502
|
-
throw new RuleIDRequiredError();
|
|
257
|
+
throw new (0, _chunkA6RGK4MAcjs.RuleIDRequiredError)();
|
|
503
258
|
}
|
|
504
259
|
return `${RULES_PATH}/${encodeURIComponent(ruleId.trim())}${suffix}`;
|
|
505
260
|
}
|
|
506
261
|
function requireUserId(userId) {
|
|
507
262
|
if (typeof userId !== "string" || userId.trim() === "") {
|
|
508
|
-
throw new UserIDRequiredError();
|
|
263
|
+
throw new (0, _chunkA6RGK4MAcjs.UserIDRequiredError)();
|
|
509
264
|
}
|
|
510
265
|
return userId.trim();
|
|
511
266
|
}
|
|
@@ -514,12 +269,12 @@ var GeoIdentityService = class {
|
|
|
514
269
|
this.http = http;
|
|
515
270
|
this.isClosed = isClosed;
|
|
516
271
|
}
|
|
517
|
-
|
|
518
|
-
|
|
272
|
+
|
|
273
|
+
|
|
519
274
|
/** Creates a GeoIdentity rule. */
|
|
520
275
|
async createRule(req) {
|
|
521
|
-
if (typeof req
|
|
522
|
-
throw new RuleNameRequiredError();
|
|
276
|
+
if (typeof _optionalChain([req, 'optionalAccess', _5 => _5.name]) !== "string" || req.name.trim() === "") {
|
|
277
|
+
throw new (0, _chunkA6RGK4MAcjs.RuleNameRequiredError)();
|
|
523
278
|
}
|
|
524
279
|
return toRule(await this.send("POST", RULES_PATH, toWire(req)));
|
|
525
280
|
}
|
|
@@ -530,7 +285,7 @@ var GeoIdentityService = class {
|
|
|
530
285
|
async listRules(opts = {}) {
|
|
531
286
|
const query = typeof opts.isActive === "boolean" ? `?is_active=${opts.isActive}` : "";
|
|
532
287
|
const raw = await this.send("GET", RULES_PATH + query);
|
|
533
|
-
return (raw
|
|
288
|
+
return (_nullishCoalesce(raw, () => ( []))).map(toRule);
|
|
534
289
|
}
|
|
535
290
|
/** Returns a rule including its assigned subjects. */
|
|
536
291
|
async getRule(ruleId) {
|
|
@@ -538,7 +293,7 @@ var GeoIdentityService = class {
|
|
|
538
293
|
}
|
|
539
294
|
/** Partially updates a rule. */
|
|
540
295
|
async updateRule(ruleId, req) {
|
|
541
|
-
return toRule(await this.send("PATCH", rulePath(ruleId), toWire(req
|
|
296
|
+
return toRule(await this.send("PATCH", rulePath(ruleId), toWire(_nullishCoalesce(req, () => ( {})))));
|
|
542
297
|
}
|
|
543
298
|
/** Deletes a rule and all of its assignments. */
|
|
544
299
|
async deleteRule(ruleId) {
|
|
@@ -572,7 +327,7 @@ var GeoIdentityService = class {
|
|
|
572
327
|
*/
|
|
573
328
|
async listUserRules(userId) {
|
|
574
329
|
const raw = await this.send("GET", userPath(userId, "/geoidentity/rules"));
|
|
575
|
-
return (raw
|
|
330
|
+
return (_nullishCoalesce(raw, () => ( []))).map(toRule);
|
|
576
331
|
}
|
|
577
332
|
async changeAssignment(method, ruleId, payload) {
|
|
578
333
|
return toRule(await this.send(method, rulePath(ruleId, "/assignments"), payload));
|
|
@@ -585,252 +340,23 @@ function polygonFromLatLng(coordinates) {
|
|
|
585
340
|
return { type: "Polygon", coordinates: [validateAndNormalizePolygon(coordinates)] };
|
|
586
341
|
}
|
|
587
342
|
|
|
588
|
-
// src/crypto.ts
|
|
589
|
-
var import_node_crypto = require("crypto");
|
|
590
|
-
function generateHMACSignature(key, timestamp) {
|
|
591
|
-
if (!key) {
|
|
592
|
-
return "";
|
|
593
|
-
}
|
|
594
|
-
return (0, import_node_crypto.createHmac)("sha256", key).update(timestamp.toString()).digest("hex");
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// src/http.ts
|
|
598
|
-
var USER_AGENT = "GeoEngineNodeSDK/2.1.0";
|
|
599
|
-
function parseHttpError(statusCode, bodyText, isSpatial = false) {
|
|
600
|
-
let parsedErrorContainer = null;
|
|
601
|
-
try {
|
|
602
|
-
parsedErrorContainer = JSON.parse(bodyText);
|
|
603
|
-
} catch {
|
|
604
|
-
}
|
|
605
|
-
const container = parsedErrorContainer?.error;
|
|
606
|
-
let code = container?.status ?? "";
|
|
607
|
-
let message = container?.message ?? parsedErrorContainer?.message ?? bodyText.trim();
|
|
608
|
-
const details = container?.details ?? [];
|
|
609
|
-
if (container?.details && container.details.length > 0) {
|
|
610
|
-
for (const detail of container.details) {
|
|
611
|
-
if (detail.reason) {
|
|
612
|
-
code = detail.reason;
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
if (!code) {
|
|
618
|
-
switch (statusCode) {
|
|
619
|
-
case 204:
|
|
620
|
-
case 404:
|
|
621
|
-
code = "NOT_FOUND";
|
|
622
|
-
break;
|
|
623
|
-
case 402:
|
|
624
|
-
code = "QUOTA_EXCEEDED";
|
|
625
|
-
break;
|
|
626
|
-
case 401:
|
|
627
|
-
code = "UNAUTHORIZED";
|
|
628
|
-
break;
|
|
629
|
-
case 403:
|
|
630
|
-
code = "FORBIDDEN";
|
|
631
|
-
break;
|
|
632
|
-
default:
|
|
633
|
-
code = "";
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
if (!message) {
|
|
637
|
-
message = `HTTP ${statusCode}`;
|
|
638
|
-
}
|
|
639
|
-
if (statusCode === 204 || statusCode === 404 || code === "NOT_FOUND") {
|
|
640
|
-
return new GeofenceNotFoundError(message, statusCode, details);
|
|
641
|
-
}
|
|
642
|
-
if (statusCode === 402 || code === "QUOTA_EXCEEDED") {
|
|
643
|
-
return new QuotaExceededError(message, statusCode, details);
|
|
644
|
-
}
|
|
645
|
-
if (statusCode === 401 || code === "UNAUTHORIZED" || code === "MISSING_API_KEY" || code === "MISSING_ORGANIZATION") {
|
|
646
|
-
return new AuthenticationError(message, statusCode, details);
|
|
647
|
-
}
|
|
648
|
-
if (statusCode === 403 || code === "FORBIDDEN") {
|
|
649
|
-
return new ForbiddenError(message, statusCode, details);
|
|
650
|
-
}
|
|
651
|
-
if (isSpatial) {
|
|
652
|
-
return new SpatialAPIError(statusCode, code, message, void 0, details);
|
|
653
|
-
}
|
|
654
|
-
return new APIError(statusCode, message);
|
|
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
|
-
}
|
|
709
|
-
var HttpClient = class {
|
|
710
|
-
config;
|
|
711
|
-
constructor(options = {}) {
|
|
712
|
-
const defaultManagement = "https://management.geoengine.dev";
|
|
713
|
-
const defaultIngest = "https://ingest.geoengine.dev";
|
|
714
|
-
const defaultApiService = "https://api.geoengine.dev";
|
|
715
|
-
this.config = {
|
|
716
|
-
apiKey: options.apiKey ?? "",
|
|
717
|
-
jwtToken: options.jwtToken,
|
|
718
|
-
environment: options.environment ?? "live",
|
|
719
|
-
managementUrl: options.baseUrl ?? options.managementUrl ?? defaultManagement,
|
|
720
|
-
ingestUrl: options.baseUrl ?? options.ingestUrl ?? defaultIngest,
|
|
721
|
-
apiServiceUrl: options.baseUrl ?? options.apiServiceUrl ?? defaultApiService,
|
|
722
|
-
timeout: options.timeout ?? 1e4,
|
|
723
|
-
maxRetries: options.maxRetries ?? 2,
|
|
724
|
-
batchSize: options.batchSize ?? 100,
|
|
725
|
-
flushInterval: options.flushInterval ?? 500,
|
|
726
|
-
bufferSize: options.bufferSize ?? 5e3,
|
|
727
|
-
fetch: options.fetch ?? globalThis.fetch
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
get options() {
|
|
731
|
-
return this.config;
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Executes an HTTP request with timeout, authentication headers and exponential backoff retry.
|
|
735
|
-
*/
|
|
736
|
-
async request(opts) {
|
|
737
|
-
const method = opts.method ?? "POST";
|
|
738
|
-
const timeoutMs = opts.timeout ?? this.config.timeout;
|
|
739
|
-
const maxRetries = opts.isApiService && method !== "GET" ? 0 : this.config.maxRetries;
|
|
740
|
-
let attempt = 0;
|
|
741
|
-
while (true) {
|
|
742
|
-
attempt++;
|
|
743
|
-
const controller = new globalThis.AbortController();
|
|
744
|
-
const timeoutId = globalThis.setTimeout(() => controller.abort(), timeoutMs);
|
|
745
|
-
const now = Date.now();
|
|
746
|
-
const headers = {
|
|
747
|
-
...opts.isApiService ? { Accept: "application/json" } : { "Content-Type": "application/json" },
|
|
748
|
-
"X-API-Key": this.config.apiKey,
|
|
749
|
-
"X-Geo-Environment": this.config.environment,
|
|
750
|
-
"X-Request-Time": now.toString(),
|
|
751
|
-
"X-Signature": generateHMACSignature(this.config.apiKey, now),
|
|
752
|
-
"User-Agent": USER_AGENT
|
|
753
|
-
};
|
|
754
|
-
if (opts.isApiService && opts.body !== void 0) {
|
|
755
|
-
headers["Content-Type"] = "application/json";
|
|
756
|
-
}
|
|
757
|
-
if (this.config.jwtToken) {
|
|
758
|
-
headers["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
759
|
-
}
|
|
760
|
-
try {
|
|
761
|
-
const response = await this.config.fetch(opts.endpoint, {
|
|
762
|
-
method,
|
|
763
|
-
headers,
|
|
764
|
-
body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0,
|
|
765
|
-
signal: controller.signal
|
|
766
|
-
});
|
|
767
|
-
globalThis.clearTimeout(timeoutId);
|
|
768
|
-
if (response.status === 204) {
|
|
769
|
-
if (opts.isSpatial) {
|
|
770
|
-
throw new GeofenceNotFoundError("geofence not found", 204);
|
|
771
|
-
}
|
|
772
|
-
return null;
|
|
773
|
-
}
|
|
774
|
-
if ((response.status === 429 || response.status >= 500) && attempt <= maxRetries) {
|
|
775
|
-
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
776
|
-
await new Promise(
|
|
777
|
-
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
778
|
-
);
|
|
779
|
-
continue;
|
|
780
|
-
}
|
|
781
|
-
const responseText = await response.text();
|
|
782
|
-
if (!response.ok) {
|
|
783
|
-
throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, opts.isSpatial);
|
|
784
|
-
}
|
|
785
|
-
if (!responseText || responseText.trim() === "") {
|
|
786
|
-
return null;
|
|
787
|
-
}
|
|
788
|
-
const json = JSON.parse(responseText);
|
|
789
|
-
if ((opts.isSpatial || opts.isApiService) && typeof json === "object" && json !== null && "success" in json) {
|
|
790
|
-
if (!json.success) {
|
|
791
|
-
throw opts.isApiService ? parseApiServiceError(response.status, responseText) : parseHttpError(response.status, responseText, true);
|
|
792
|
-
}
|
|
793
|
-
return json.data;
|
|
794
|
-
}
|
|
795
|
-
return json;
|
|
796
|
-
} catch (err) {
|
|
797
|
-
globalThis.clearTimeout(timeoutId);
|
|
798
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
799
|
-
throw new TimeoutError(timeoutMs);
|
|
800
|
-
}
|
|
801
|
-
if (err instanceof APIError) {
|
|
802
|
-
throw err;
|
|
803
|
-
}
|
|
804
|
-
if (attempt <= maxRetries) {
|
|
805
|
-
const delay = Math.min(100 * Math.pow(2, attempt) + Math.random() * 50, 2e3);
|
|
806
|
-
await new Promise(
|
|
807
|
-
(resolve) => globalThis.setTimeout(() => resolve(), delay)
|
|
808
|
-
);
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
throw err;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
|
|
817
343
|
// src/ingester.ts
|
|
818
|
-
var
|
|
819
|
-
var AsyncIngester = class {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
queue = []
|
|
825
|
-
inFlightPromises = /* @__PURE__ */ new Set()
|
|
826
|
-
timer = null
|
|
827
|
-
isClosed = false
|
|
828
|
-
constructor(client, bufferSize = 5e3, batchSize = 100, flushIntervalMs = 500) {
|
|
344
|
+
var _timers = require('timers');
|
|
345
|
+
var AsyncIngester = (_class = class {
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
__init() {this.queue = []}
|
|
351
|
+
__init2() {this.inFlightPromises = /* @__PURE__ */ new Set()}
|
|
352
|
+
__init3() {this.timer = null}
|
|
353
|
+
__init4() {this.isClosed = false}
|
|
354
|
+
constructor(client, bufferSize = 5e3, batchSize = 100, flushIntervalMs = 500) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
|
|
829
355
|
this.client = client;
|
|
830
356
|
this.bufferSize = bufferSize;
|
|
831
357
|
this.batchSize = batchSize;
|
|
832
358
|
this.intervalMs = flushIntervalMs;
|
|
833
|
-
this.timer = (0,
|
|
359
|
+
this.timer = _timers.setInterval.call(void 0, () => {
|
|
834
360
|
void this.flush();
|
|
835
361
|
}, this.intervalMs);
|
|
836
362
|
if (this.timer && typeof this.timer.unref === "function") {
|
|
@@ -888,7 +414,7 @@ var AsyncIngester = class {
|
|
|
888
414
|
}
|
|
889
415
|
this.isClosed = true;
|
|
890
416
|
if (this.timer) {
|
|
891
|
-
(0,
|
|
417
|
+
_timers.clearInterval.call(void 0, this.timer);
|
|
892
418
|
this.timer = null;
|
|
893
419
|
}
|
|
894
420
|
while (this.queue.length > 0) {
|
|
@@ -898,19 +424,19 @@ var AsyncIngester = class {
|
|
|
898
424
|
await Promise.all(Array.from(this.inFlightPromises));
|
|
899
425
|
}
|
|
900
426
|
}
|
|
901
|
-
};
|
|
427
|
+
}, _class);
|
|
902
428
|
|
|
903
429
|
// src/models.ts
|
|
904
430
|
var SpatialValidationResult = class {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
910
436
|
constructor(data) {
|
|
911
437
|
this.inside = Boolean(data.inside);
|
|
912
|
-
this.geofenceId = data.geofence_id
|
|
913
|
-
this.geofenceName = data.geofence_name
|
|
438
|
+
this.geofenceId = _nullishCoalesce(_nullishCoalesce(data.geofence_id, () => ( data.geofenceId)), () => ( ""));
|
|
439
|
+
this.geofenceName = _nullishCoalesce(data.geofence_name, () => ( data.geofenceName));
|
|
914
440
|
this.latitude = data.latitude;
|
|
915
441
|
this.longitude = data.longitude;
|
|
916
442
|
}
|
|
@@ -942,15 +468,15 @@ var SpatialValidationResult = class {
|
|
|
942
468
|
}
|
|
943
469
|
};
|
|
944
470
|
var SpatialGeneralResult = class {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
950
476
|
constructor(data) {
|
|
951
477
|
this.inside = Boolean(data.inside);
|
|
952
|
-
this.totalMatches = data.total_matches
|
|
953
|
-
this.matchedGeofences = data.matched_geofences
|
|
478
|
+
this.totalMatches = _nullishCoalesce(_nullishCoalesce(data.total_matches, () => ( data.totalMatches)), () => ( (_nullishCoalesce(_nullishCoalesce(_optionalChain([data, 'access', _6 => _6.matched_geofences, 'optionalAccess', _7 => _7.length]), () => ( _optionalChain([data, 'access', _8 => _8.matchedGeofences, 'optionalAccess', _9 => _9.length]))), () => ( 0)))));
|
|
479
|
+
this.matchedGeofences = _nullishCoalesce(_nullishCoalesce(data.matched_geofences, () => ( data.matchedGeofences)), () => ( []));
|
|
954
480
|
this.latitude = data.latitude;
|
|
955
481
|
this.longitude = data.longitude;
|
|
956
482
|
}
|
|
@@ -970,7 +496,7 @@ var SpatialGeneralResult = class {
|
|
|
970
496
|
* Returns the first matched geofence, or null if no matches found.
|
|
971
497
|
*/
|
|
972
498
|
firstMatch() {
|
|
973
|
-
return this.matchedGeofences[0]
|
|
499
|
+
return _nullishCoalesce(this.matchedGeofences[0], () => ( null));
|
|
974
500
|
}
|
|
975
501
|
/**
|
|
976
502
|
* Returns all matched geofence IDs as a string array.
|
|
@@ -1022,7 +548,7 @@ var SpatialService = class {
|
|
|
1022
548
|
constructor(http) {
|
|
1023
549
|
this.http = http;
|
|
1024
550
|
}
|
|
1025
|
-
|
|
551
|
+
|
|
1026
552
|
/**
|
|
1027
553
|
* Convenience method to check if coordinates fall within a specific geofence.
|
|
1028
554
|
*
|
|
@@ -1115,9 +641,9 @@ var SpatialCheckBuilder = class {
|
|
|
1115
641
|
this.lat = lat;
|
|
1116
642
|
this.lng = lng;
|
|
1117
643
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
1121
647
|
/**
|
|
1122
648
|
* Configures validation targeting a specific geofence ID.
|
|
1123
649
|
*/
|
|
@@ -1138,10 +664,10 @@ var SingleGeofenceCheck = class {
|
|
|
1138
664
|
this.lat = lat;
|
|
1139
665
|
this.lng = lng;
|
|
1140
666
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
1145
671
|
/**
|
|
1146
672
|
* Performs the single geofence spatial query.
|
|
1147
673
|
*/
|
|
@@ -1167,9 +693,9 @@ var GeneralGeofenceCheck = class {
|
|
|
1167
693
|
this.lat = lat;
|
|
1168
694
|
this.lng = lng;
|
|
1169
695
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
1173
699
|
/**
|
|
1174
700
|
* Performs the general spatial query against all organization geofences.
|
|
1175
701
|
*/
|
|
@@ -1191,40 +717,45 @@ var GeneralGeofenceCheck = class {
|
|
|
1191
717
|
};
|
|
1192
718
|
|
|
1193
719
|
// src/client.ts
|
|
1194
|
-
var GeoEngine = class {
|
|
1195
|
-
|
|
1196
|
-
|
|
720
|
+
var GeoEngine = (_class2 = class {
|
|
721
|
+
#apiKey;
|
|
722
|
+
|
|
723
|
+
__init5() {this.isClosed = false}
|
|
1197
724
|
/**
|
|
1198
725
|
* Spatial provides point-in-polygon querying and geofence validation capabilities.
|
|
1199
726
|
*/
|
|
1200
|
-
|
|
727
|
+
|
|
1201
728
|
/**
|
|
1202
729
|
* Alias for spatial (to maintain exact casing compatibility with Go client.Spatial).
|
|
1203
730
|
*/
|
|
1204
|
-
|
|
731
|
+
|
|
1205
732
|
/**
|
|
1206
733
|
* Users manages organization members, roles and invitations.
|
|
1207
734
|
*/
|
|
1208
|
-
|
|
735
|
+
|
|
1209
736
|
/**
|
|
1210
737
|
* Alias for users (matches Go client.Users).
|
|
1211
738
|
*/
|
|
1212
|
-
|
|
739
|
+
|
|
1213
740
|
/**
|
|
1214
741
|
* GeoIdentity manages GeoIdentity access rules for users and the organization.
|
|
1215
742
|
*/
|
|
1216
|
-
|
|
743
|
+
|
|
1217
744
|
/**
|
|
1218
745
|
* Alias for geoIdentity (matches Go client.GeoIdentity).
|
|
1219
746
|
*/
|
|
1220
|
-
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Server-only runtime decision client for `POST /v1/evaluate`.
|
|
750
|
+
*/
|
|
751
|
+
|
|
1221
752
|
/**
|
|
1222
753
|
* Initializes a new GeoEngine client instance.
|
|
1223
754
|
*
|
|
1224
755
|
* @param apiKey Your GeoEngine API Key (required)
|
|
1225
756
|
* @param options Optional configuration parameters
|
|
1226
757
|
*/
|
|
1227
|
-
constructor(apiKeyOrOptions, maybeOptions = {}) {
|
|
758
|
+
constructor(apiKeyOrOptions, maybeOptions = {}) {;_class2.prototype.__init5.call(this);
|
|
1228
759
|
let resolvedOptions;
|
|
1229
760
|
if (typeof apiKeyOrOptions === "string") {
|
|
1230
761
|
resolvedOptions = { ...maybeOptions, apiKey: apiKeyOrOptions };
|
|
@@ -1234,9 +765,10 @@ var GeoEngine = class {
|
|
|
1234
765
|
resolvedOptions = {};
|
|
1235
766
|
}
|
|
1236
767
|
if (!resolvedOptions.apiKey || resolvedOptions.apiKey.trim() === "") {
|
|
1237
|
-
throw new ValidationError("GeoEngine: API Key es requerida.");
|
|
768
|
+
throw new (0, _chunkA6RGK4MAcjs.ValidationError)("GeoEngine: API Key es requerida.");
|
|
1238
769
|
}
|
|
1239
|
-
this
|
|
770
|
+
this.#apiKey = resolvedOptions.apiKey;
|
|
771
|
+
this.http = new (0, _chunkA6RGK4MAcjs.HttpClient)(resolvedOptions);
|
|
1240
772
|
this.spatial = new SpatialService(this.http);
|
|
1241
773
|
this.Spatial = this.spatial;
|
|
1242
774
|
const isClosed = () => this.isClosed;
|
|
@@ -1244,13 +776,30 @@ var GeoEngine = class {
|
|
|
1244
776
|
this.Users = this.users;
|
|
1245
777
|
this.geoIdentity = new GeoIdentityService(this.http, isClosed);
|
|
1246
778
|
this.GeoIdentity = this.geoIdentity;
|
|
779
|
+
this.identity = new (0, _chunkA6RGK4MAcjs.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
|
+
});
|
|
1247
786
|
}
|
|
1248
787
|
/**
|
|
1249
|
-
* Current configuration options.
|
|
788
|
+
* Current configuration options (without secret apiKey).
|
|
1250
789
|
*/
|
|
1251
790
|
get options() {
|
|
1252
791
|
return this.http.options;
|
|
1253
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
|
+
}
|
|
1254
803
|
/**
|
|
1255
804
|
* Sends device coordinates over HTTP REST.
|
|
1256
805
|
* Equivalent to Go's Client.SendLocation.
|
|
@@ -1261,7 +810,7 @@ var GeoEngine = class {
|
|
|
1261
810
|
*/
|
|
1262
811
|
async sendLocation(deviceId, lat, lng) {
|
|
1263
812
|
if (this.isClosed) {
|
|
1264
|
-
throw new ClientClosedError();
|
|
813
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1265
814
|
}
|
|
1266
815
|
const validId = validateDeviceId(deviceId);
|
|
1267
816
|
const payload = {
|
|
@@ -1288,10 +837,10 @@ var GeoEngine = class {
|
|
|
1288
837
|
*/
|
|
1289
838
|
async createGeofence(name, coordinates, webhookUrl) {
|
|
1290
839
|
if (this.isClosed) {
|
|
1291
|
-
throw new ClientClosedError();
|
|
840
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1292
841
|
}
|
|
1293
842
|
if (!name || typeof name !== "string" || name.trim() === "") {
|
|
1294
|
-
throw new ValidationError("geoengine: name is required");
|
|
843
|
+
throw new (0, _chunkA6RGK4MAcjs.ValidationError)("geoengine: name is required");
|
|
1295
844
|
}
|
|
1296
845
|
const polygon = validateAndNormalizePolygon(coordinates);
|
|
1297
846
|
const payload = {
|
|
@@ -1316,7 +865,7 @@ var GeoEngine = class {
|
|
|
1316
865
|
*/
|
|
1317
866
|
async validateSpatialPoint(geofenceId, lat, lng) {
|
|
1318
867
|
if (this.isClosed) {
|
|
1319
|
-
throw new ClientClosedError();
|
|
868
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1320
869
|
}
|
|
1321
870
|
return this.spatial.validatePoint(geofenceId, lat, lng);
|
|
1322
871
|
}
|
|
@@ -1326,7 +875,7 @@ var GeoEngine = class {
|
|
|
1326
875
|
*/
|
|
1327
876
|
async validateSpatialLocation(req) {
|
|
1328
877
|
if (this.isClosed) {
|
|
1329
|
-
throw new ClientClosedError();
|
|
878
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1330
879
|
}
|
|
1331
880
|
return this.spatial.validateLocation(req);
|
|
1332
881
|
}
|
|
@@ -1336,7 +885,7 @@ var GeoEngine = class {
|
|
|
1336
885
|
*/
|
|
1337
886
|
async validateSpatialGeneral(lat, lng) {
|
|
1338
887
|
if (this.isClosed) {
|
|
1339
|
-
throw new ClientClosedError();
|
|
888
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1340
889
|
}
|
|
1341
890
|
return this.spatial.validateGeneral(lat, lng);
|
|
1342
891
|
}
|
|
@@ -1346,7 +895,7 @@ var GeoEngine = class {
|
|
|
1346
895
|
*/
|
|
1347
896
|
async validateSpatialGeneralLocation(req) {
|
|
1348
897
|
if (this.isClosed) {
|
|
1349
|
-
throw new ClientClosedError();
|
|
898
|
+
throw new (0, _chunkA6RGK4MAcjs.ClientClosedError)();
|
|
1350
899
|
}
|
|
1351
900
|
return this.spatial.validateGeneralLocation(req);
|
|
1352
901
|
}
|
|
@@ -1361,9 +910,9 @@ var GeoEngine = class {
|
|
|
1361
910
|
createAsyncIngester(bufferSize, batchSize, flushIntervalMs) {
|
|
1362
911
|
return new AsyncIngester(
|
|
1363
912
|
this,
|
|
1364
|
-
bufferSize
|
|
1365
|
-
batchSize
|
|
1366
|
-
flushIntervalMs
|
|
913
|
+
_nullishCoalesce(bufferSize, () => ( this.http.options.bufferSize)),
|
|
914
|
+
_nullishCoalesce(batchSize, () => ( this.http.options.batchSize)),
|
|
915
|
+
_nullishCoalesce(flushIntervalMs, () => ( this.http.options.flushInterval))
|
|
1367
916
|
);
|
|
1368
917
|
}
|
|
1369
918
|
/**
|
|
@@ -1374,59 +923,63 @@ var GeoEngine = class {
|
|
|
1374
923
|
close() {
|
|
1375
924
|
this.isClosed = true;
|
|
1376
925
|
}
|
|
1377
|
-
};
|
|
926
|
+
}, _class2);
|
|
1378
927
|
|
|
1379
928
|
// src/index.ts
|
|
1380
|
-
var
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
929
|
+
var src_default = GeoEngine;
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
exports.APIError = _chunkA6RGK4MAcjs.APIError; exports.APIServiceError = _chunkA6RGK4MAcjs.APIServiceError; exports.AsyncIngester = AsyncIngester; exports.AuthenticationError = _chunkA6RGK4MAcjs.AuthenticationError; exports.Client = GeoEngine; exports.ClientClosedError = _chunkA6RGK4MAcjs.ClientClosedError; exports.DeviceIDRequiredError = _chunkA6RGK4MAcjs.DeviceIDRequiredError; exports.EmailRequiredError = _chunkA6RGK4MAcjs.EmailRequiredError; exports.ForbiddenError = _chunkA6RGK4MAcjs.ForbiddenError; exports.GeneralGeofenceCheck = GeneralGeofenceCheck; exports.GeoEngine = GeoEngine; exports.GeoEngineError = _chunkA6RGK4MAcjs.GeoEngineError; exports.GeoIdentityService = GeoIdentityService; exports.GeofenceIDRequiredError = _chunkA6RGK4MAcjs.GeofenceIDRequiredError; exports.GeofenceNotFoundError = _chunkA6RGK4MAcjs.GeofenceNotFoundError; exports.IdentityIntegrationError = _chunkA6RGK4MAcjs.IdentityIntegrationError; exports.IdentityService = _chunkA6RGK4MAcjs.IdentityService; exports.IdentityTransientError = _chunkA6RGK4MAcjs.IdentityTransientError; exports.InvalidCoordinatesError = _chunkA6RGK4MAcjs.InvalidCoordinatesError; exports.InvalidLatitudeError = _chunkA6RGK4MAcjs.InvalidLatitudeError; exports.InvalidLongitudeError = _chunkA6RGK4MAcjs.InvalidLongitudeError; exports.InvitationPendingError = _chunkA6RGK4MAcjs.InvitationPendingError; exports.LastAdminError = _chunkA6RGK4MAcjs.LastAdminError; exports.LastSubjectError = _chunkA6RGK4MAcjs.LastSubjectError; exports.QuotaExceededError = _chunkA6RGK4MAcjs.QuotaExceededError; exports.RoleRequiredError = _chunkA6RGK4MAcjs.RoleRequiredError; exports.Roles = Roles; exports.RuleActions = RuleActions; exports.RuleIDRequiredError = _chunkA6RGK4MAcjs.RuleIDRequiredError; exports.RuleNameRequiredError = _chunkA6RGK4MAcjs.RuleNameRequiredError; exports.RuleNotFoundError = _chunkA6RGK4MAcjs.RuleNotFoundError; exports.SingleGeofenceCheck = SingleGeofenceCheck; exports.SpatialAPIError = _chunkA6RGK4MAcjs.SpatialAPIError; exports.SpatialCheckBuilder = SpatialCheckBuilder; exports.SpatialGeneralResult = SpatialGeneralResult; exports.SpatialService = SpatialService; exports.SpatialValidationResult = SpatialValidationResult; exports.SubjectTypes = SubjectTypes; exports.TimeoutError = _chunkA6RGK4MAcjs.TimeoutError; exports.UserAlreadyExistsError = _chunkA6RGK4MAcjs.UserAlreadyExistsError; exports.UserIDRequiredError = _chunkA6RGK4MAcjs.UserIDRequiredError; exports.UserNotFoundError = _chunkA6RGK4MAcjs.UserNotFoundError; exports.UserStatus = UserStatus; exports.UsersService = UsersService; exports.ValidationError = _chunkA6RGK4MAcjs.ValidationError; exports.default = src_default; exports.generateHMACSignature = _chunkA6RGK4MAcjs.generateHMACSignature; exports.isTransient = _chunkA6RGK4MAcjs.isTransient; exports.polygonFromLatLng = polygonFromLatLng; exports.validateAndNormalizePolygon = validateAndNormalizePolygon; exports.validateCoordinates = validateCoordinates; exports.validateDeviceId = validateDeviceId; exports.validateGeofenceId = validateGeofenceId;
|
|
1432
985
|
//# sourceMappingURL=index.cjs.map
|