ironflock 1.0.2 → 1.2.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/README.md +334 -23
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +169 -2
- package/dist/index.mjs +799 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -17
- package/dist/crossbar/index.d.ts +0 -38
- package/dist/crossbar/index.js +0 -153
- package/dist/crossbar/serializer.d.ts +0 -8
- package/dist/crossbar/serializer.js +0 -55
- package/dist/index.js +0 -3
- package/dist/ironflock.d.ts +0 -19
- package/dist/ironflock.js +0 -166
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -69
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -26
- package/src/crossbar/index.ts +0 -125
- package/src/crossbar/serializer.ts +0 -31
- package/src/index.ts +0 -3
- package/src/ironflock.ts +0 -109
- package/src/test/index.ts +0 -28
- package/src/utils/index.ts +0 -25
- package/tsconfig.json +0 -21
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import C from "autobahn";
|
|
2
|
+
function j(d) {
|
|
3
|
+
return d && d.__esModule && Object.prototype.hasOwnProperty.call(d, "default") ? d.default : d;
|
|
4
|
+
}
|
|
5
|
+
var S = { exports: {} }, T;
|
|
6
|
+
function L() {
|
|
7
|
+
return T || (T = 1, (function(d) {
|
|
8
|
+
var r = Object.prototype.hasOwnProperty, s = "~";
|
|
9
|
+
function o() {
|
|
10
|
+
}
|
|
11
|
+
Object.create && (o.prototype = /* @__PURE__ */ Object.create(null), new o().__proto__ || (s = !1));
|
|
12
|
+
function l(a, e, n) {
|
|
13
|
+
this.fn = a, this.context = e, this.once = n || !1;
|
|
14
|
+
}
|
|
15
|
+
function i(a, e, n, c, f) {
|
|
16
|
+
if (typeof n != "function")
|
|
17
|
+
throw new TypeError("The listener must be a function");
|
|
18
|
+
var v = new l(n, c || a, f), g = s ? s + e : e;
|
|
19
|
+
return a._events[g] ? a._events[g].fn ? a._events[g] = [a._events[g], v] : a._events[g].push(v) : (a._events[g] = v, a._eventsCount++), a;
|
|
20
|
+
}
|
|
21
|
+
function u(a, e) {
|
|
22
|
+
--a._eventsCount === 0 ? a._events = new o() : delete a._events[e];
|
|
23
|
+
}
|
|
24
|
+
function t() {
|
|
25
|
+
this._events = new o(), this._eventsCount = 0;
|
|
26
|
+
}
|
|
27
|
+
t.prototype.eventNames = function() {
|
|
28
|
+
var e = [], n, c;
|
|
29
|
+
if (this._eventsCount === 0) return e;
|
|
30
|
+
for (c in n = this._events)
|
|
31
|
+
r.call(n, c) && e.push(s ? c.slice(1) : c);
|
|
32
|
+
return Object.getOwnPropertySymbols ? e.concat(Object.getOwnPropertySymbols(n)) : e;
|
|
33
|
+
}, t.prototype.listeners = function(e) {
|
|
34
|
+
var n = s ? s + e : e, c = this._events[n];
|
|
35
|
+
if (!c) return [];
|
|
36
|
+
if (c.fn) return [c.fn];
|
|
37
|
+
for (var f = 0, v = c.length, g = new Array(v); f < v; f++)
|
|
38
|
+
g[f] = c[f].fn;
|
|
39
|
+
return g;
|
|
40
|
+
}, t.prototype.listenerCount = function(e) {
|
|
41
|
+
var n = s ? s + e : e, c = this._events[n];
|
|
42
|
+
return c ? c.fn ? 1 : c.length : 0;
|
|
43
|
+
}, t.prototype.emit = function(e, n, c, f, v, g) {
|
|
44
|
+
var w = s ? s + e : e;
|
|
45
|
+
if (!this._events[w]) return !1;
|
|
46
|
+
var h = this._events[w], b = arguments.length, A, m;
|
|
47
|
+
if (h.fn) {
|
|
48
|
+
switch (h.once && this.removeListener(e, h.fn, void 0, !0), b) {
|
|
49
|
+
case 1:
|
|
50
|
+
return h.fn.call(h.context), !0;
|
|
51
|
+
case 2:
|
|
52
|
+
return h.fn.call(h.context, n), !0;
|
|
53
|
+
case 3:
|
|
54
|
+
return h.fn.call(h.context, n, c), !0;
|
|
55
|
+
case 4:
|
|
56
|
+
return h.fn.call(h.context, n, c, f), !0;
|
|
57
|
+
case 5:
|
|
58
|
+
return h.fn.call(h.context, n, c, f, v), !0;
|
|
59
|
+
case 6:
|
|
60
|
+
return h.fn.call(h.context, n, c, f, v, g), !0;
|
|
61
|
+
}
|
|
62
|
+
for (m = 1, A = new Array(b - 1); m < b; m++)
|
|
63
|
+
A[m - 1] = arguments[m];
|
|
64
|
+
h.fn.apply(h.context, A);
|
|
65
|
+
} else {
|
|
66
|
+
var O = h.length, _;
|
|
67
|
+
for (m = 0; m < O; m++)
|
|
68
|
+
switch (h[m].once && this.removeListener(e, h[m].fn, void 0, !0), b) {
|
|
69
|
+
case 1:
|
|
70
|
+
h[m].fn.call(h[m].context);
|
|
71
|
+
break;
|
|
72
|
+
case 2:
|
|
73
|
+
h[m].fn.call(h[m].context, n);
|
|
74
|
+
break;
|
|
75
|
+
case 3:
|
|
76
|
+
h[m].fn.call(h[m].context, n, c);
|
|
77
|
+
break;
|
|
78
|
+
case 4:
|
|
79
|
+
h[m].fn.call(h[m].context, n, c, f);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
if (!A) for (_ = 1, A = new Array(b - 1); _ < b; _++)
|
|
83
|
+
A[_ - 1] = arguments[_];
|
|
84
|
+
h[m].fn.apply(h[m].context, A);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return !0;
|
|
88
|
+
}, t.prototype.on = function(e, n, c) {
|
|
89
|
+
return i(this, e, n, c, !1);
|
|
90
|
+
}, t.prototype.once = function(e, n, c) {
|
|
91
|
+
return i(this, e, n, c, !0);
|
|
92
|
+
}, t.prototype.removeListener = function(e, n, c, f) {
|
|
93
|
+
var v = s ? s + e : e;
|
|
94
|
+
if (!this._events[v]) return this;
|
|
95
|
+
if (!n)
|
|
96
|
+
return u(this, v), this;
|
|
97
|
+
var g = this._events[v];
|
|
98
|
+
if (g.fn)
|
|
99
|
+
g.fn === n && (!f || g.once) && (!c || g.context === c) && u(this, v);
|
|
100
|
+
else {
|
|
101
|
+
for (var w = 0, h = [], b = g.length; w < b; w++)
|
|
102
|
+
(g[w].fn !== n || f && !g[w].once || c && g[w].context !== c) && h.push(g[w]);
|
|
103
|
+
h.length ? this._events[v] = h.length === 1 ? h[0] : h : u(this, v);
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}, t.prototype.removeAllListeners = function(e) {
|
|
107
|
+
var n;
|
|
108
|
+
return e ? (n = s ? s + e : e, this._events[n] && u(this, n)) : (this._events = new o(), this._eventsCount = 0), this;
|
|
109
|
+
}, t.prototype.off = t.prototype.removeListener, t.prototype.addListener = t.prototype.on, t.prefixed = s, t.EventEmitter = t, d.exports = t;
|
|
110
|
+
})(S)), S.exports;
|
|
111
|
+
}
|
|
112
|
+
var P = L();
|
|
113
|
+
const U = /* @__PURE__ */ j(P), D = "wss://cbw.datapods.io/ws-ua-usr", $ = "wss://cbw.ironflock.com/ws-ua-usr", W = "wss://cbw.ironflock.dev/ws-ua-usr", F = "wss://cbw.record-evolution.com/ws-ua-usr", I = "ws://localhost:8080/ws-ua-usr", V = {
|
|
114
|
+
"https://studio.datapods.io": D,
|
|
115
|
+
"https://studio.ironflock.dev": W,
|
|
116
|
+
"https://studio.ironflock.com": $,
|
|
117
|
+
"https://studio.record-evolution.com": F,
|
|
118
|
+
"http://localhost:8085": I,
|
|
119
|
+
"http://localhost:8086": I,
|
|
120
|
+
"http://host.docker.internal:8086": I
|
|
121
|
+
}, Y = 6e3;
|
|
122
|
+
class K extends U {
|
|
123
|
+
constructor() {
|
|
124
|
+
super(), this.subscriptions = [], this.registrations = [], this.firstResolver = () => {
|
|
125
|
+
}, this.firstRejecter = () => {
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
static getWebSocketURI(r) {
|
|
129
|
+
return r ? V[r] ?? $ : $;
|
|
130
|
+
}
|
|
131
|
+
configure(r, s, o, l, i) {
|
|
132
|
+
this.realm = `realm-${r}-${s}-${o}`, this.serial_number = l, this.socketURI = i ?? K.getWebSocketURI();
|
|
133
|
+
}
|
|
134
|
+
async start() {
|
|
135
|
+
if (!this.realm || !this.serial_number || !this.socketURI)
|
|
136
|
+
throw new Error("CrossbarConnection must be configured before starting. Call configure() first.");
|
|
137
|
+
return this.firstConnection = new Promise((r, s) => {
|
|
138
|
+
this.firstResolver = r, this.firstRejecter = s;
|
|
139
|
+
}), this.connection = new C.Connection({
|
|
140
|
+
realm: this.realm,
|
|
141
|
+
url: this.socketURI,
|
|
142
|
+
authmethods: ["wampcra"],
|
|
143
|
+
authid: this.serial_number,
|
|
144
|
+
max_retries: -1,
|
|
145
|
+
max_retry_delay: 2,
|
|
146
|
+
initial_retry_delay: 1,
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
autoping_interval: 2,
|
|
149
|
+
autoping_timeout: 4,
|
|
150
|
+
onchallenge: (r, s, o) => C.auth_cra.sign(this.serial_number, o.challenge)
|
|
151
|
+
}), this.connection.onopen = this.onOpen.bind(this), this.connection.onclose = this.onClose.bind(this), this.connection.open(), this.firstConnection;
|
|
152
|
+
}
|
|
153
|
+
onOpen(r) {
|
|
154
|
+
this.session = r, this.session.caller_disclose_me = !0, this.resubscribeAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
onClose(r, s) {
|
|
158
|
+
return this.session = void 0, this.emit("disconnected"), this.firstRejecter(
|
|
159
|
+
new Error(
|
|
160
|
+
`Connection failed: ${r} - ${JSON.stringify(s, null, 2)}`
|
|
161
|
+
)
|
|
162
|
+
), this.firstRejecter = () => {
|
|
163
|
+
}, console.warn("Connection closed:", {
|
|
164
|
+
reason: r,
|
|
165
|
+
details: s,
|
|
166
|
+
realm: this.realm,
|
|
167
|
+
url: this.socketURI,
|
|
168
|
+
authid: this.serial_number
|
|
169
|
+
}), !1;
|
|
170
|
+
}
|
|
171
|
+
async sessionWait() {
|
|
172
|
+
const r = Date.now();
|
|
173
|
+
for (; !this.session; ) {
|
|
174
|
+
if (Date.now() - r > Y)
|
|
175
|
+
throw new Error("Timeout waiting for session");
|
|
176
|
+
await new Promise((s) => setTimeout(s, 200));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async waitForConnection() {
|
|
180
|
+
return this.firstConnection;
|
|
181
|
+
}
|
|
182
|
+
getSession() {
|
|
183
|
+
return this.session;
|
|
184
|
+
}
|
|
185
|
+
get is_open() {
|
|
186
|
+
var r;
|
|
187
|
+
return !!((r = this.session) != null && r.isOpen);
|
|
188
|
+
}
|
|
189
|
+
isConnected() {
|
|
190
|
+
return this.is_open;
|
|
191
|
+
}
|
|
192
|
+
stop() {
|
|
193
|
+
var r;
|
|
194
|
+
(r = this.connection) == null || r.close("wamp.close.normal", "Connection closed by client");
|
|
195
|
+
}
|
|
196
|
+
async subscribe(r, s) {
|
|
197
|
+
var l;
|
|
198
|
+
await this.sessionWait();
|
|
199
|
+
const o = await ((l = this.session) == null ? void 0 : l.subscribe(r, s));
|
|
200
|
+
return o && this.subscriptions.push(o), o;
|
|
201
|
+
}
|
|
202
|
+
async unsubscribe(r) {
|
|
203
|
+
var o;
|
|
204
|
+
await this.sessionWait();
|
|
205
|
+
const s = this.subscriptions.indexOf(r);
|
|
206
|
+
s !== -1 && (this.subscriptions.splice(s, 1), await ((o = this.session) == null ? void 0 : o.unsubscribe(r)));
|
|
207
|
+
}
|
|
208
|
+
async unsubscribeTopic(r) {
|
|
209
|
+
const s = this.subscriptions.filter((o) => o.topic === r);
|
|
210
|
+
for (const o of s)
|
|
211
|
+
await this.unsubscribe(o);
|
|
212
|
+
}
|
|
213
|
+
async resubscribeAll() {
|
|
214
|
+
const r = [...this.subscriptions];
|
|
215
|
+
this.subscriptions = [], await Promise.all(
|
|
216
|
+
r.map((s) => this.subscribe(s.topic, s.handler))
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
async register(r, s) {
|
|
220
|
+
var l;
|
|
221
|
+
await this.sessionWait();
|
|
222
|
+
const o = await ((l = this.session) == null ? void 0 : l.register(r, s));
|
|
223
|
+
return o && this.registrations.push(o), o;
|
|
224
|
+
}
|
|
225
|
+
async unregister(r) {
|
|
226
|
+
var o;
|
|
227
|
+
await this.sessionWait(), await ((o = this.session) == null ? void 0 : o.unregister(r));
|
|
228
|
+
const s = this.registrations.indexOf(r);
|
|
229
|
+
s !== -1 && this.registrations.splice(s, 1);
|
|
230
|
+
}
|
|
231
|
+
async call(r, s, o, l) {
|
|
232
|
+
var i;
|
|
233
|
+
return await this.sessionWait(), (i = this.session) == null ? void 0 : i.call(r, s, o, l);
|
|
234
|
+
}
|
|
235
|
+
async publish(r, s, o, l) {
|
|
236
|
+
var i;
|
|
237
|
+
return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(r, s, o, l);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const R = (d) => Math.floor(d) === d && Q <= d && d <= B, Q = 0, B = 2 ** 32 - 1, M = (d) => J.test(d), J = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i, k = (d) => {
|
|
241
|
+
const r = (s) => {
|
|
242
|
+
if (d.length === 0)
|
|
243
|
+
return !0;
|
|
244
|
+
const o = d[d.length - 1].path;
|
|
245
|
+
return s.length > o.length || o.substring(0, s.length) !== s;
|
|
246
|
+
};
|
|
247
|
+
return (s, o) => (s && r(o.path) && (o.value === void 0 && (o.description ?? (o.description = [
|
|
248
|
+
"The value at this path is `undefined`.",
|
|
249
|
+
"",
|
|
250
|
+
`Please fill the \`${o.expected}\` typed value next time.`
|
|
251
|
+
].join(`
|
|
252
|
+
`))), d.push(o)), !1);
|
|
253
|
+
}, p = (d) => Object.assign(d, {
|
|
254
|
+
"~standard": {
|
|
255
|
+
version: 1,
|
|
256
|
+
vendor: "typia",
|
|
257
|
+
validate: (r) => {
|
|
258
|
+
const s = d(r);
|
|
259
|
+
return s.success ? {
|
|
260
|
+
value: s.data
|
|
261
|
+
} : {
|
|
262
|
+
issues: s.errors.map((o) => ({
|
|
263
|
+
message: `expected ${o.expected}, got ${o.value}`,
|
|
264
|
+
path: q(o.path)
|
|
265
|
+
}))
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
var y;
|
|
271
|
+
(function(d) {
|
|
272
|
+
d[d.Start = 0] = "Start", d[d.Property = 1] = "Property", d[d.StringKey = 2] = "StringKey", d[d.NumberKey = 3] = "NumberKey";
|
|
273
|
+
})(y || (y = {}));
|
|
274
|
+
const q = (d) => {
|
|
275
|
+
if (!d.startsWith("$input"))
|
|
276
|
+
throw new Error(`Invalid path: ${JSON.stringify(d)}`);
|
|
277
|
+
const r = [];
|
|
278
|
+
let s = "", o = y.Start, l = 5;
|
|
279
|
+
for (; l < d.length - 1; ) {
|
|
280
|
+
l++;
|
|
281
|
+
const i = d[l];
|
|
282
|
+
if (o === y.Property ? i === "." || i === "[" ? (r.push({
|
|
283
|
+
key: s
|
|
284
|
+
}), o = y.Start) : l === d.length - 1 ? (s += i, r.push({
|
|
285
|
+
key: s
|
|
286
|
+
}), l++, o = y.Start) : s += i : o === y.StringKey ? i === '"' ? (r.push({
|
|
287
|
+
key: JSON.parse(s + i)
|
|
288
|
+
}), l += 2, o = y.Start) : i === "\\" ? (s += d[l], l++, s += d[l]) : s += i : o === y.NumberKey && (i === "]" ? (r.push({
|
|
289
|
+
key: Number.parseInt(s)
|
|
290
|
+
}), l++, o = y.Start) : s += i), o === y.Start && l < d.length - 1) {
|
|
291
|
+
const u = d[l];
|
|
292
|
+
if (s = "", u === "[")
|
|
293
|
+
d[l + 1] === '"' ? (o = y.StringKey, l++, s = '"') : o = y.NumberKey;
|
|
294
|
+
else if (u === ".")
|
|
295
|
+
o = y.Property;
|
|
296
|
+
else
|
|
297
|
+
throw new Error("Unreachable: pointer points invalid character");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (o !== y.Start)
|
|
301
|
+
throw new Error(`Failed to parse path: ${JSON.stringify(d)}`);
|
|
302
|
+
return r;
|
|
303
|
+
};
|
|
304
|
+
var x = /* @__PURE__ */ ((d) => (d.DEVELOPMENT = "dev", d.PRODUCTION = "prod", d))(x || {});
|
|
305
|
+
const H = (() => {
|
|
306
|
+
const d = (e) => typeof e.limit == "number" && R(e.limit) && 1 <= e.limit && e.limit <= 1e4 && (e.offset === void 0 || typeof e.offset == "number" && R(e.offset) && 0 <= e.offset) && (e.timeRange === void 0 || typeof e.timeRange == "object" && e.timeRange !== null && r(e.timeRange)) && (e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && s(n))), r = (e) => typeof e.start == "string" && M(e.start) && typeof e.end == "string" && M(e.end), s = (e) => typeof e.column == "string" && 1 <= e.column.length && typeof e.operator == "string" && 1 <= e.operator.length && e.value !== null && e.value !== void 0 && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || Array.isArray(e.value) && e.value.every((n) => typeof n == "string" || typeof n == "number")), o = (e, n, c = !0) => [typeof e.limit == "number" && (R(e.limit) || a(c, {
|
|
307
|
+
path: n + ".limit",
|
|
308
|
+
expected: 'number & Type<"uint32">',
|
|
309
|
+
value: e.limit
|
|
310
|
+
})) && (1 <= e.limit || a(c, {
|
|
311
|
+
path: n + ".limit",
|
|
312
|
+
expected: "number & Minimum<1>",
|
|
313
|
+
value: e.limit
|
|
314
|
+
})) && (e.limit <= 1e4 || a(c, {
|
|
315
|
+
path: n + ".limit",
|
|
316
|
+
expected: "number & Maximum<10000>",
|
|
317
|
+
value: e.limit
|
|
318
|
+
})) || a(c, {
|
|
319
|
+
path: n + ".limit",
|
|
320
|
+
expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
|
|
321
|
+
value: e.limit
|
|
322
|
+
}), e.offset === void 0 || typeof e.offset == "number" && (R(e.offset) || a(c, {
|
|
323
|
+
path: n + ".offset",
|
|
324
|
+
expected: 'number & Type<"uint32">',
|
|
325
|
+
value: e.offset
|
|
326
|
+
})) && (0 <= e.offset || a(c, {
|
|
327
|
+
path: n + ".offset",
|
|
328
|
+
expected: "number & Minimum<0>",
|
|
329
|
+
value: e.offset
|
|
330
|
+
})) || a(c, {
|
|
331
|
+
path: n + ".offset",
|
|
332
|
+
expected: '((number & Type<"uint32"> & Minimum<0>) | undefined)',
|
|
333
|
+
value: e.offset
|
|
334
|
+
}), e.timeRange === void 0 || (typeof e.timeRange == "object" && e.timeRange !== null || a(c, {
|
|
335
|
+
path: n + ".timeRange",
|
|
336
|
+
expected: "(ISOTimeRange | undefined)",
|
|
337
|
+
value: e.timeRange
|
|
338
|
+
})) && l(e.timeRange, n + ".timeRange", c) || a(c, {
|
|
339
|
+
path: n + ".timeRange",
|
|
340
|
+
expected: "(ISOTimeRange | undefined)",
|
|
341
|
+
value: e.timeRange
|
|
342
|
+
}), e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || a(c, {
|
|
343
|
+
path: n + ".filterAnd",
|
|
344
|
+
expected: "(Array<SQLFilterAnd> | undefined)",
|
|
345
|
+
value: e.filterAnd
|
|
346
|
+
})) && e.filterAnd.map((f, v) => (typeof f == "object" && f !== null || a(c, {
|
|
347
|
+
path: n + ".filterAnd[" + v + "]",
|
|
348
|
+
expected: "SQLFilterAnd",
|
|
349
|
+
value: f
|
|
350
|
+
})) && i(f, n + ".filterAnd[" + v + "]", c) || a(c, {
|
|
351
|
+
path: n + ".filterAnd[" + v + "]",
|
|
352
|
+
expected: "SQLFilterAnd",
|
|
353
|
+
value: f
|
|
354
|
+
})).every((f) => f) || a(c, {
|
|
355
|
+
path: n + ".filterAnd",
|
|
356
|
+
expected: "(Array<SQLFilterAnd> | undefined)",
|
|
357
|
+
value: e.filterAnd
|
|
358
|
+
})].every((f) => f), l = (e, n, c = !0) => [typeof e.start == "string" && (M(e.start) || a(c, {
|
|
359
|
+
path: n + ".start",
|
|
360
|
+
expected: 'string & Format<"date-time">',
|
|
361
|
+
value: e.start
|
|
362
|
+
})) || a(c, {
|
|
363
|
+
path: n + ".start",
|
|
364
|
+
expected: '(string & Format<"date-time">)',
|
|
365
|
+
value: e.start
|
|
366
|
+
}), typeof e.end == "string" && (M(e.end) || a(c, {
|
|
367
|
+
path: n + ".end",
|
|
368
|
+
expected: 'string & Format<"date-time">',
|
|
369
|
+
value: e.end
|
|
370
|
+
})) || a(c, {
|
|
371
|
+
path: n + ".end",
|
|
372
|
+
expected: '(string & Format<"date-time">)',
|
|
373
|
+
value: e.end
|
|
374
|
+
})].every((f) => f), i = (e, n, c = !0) => [typeof e.column == "string" && (1 <= e.column.length || a(c, {
|
|
375
|
+
path: n + ".column",
|
|
376
|
+
expected: "string & MinLength<1>",
|
|
377
|
+
value: e.column
|
|
378
|
+
})) || a(c, {
|
|
379
|
+
path: n + ".column",
|
|
380
|
+
expected: "(string & MinLength<1>)",
|
|
381
|
+
value: e.column
|
|
382
|
+
}), typeof e.operator == "string" && (1 <= e.operator.length || a(c, {
|
|
383
|
+
path: n + ".operator",
|
|
384
|
+
expected: "string & MinLength<1>",
|
|
385
|
+
value: e.operator
|
|
386
|
+
})) || a(c, {
|
|
387
|
+
path: n + ".operator",
|
|
388
|
+
expected: "(string & MinLength<1>)",
|
|
389
|
+
value: e.operator
|
|
390
|
+
}), (e.value !== null || a(c, {
|
|
391
|
+
path: n + ".value",
|
|
392
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
393
|
+
value: e.value
|
|
394
|
+
})) && (e.value !== void 0 || a(c, {
|
|
395
|
+
path: n + ".value",
|
|
396
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
397
|
+
value: e.value
|
|
398
|
+
})) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || a(c, {
|
|
399
|
+
path: n + ".value",
|
|
400
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
401
|
+
value: e.value
|
|
402
|
+
})) && e.value.map((f, v) => typeof f == "string" || typeof f == "number" || a(c, {
|
|
403
|
+
path: n + ".value[" + v + "]",
|
|
404
|
+
expected: "(number | string)",
|
|
405
|
+
value: f
|
|
406
|
+
})).every((f) => f) || a(c, {
|
|
407
|
+
path: n + ".value",
|
|
408
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
409
|
+
value: e.value
|
|
410
|
+
}))].every((f) => f), u = (e) => typeof e == "object" && e !== null && d(e);
|
|
411
|
+
let t, a;
|
|
412
|
+
return p((e) => {
|
|
413
|
+
if (u(e) === !1) {
|
|
414
|
+
t = [], a = k(t), ((c, f, v = !0) => (typeof c == "object" && c !== null || a(!0, {
|
|
415
|
+
path: f + "",
|
|
416
|
+
expected: "TableQueryParams",
|
|
417
|
+
value: c
|
|
418
|
+
})) && o(c, f + "", !0) || a(!0, {
|
|
419
|
+
path: f + "",
|
|
420
|
+
expected: "TableQueryParams",
|
|
421
|
+
value: c
|
|
422
|
+
}))(e, "$input", !0);
|
|
423
|
+
const n = t.length === 0;
|
|
424
|
+
return n ? {
|
|
425
|
+
success: n,
|
|
426
|
+
data: e
|
|
427
|
+
} : {
|
|
428
|
+
success: n,
|
|
429
|
+
errors: t,
|
|
430
|
+
data: e
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
success: !0,
|
|
435
|
+
data: e
|
|
436
|
+
};
|
|
437
|
+
});
|
|
438
|
+
})(), G = (() => {
|
|
439
|
+
const d = (i) => typeof i.longitude == "number" && -180 <= i.longitude && i.longitude <= 180 && typeof i.latitude == "number" && -90 <= i.latitude && i.latitude <= 90, r = (i, u, t = !0) => [typeof i.longitude == "number" && (-180 <= i.longitude || l(t, {
|
|
440
|
+
path: u + ".longitude",
|
|
441
|
+
expected: "number & Minimum<-180>",
|
|
442
|
+
value: i.longitude
|
|
443
|
+
})) && (i.longitude <= 180 || l(t, {
|
|
444
|
+
path: u + ".longitude",
|
|
445
|
+
expected: "number & Maximum<180>",
|
|
446
|
+
value: i.longitude
|
|
447
|
+
})) || l(t, {
|
|
448
|
+
path: u + ".longitude",
|
|
449
|
+
expected: "(number & Minimum<-180> & Maximum<180>)",
|
|
450
|
+
value: i.longitude
|
|
451
|
+
}), typeof i.latitude == "number" && (-90 <= i.latitude || l(t, {
|
|
452
|
+
path: u + ".latitude",
|
|
453
|
+
expected: "number & Minimum<-90>",
|
|
454
|
+
value: i.latitude
|
|
455
|
+
})) && (i.latitude <= 90 || l(t, {
|
|
456
|
+
path: u + ".latitude",
|
|
457
|
+
expected: "number & Maximum<90>",
|
|
458
|
+
value: i.latitude
|
|
459
|
+
})) || l(t, {
|
|
460
|
+
path: u + ".latitude",
|
|
461
|
+
expected: "(number & Minimum<-90> & Maximum<90>)",
|
|
462
|
+
value: i.latitude
|
|
463
|
+
})].every((a) => a), s = (i) => typeof i == "object" && i !== null && d(i);
|
|
464
|
+
let o, l;
|
|
465
|
+
return p((i) => {
|
|
466
|
+
if (s(i) === !1) {
|
|
467
|
+
o = [], l = k(o), ((t, a, e = !0) => (typeof t == "object" && t !== null || l(!0, {
|
|
468
|
+
path: a + "",
|
|
469
|
+
expected: "LocationParams",
|
|
470
|
+
value: t
|
|
471
|
+
})) && r(t, a + "", !0) || l(!0, {
|
|
472
|
+
path: a + "",
|
|
473
|
+
expected: "LocationParams",
|
|
474
|
+
value: t
|
|
475
|
+
}))(i, "$input", !0);
|
|
476
|
+
const u = o.length === 0;
|
|
477
|
+
return u ? {
|
|
478
|
+
success: u,
|
|
479
|
+
data: i
|
|
480
|
+
} : {
|
|
481
|
+
success: u,
|
|
482
|
+
errors: o,
|
|
483
|
+
data: i
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
success: !0,
|
|
488
|
+
data: i
|
|
489
|
+
};
|
|
490
|
+
});
|
|
491
|
+
})(), X = (() => {
|
|
492
|
+
const d = (t) => typeof t.topic == "string" && 1 <= t.topic.length && (t.args === void 0 || Array.isArray(t.args)) && (t.kwargs === void 0 || typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 && r(t.kwargs)), r = (t) => Object.keys(t).every((a) => (t[a] === void 0, !0)), s = (t, a, e = !0) => [typeof t.topic == "string" && (1 <= t.topic.length || u(e, {
|
|
493
|
+
path: a + ".topic",
|
|
494
|
+
expected: "string & MinLength<1>",
|
|
495
|
+
value: t.topic
|
|
496
|
+
})) || u(e, {
|
|
497
|
+
path: a + ".topic",
|
|
498
|
+
expected: "(string & MinLength<1>)",
|
|
499
|
+
value: t.topic
|
|
500
|
+
}), t.args === void 0 || Array.isArray(t.args) || u(e, {
|
|
501
|
+
path: a + ".args",
|
|
502
|
+
expected: "(Array<unknown> | undefined)",
|
|
503
|
+
value: t.args
|
|
504
|
+
}), t.kwargs === void 0 || (typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 || u(e, {
|
|
505
|
+
path: a + ".kwargs",
|
|
506
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
507
|
+
value: t.kwargs
|
|
508
|
+
})) && o(t.kwargs, a + ".kwargs", e) || u(e, {
|
|
509
|
+
path: a + ".kwargs",
|
|
510
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
511
|
+
value: t.kwargs
|
|
512
|
+
})].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
|
|
513
|
+
let i, u;
|
|
514
|
+
return p((t) => {
|
|
515
|
+
if (l(t) === !1) {
|
|
516
|
+
i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
|
|
517
|
+
path: n + "",
|
|
518
|
+
expected: "PublishParams",
|
|
519
|
+
value: e
|
|
520
|
+
})) && s(e, n + "", !0) || u(!0, {
|
|
521
|
+
path: n + "",
|
|
522
|
+
expected: "PublishParams",
|
|
523
|
+
value: e
|
|
524
|
+
}))(t, "$input", !0);
|
|
525
|
+
const a = i.length === 0;
|
|
526
|
+
return a ? {
|
|
527
|
+
success: a,
|
|
528
|
+
data: t
|
|
529
|
+
} : {
|
|
530
|
+
success: a,
|
|
531
|
+
errors: i,
|
|
532
|
+
data: t
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
success: !0,
|
|
537
|
+
data: t
|
|
538
|
+
};
|
|
539
|
+
});
|
|
540
|
+
})(), Z = (() => {
|
|
541
|
+
const d = (t) => typeof t.deviceKey == "string" && 1 <= t.deviceKey.length && typeof t.topic == "string" && 1 <= t.topic.length && (t.args === void 0 || Array.isArray(t.args)) && (t.kwargs === void 0 || typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 && r(t.kwargs)), r = (t) => Object.keys(t).every((a) => (t[a] === void 0, !0)), s = (t, a, e = !0) => [typeof t.deviceKey == "string" && (1 <= t.deviceKey.length || u(e, {
|
|
542
|
+
path: a + ".deviceKey",
|
|
543
|
+
expected: "string & MinLength<1>",
|
|
544
|
+
value: t.deviceKey
|
|
545
|
+
})) || u(e, {
|
|
546
|
+
path: a + ".deviceKey",
|
|
547
|
+
expected: "(string & MinLength<1>)",
|
|
548
|
+
value: t.deviceKey
|
|
549
|
+
}), typeof t.topic == "string" && (1 <= t.topic.length || u(e, {
|
|
550
|
+
path: a + ".topic",
|
|
551
|
+
expected: "string & MinLength<1>",
|
|
552
|
+
value: t.topic
|
|
553
|
+
})) || u(e, {
|
|
554
|
+
path: a + ".topic",
|
|
555
|
+
expected: "(string & MinLength<1>)",
|
|
556
|
+
value: t.topic
|
|
557
|
+
}), t.args === void 0 || Array.isArray(t.args) || u(e, {
|
|
558
|
+
path: a + ".args",
|
|
559
|
+
expected: "(Array<unknown> | undefined)",
|
|
560
|
+
value: t.args
|
|
561
|
+
}), t.kwargs === void 0 || (typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 || u(e, {
|
|
562
|
+
path: a + ".kwargs",
|
|
563
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
564
|
+
value: t.kwargs
|
|
565
|
+
})) && o(t.kwargs, a + ".kwargs", e) || u(e, {
|
|
566
|
+
path: a + ".kwargs",
|
|
567
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
568
|
+
value: t.kwargs
|
|
569
|
+
})].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
|
|
570
|
+
let i, u;
|
|
571
|
+
return p((t) => {
|
|
572
|
+
if (l(t) === !1) {
|
|
573
|
+
i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
|
|
574
|
+
path: n + "",
|
|
575
|
+
expected: "CallParams",
|
|
576
|
+
value: e
|
|
577
|
+
})) && s(e, n + "", !0) || u(!0, {
|
|
578
|
+
path: n + "",
|
|
579
|
+
expected: "CallParams",
|
|
580
|
+
value: e
|
|
581
|
+
}))(t, "$input", !0);
|
|
582
|
+
const a = i.length === 0;
|
|
583
|
+
return a ? {
|
|
584
|
+
success: a,
|
|
585
|
+
data: t
|
|
586
|
+
} : {
|
|
587
|
+
success: a,
|
|
588
|
+
errors: i,
|
|
589
|
+
data: t
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
success: !0,
|
|
594
|
+
data: t
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
})(), z = (() => {
|
|
598
|
+
const d = (t) => typeof t.tablename == "string" && 1 <= t.tablename.length && (t.args === void 0 || Array.isArray(t.args)) && (t.kwargs === void 0 || typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 && r(t.kwargs)), r = (t) => Object.keys(t).every((a) => (t[a] === void 0, !0)), s = (t, a, e = !0) => [typeof t.tablename == "string" && (1 <= t.tablename.length || u(e, {
|
|
599
|
+
path: a + ".tablename",
|
|
600
|
+
expected: "string & MinLength<1>",
|
|
601
|
+
value: t.tablename
|
|
602
|
+
})) || u(e, {
|
|
603
|
+
path: a + ".tablename",
|
|
604
|
+
expected: "(string & MinLength<1>)",
|
|
605
|
+
value: t.tablename
|
|
606
|
+
}), t.args === void 0 || Array.isArray(t.args) || u(e, {
|
|
607
|
+
path: a + ".args",
|
|
608
|
+
expected: "(Array<unknown> | undefined)",
|
|
609
|
+
value: t.args
|
|
610
|
+
}), t.kwargs === void 0 || (typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 || u(e, {
|
|
611
|
+
path: a + ".kwargs",
|
|
612
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
613
|
+
value: t.kwargs
|
|
614
|
+
})) && o(t.kwargs, a + ".kwargs", e) || u(e, {
|
|
615
|
+
path: a + ".kwargs",
|
|
616
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
617
|
+
value: t.kwargs
|
|
618
|
+
})].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
|
|
619
|
+
let i, u;
|
|
620
|
+
return p((t) => {
|
|
621
|
+
if (l(t) === !1) {
|
|
622
|
+
i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
|
|
623
|
+
path: n + "",
|
|
624
|
+
expected: "TableParams",
|
|
625
|
+
value: e
|
|
626
|
+
})) && s(e, n + "", !0) || u(!0, {
|
|
627
|
+
path: n + "",
|
|
628
|
+
expected: "TableParams",
|
|
629
|
+
value: e
|
|
630
|
+
}))(t, "$input", !0);
|
|
631
|
+
const a = i.length === 0;
|
|
632
|
+
return a ? {
|
|
633
|
+
success: a,
|
|
634
|
+
data: t
|
|
635
|
+
} : {
|
|
636
|
+
success: a,
|
|
637
|
+
errors: i,
|
|
638
|
+
data: t
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
success: !0,
|
|
643
|
+
data: t
|
|
644
|
+
};
|
|
645
|
+
});
|
|
646
|
+
})();
|
|
647
|
+
function E(d) {
|
|
648
|
+
var r;
|
|
649
|
+
return typeof process < "u" ? (r = process.env) == null ? void 0 : r[d] : void 0;
|
|
650
|
+
}
|
|
651
|
+
function ee(d) {
|
|
652
|
+
const r = d ?? E("DEVICE_SERIAL_NUMBER");
|
|
653
|
+
if (!r)
|
|
654
|
+
throw new Error("serialNumber option is required (or set DEVICE_SERIAL_NUMBER env var in Node.js)");
|
|
655
|
+
return r;
|
|
656
|
+
}
|
|
657
|
+
class N {
|
|
658
|
+
constructor(r) {
|
|
659
|
+
this._isConfigured = !1, this._serialNumber = ee(r == null ? void 0 : r.serialNumber), this._deviceName = (r == null ? void 0 : r.deviceName) ?? E("DEVICE_NAME"), this._deviceKey = (r == null ? void 0 : r.deviceKey) ?? E("DEVICE_KEY"), this._appName = (r == null ? void 0 : r.appName) ?? E("APP_NAME"), this._swarmKey = (r == null ? void 0 : r.swarmKey) ?? parseInt(E("SWARM_KEY") ?? "0", 10), this._appKey = (r == null ? void 0 : r.appKey) ?? parseInt(E("APP_KEY") ?? "0", 10), this._env = (r == null ? void 0 : r.env) ?? E("ENV"), this._reswarmUrl = (r == null ? void 0 : r.reswarmUrl) ?? E("RESWARM_URL"), this._cburl = r == null ? void 0 : r.cburl, this._connection = new K();
|
|
660
|
+
const s = [];
|
|
661
|
+
this._deviceKey || s.push("DEVICE_KEY"), this._appName || s.push("APP_NAME"), this._swarmKey || s.push("SWARM_KEY"), this._appKey || s.push("APP_KEY"), s.length > 0 && console.warn(
|
|
662
|
+
`Warning: The following environment variables must be present: ${s.join(", ")}`
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
get connection() {
|
|
666
|
+
return this._connection;
|
|
667
|
+
}
|
|
668
|
+
get isConnected() {
|
|
669
|
+
return this._connection.is_open;
|
|
670
|
+
}
|
|
671
|
+
configureConnection(r) {
|
|
672
|
+
if (this._isConfigured) return;
|
|
673
|
+
const s = (this._env ?? "DEV").toUpperCase(), l = {
|
|
674
|
+
DEV: x.DEVELOPMENT,
|
|
675
|
+
PROD: x.PRODUCTION
|
|
676
|
+
}[s] ?? x.DEVELOPMENT, i = r ?? this._cburl ?? K.getWebSocketURI(this._reswarmUrl);
|
|
677
|
+
this._connection.configure(
|
|
678
|
+
this._swarmKey,
|
|
679
|
+
this._appKey,
|
|
680
|
+
l,
|
|
681
|
+
this._serialNumber,
|
|
682
|
+
i
|
|
683
|
+
), this._isConfigured = !0;
|
|
684
|
+
}
|
|
685
|
+
async start(r) {
|
|
686
|
+
this.configureConnection(r), await this._connection.start();
|
|
687
|
+
}
|
|
688
|
+
async stop() {
|
|
689
|
+
this._connection.stop();
|
|
690
|
+
}
|
|
691
|
+
async publish(r, s, o) {
|
|
692
|
+
const l = X({ topic: r, args: s, kwargs: o });
|
|
693
|
+
if (!l.success)
|
|
694
|
+
throw new Error(`Invalid publish parameters: ${l.errors.map((t) => t.path + ": " + t.expected).join(", ")}`);
|
|
695
|
+
const u = { ...{
|
|
696
|
+
DEVICE_SERIAL_NUMBER: this._serialNumber,
|
|
697
|
+
DEVICE_KEY: this._deviceKey,
|
|
698
|
+
DEVICE_NAME: this._deviceName
|
|
699
|
+
}, ...o ?? {} };
|
|
700
|
+
return this._connection.publish(r, s, u, {
|
|
701
|
+
acknowledge: !0
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
async publishToTable(r, s, o) {
|
|
705
|
+
const l = z({ tablename: r, args: s, kwargs: o });
|
|
706
|
+
if (!l.success)
|
|
707
|
+
throw new Error(`Invalid table parameters: ${l.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
|
|
708
|
+
if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
|
|
709
|
+
if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
|
|
710
|
+
const i = `${this._swarmKey}.${this._appKey}.${r}`;
|
|
711
|
+
return this.publish(i, s, o);
|
|
712
|
+
}
|
|
713
|
+
async subscribe(r, s, o) {
|
|
714
|
+
return this._connection.subscribe(r, s);
|
|
715
|
+
}
|
|
716
|
+
async subscribeToTable(r, s, o) {
|
|
717
|
+
if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
|
|
718
|
+
if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
|
|
719
|
+
const l = `${this._swarmKey}.${this._appKey}.${r}`;
|
|
720
|
+
return this.subscribe(l, s, o);
|
|
721
|
+
}
|
|
722
|
+
async call(r, s, o, l, i) {
|
|
723
|
+
const u = Z({ deviceKey: r, topic: s, args: o, kwargs: l });
|
|
724
|
+
if (!u.success)
|
|
725
|
+
throw new Error(`Invalid call parameters: ${u.errors.map((a) => a.path + ": " + a.expected).join(", ")}`);
|
|
726
|
+
const t = `${r}.${s}`;
|
|
727
|
+
return this._connection.call(t, o, l, i);
|
|
728
|
+
}
|
|
729
|
+
async registerFunction(r, s, o) {
|
|
730
|
+
const l = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${r}`, i = await this._connection.register(l, s);
|
|
731
|
+
return console.log(`Function registered for IronFlock topic '${r}'. (Full WAMP topic: '${l}')`), i;
|
|
732
|
+
}
|
|
733
|
+
async register(r, s, o) {
|
|
734
|
+
return this.registerFunction(r, s, o);
|
|
735
|
+
}
|
|
736
|
+
async getHistory(r, s = { limit: 10 }) {
|
|
737
|
+
if (!r) throw new Error("Tablename must not be empty!");
|
|
738
|
+
const o = H(s);
|
|
739
|
+
if (!o.success)
|
|
740
|
+
throw new Error(`Invalid query parameters: ${o.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
|
|
741
|
+
const l = `history.transformed.app.${this._appKey}.${r}`;
|
|
742
|
+
try {
|
|
743
|
+
return await this._connection.call(l, [s]);
|
|
744
|
+
} catch (i) {
|
|
745
|
+
const u = String(i);
|
|
746
|
+
return u.includes("no_such_procedure") || u.includes("no callee registered") ? (console.error(`Get history failed: History service procedure '${l}' not registered`), null) : (console.error(`Get history failed: ${i}`), null);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
async setDeviceLocation(r, s) {
|
|
750
|
+
const o = G({ longitude: r, latitude: s });
|
|
751
|
+
if (!o.success)
|
|
752
|
+
throw new Error(`Invalid location parameters: ${o.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
|
|
753
|
+
const l = { long: r, lat: s }, i = {
|
|
754
|
+
DEVICE_SERIAL_NUMBER: this._serialNumber,
|
|
755
|
+
DEVICE_KEY: this._deviceKey,
|
|
756
|
+
DEVICE_NAME: this._deviceName
|
|
757
|
+
};
|
|
758
|
+
try {
|
|
759
|
+
return await this._connection.call(
|
|
760
|
+
"ironflock.location_service.update",
|
|
761
|
+
[l],
|
|
762
|
+
i
|
|
763
|
+
);
|
|
764
|
+
} catch (u) {
|
|
765
|
+
return console.error(`Set location failed: ${u}`), null;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
getRemoteAccessUrlForPort(r) {
|
|
769
|
+
return this._deviceKey && this._appName ? `https://${this._deviceKey}-${this._appName.toLowerCase()}-${r}.app.ironflock.com` : null;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Create an IronFlock instance by fetching configuration from a server endpoint.
|
|
773
|
+
* The endpoint should return JSON matching `IronFlockOptions`.
|
|
774
|
+
*
|
|
775
|
+
* Useful in browser environments where config is provided by a backend:
|
|
776
|
+
* ```ts
|
|
777
|
+
* const flock = await IronFlock.fromServer("/api/ironflock-config");
|
|
778
|
+
* await flock.start();
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
static async fromServer(r) {
|
|
782
|
+
const s = await fetch(r);
|
|
783
|
+
if (!s.ok)
|
|
784
|
+
throw new Error(`Failed to fetch IronFlock config from ${r}: ${s.status} ${s.statusText}`);
|
|
785
|
+
const o = await s.json();
|
|
786
|
+
return new N(o);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
export {
|
|
790
|
+
K as CrossbarConnection,
|
|
791
|
+
N as IronFlock,
|
|
792
|
+
x as Stage,
|
|
793
|
+
Z as validateCallParams,
|
|
794
|
+
G as validateLocationParams,
|
|
795
|
+
X as validatePublishParams,
|
|
796
|
+
z as validateTableParams,
|
|
797
|
+
H as validateTableQueryParams
|
|
798
|
+
};
|
|
799
|
+
//# sourceMappingURL=index.mjs.map
|