@nanolink/mirrors 1.1.7 → 1.1.8-beta.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.
Files changed (57) hide show
  1. package/README.md +82 -21
  2. package/dist/MirrorSync.d.ts +18 -0
  3. package/dist/MirrorSync.js +65 -15
  4. package/dist/MirrorSync.js.map +1 -1
  5. package/dist/SubscriptionClient.js +8 -18
  6. package/dist/SubscriptionClient.js.map +1 -1
  7. package/dist/definitions/messagesubscriptions/index.d.ts +1 -0
  8. package/dist/definitions/messagesubscriptions/index.js +18 -0
  9. package/dist/definitions/messagesubscriptions/index.js.map +1 -0
  10. package/dist/definitions/messagesubscriptions/messages.d.ts +1 -0
  11. package/dist/definitions/{subscriptions → messagesubscriptions}/messages.js +1 -1
  12. package/dist/definitions/messagesubscriptions/messages.js.map +1 -0
  13. package/dist/definitions/mirrors.d.ts +9 -1
  14. package/dist/definitions/mirrors.js +12 -3
  15. package/dist/definitions/mirrors.js.map +1 -1
  16. package/dist/definitions/opsubscriptions/contained.d.ts +1 -1
  17. package/dist/definitions/opsubscriptions/contained.js +4 -4
  18. package/dist/definitions/opsubscriptions/index.d.ts +1 -0
  19. package/dist/definitions/opsubscriptions/index.js +1 -0
  20. package/dist/definitions/opsubscriptions/index.js.map +1 -1
  21. package/dist/definitions/opsubscriptions/trips.d.ts +1 -0
  22. package/dist/definitions/opsubscriptions/trips.js +30 -0
  23. package/dist/definitions/opsubscriptions/trips.js.map +1 -0
  24. package/dist/definitions/subscriptions/alarm.d.ts +1 -0
  25. package/dist/definitions/subscriptions/alarm.js +19 -0
  26. package/dist/definitions/subscriptions/alarm.js.map +1 -0
  27. package/dist/definitions/subscriptions/humiditydecimal.d.ts +1 -0
  28. package/dist/definitions/subscriptions/humiditydecimal.js +18 -0
  29. package/dist/definitions/subscriptions/humiditydecimal.js.map +1 -0
  30. package/dist/definitions/subscriptions/index.d.ts +6 -1
  31. package/dist/definitions/subscriptions/index.js +6 -1
  32. package/dist/definitions/subscriptions/index.js.map +1 -1
  33. package/dist/definitions/subscriptions/references.d.ts +1 -1
  34. package/dist/definitions/subscriptions/references.js +4 -4
  35. package/dist/definitions/subscriptions/servicePlans.d.ts +1 -1
  36. package/dist/definitions/subscriptions/servicePlans.js +1 -0
  37. package/dist/definitions/subscriptions/servicePlans.js.map +1 -1
  38. package/dist/definitions/subscriptions/taskTemplates.d.ts +1 -0
  39. package/dist/definitions/subscriptions/taskTemplates.js +38 -0
  40. package/dist/definitions/subscriptions/taskTemplates.js.map +1 -0
  41. package/dist/definitions/subscriptions/tasks.d.ts +1 -0
  42. package/dist/definitions/subscriptions/tasks.js +22 -0
  43. package/dist/definitions/subscriptions/tasks.js.map +1 -0
  44. package/dist/definitions/subscriptions/temperaturedecimal.d.ts +1 -0
  45. package/dist/definitions/subscriptions/temperaturedecimal.js +18 -0
  46. package/dist/definitions/subscriptions/temperaturedecimal.js.map +1 -0
  47. package/dist/definitions/subscriptions/trips2.d.ts +1 -0
  48. package/dist/definitions/subscriptions/trips2.js +32 -0
  49. package/dist/definitions/subscriptions/trips2.js.map +1 -0
  50. package/dist/index.d.ts +2 -1
  51. package/dist/index.js +2 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist-compat/index.js +268 -57
  54. package/dist-compat/index.js.map +1 -1
  55. package/package.json +6 -6
  56. package/dist/definitions/subscriptions/messages.d.ts +0 -1
  57. package/dist/definitions/subscriptions/messages.js.map +0 -1
@@ -64,6 +64,7 @@ __export(index_exports, {
64
64
  Connection: () => Connection,
65
65
  DelegatingObject: () => DelegatingObject,
66
66
  MirrorSync: () => MirrorSync,
67
+ OpSubscriptions: () => OpSubscriptions,
67
68
  RequiredMirrors: () => RequiredMirrors,
68
69
  SubscriptionClient: () => SubscriptionClient_default,
69
70
  Subscriptions: () => Subscriptions,
@@ -156,12 +157,18 @@ var MirrorSync = class extends import_eventemitter3.default {
156
157
  { query: this.options.subscription, variables },
157
158
  {
158
159
  next: (envelope) => {
159
- if (envelope.errors) {
160
- this.l("graphql errors", envelope.errors);
161
- this.emit("error", envelope.errors);
160
+ try {
161
+ if (envelope.errors) {
162
+ this.l("graphql errors", envelope.errors);
163
+ this.emit("error", envelope.errors);
164
+ }
165
+ const payload = envelope.data;
166
+ if (payload) this.handlePayload(payload);
167
+ } catch (err) {
168
+ this.l("unhandled error in next handler", err);
169
+ this.emit("error", err);
170
+ throw err;
162
171
  }
163
- const payload = envelope.data;
164
- if (payload) this.handlePayload(payload);
165
172
  },
166
173
  error: (err) => {
167
174
  this.l("subscription error", err);
@@ -186,6 +193,39 @@ var MirrorSync = class extends import_eventemitter3.default {
186
193
  if (!this.unsub) this.start();
187
194
  return this.loaded;
188
195
  }
196
+ waitForUpdated(matcher, options) {
197
+ return this.waitForMirrorEvent("updated", matcher, options);
198
+ }
199
+ waitForDeleted(matcher, options) {
200
+ return this.waitForMirrorEvent("deleted", matcher, options);
201
+ }
202
+ waitForMirrorEvent(event, matcher, options) {
203
+ var _a;
204
+ const timeoutMs = (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 12e4;
205
+ return new Promise((resolve, reject) => {
206
+ let timeout;
207
+ const cleanup = () => {
208
+ this.off(event, handler);
209
+ if (timeout) clearTimeout(timeout);
210
+ };
211
+ const handler = (payload) => {
212
+ if (!this.matchesMirrorEvent(event, matcher, payload)) return;
213
+ cleanup();
214
+ resolve(payload);
215
+ };
216
+ this.on(event, handler);
217
+ if (timeoutMs > 0) {
218
+ timeout = setTimeout(() => {
219
+ cleanup();
220
+ reject(new Error(`Timeout waiting for mirror ${event} event`));
221
+ }, timeoutMs);
222
+ }
223
+ });
224
+ }
225
+ matchesMirrorEvent(event, matcher, payload) {
226
+ if (typeof matcher === "function") return matcher(payload);
227
+ return event === "updated" ? payload.doc.id === matcher : payload.orgDoc.id === matcher;
228
+ }
189
229
  resetLoaded() {
190
230
  this.loaded = new Promise((resolve) => {
191
231
  this.resolveLoaded = resolve;
@@ -232,17 +272,22 @@ var MirrorSync = class extends import_eventemitter3.default {
232
272
  break;
233
273
  }
234
274
  case "VERSION_ERROR" /* VERSION_ERROR */:
235
- const ve = { currentVersion: this.currentVersion };
236
- this.currentVersion = -1;
237
- this.currentOpVersion = null;
238
- this.buffer = /* @__PURE__ */ new Map();
239
- this.fullSyncPhase = true;
240
- this.resetLoaded();
241
- this.emit("versionError", ve);
242
- this.subscribeInternal(this.currentVersion, this.currentOpVersion);
275
+ this.handleVersionError();
243
276
  break;
244
277
  }
245
278
  }
279
+ handleVersionError() {
280
+ const ve = { currentVersion: this.currentVersion };
281
+ this.currentVersion = -1;
282
+ this.currentOpVersion = null;
283
+ this.buffer = /* @__PURE__ */ new Map();
284
+ this.fullSyncPhase = true;
285
+ this.resetLoaded();
286
+ setTimeout(() => {
287
+ this.emit("versionError", ve);
288
+ this.subscribeInternal(this.currentVersion, this.currentOpVersion);
289
+ }, 0);
290
+ }
246
291
  normalizeItems(data) {
247
292
  if (!data) return [];
248
293
  return Array.isArray(data) ? data : [data];
@@ -1192,22 +1237,13 @@ var SubscriptionClient = class extends import_eventemitter32.default {
1192
1237
  this.emit("error", err);
1193
1238
  this.log("socket error", err);
1194
1239
  },
1195
- closed: async (ev) => {
1240
+ closed: (ev) => {
1196
1241
  var _a, _b, _c, _d;
1197
- try {
1198
- const e = ev;
1199
- this.log("closed", e);
1200
- this.emit("disconnected", { code: e.code, reason: (_c = (_b = (_a = e.reason) == null ? void 0 : _a.toString) == null ? void 0 : _b.call(_a)) != null ? _c : "", wasClean: (_d = e.wasClean) != null ? _d : false });
1201
- try {
1202
- if (this.client) {
1203
- await this.client.dispose();
1204
- }
1205
- } catch (e2) {
1206
- }
1207
- } finally {
1208
- this.client = null;
1209
- if (!this.closedExplicitly) this.scheduleReconnect();
1210
- }
1242
+ const e = ev;
1243
+ this.log("closed", e);
1244
+ this.emit("disconnected", { code: e.code, reason: (_c = (_b = (_a = e.reason) == null ? void 0 : _a.toString) == null ? void 0 : _b.call(_a)) != null ? _c : "", wasClean: (_d = e.wasClean) != null ? _d : false });
1245
+ this.client = null;
1246
+ if (!this.closedExplicitly) this.scheduleReconnect();
1211
1247
  }
1212
1248
  }
1213
1249
  });
@@ -1359,7 +1395,7 @@ var references = `
1359
1395
  serviceData {
1360
1396
  __typename
1361
1397
  ... on QMServiceDataOneshot { ${serviceDataCommonFields} due dueSlackInDays }
1362
- ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period intervalType due dueSlackInDays }
1398
+ ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period periodCount intervalType due dueSlackInDays }
1363
1399
  ... on QMServiceDataWarranty { ${serviceDataCommonFields} purchaseDate warrantyInMonths due dueSlackInDays }
1364
1400
  ... on QMServiceDataTrackerStateInt { ${serviceDataCommonFields} dueSlackSeconds : dueSlack nextDueSeconds : nextDue trackerVID }
1365
1401
  ... on QMServiceDataTrackerStateDouble { ${serviceDataCommonFields} dueSlackKM : dueSlack nextDueKM : nextDue trackerVID }
@@ -1385,7 +1421,7 @@ var references = `
1385
1421
  serviceData {
1386
1422
  __typename
1387
1423
  ... on QMServiceDataOneshot { ${serviceDataCommonFields} due dueSlackInDays }
1388
- ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period intervalType due dueSlackInDays }
1424
+ ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period periodCount intervalType due dueSlackInDays }
1389
1425
  ... on QMServiceDataWarranty { ${serviceDataCommonFields} purchaseDate warrantyInMonths due dueSlackInDays }
1390
1426
  ... on QMServiceDataTrackerStateInt { ${serviceDataCommonFields} dueSlackSeconds : dueSlack nextDueSeconds : nextDue trackerVID }
1391
1427
  ... on QMServiceDataTrackerStateDouble { ${serviceDataCommonFields} dueSlackKM : dueSlack nextDueKM : nextDue trackerVID }
@@ -1404,7 +1440,7 @@ var references = `
1404
1440
  serviceData {
1405
1441
  __typename
1406
1442
  ... on QMServiceDataOneshot { ${serviceDataCommonFields} due dueSlackInDays }
1407
- ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period intervalType due dueSlackInDays }
1443
+ ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period periodCount intervalType due dueSlackInDays }
1408
1444
  ... on QMServiceDataWarranty { ${serviceDataCommonFields} purchaseDate warrantyInMonths due dueSlackInDays }
1409
1445
  ... on QMServiceDataTrackerStateInt { ${serviceDataCommonFields} dueSlackSeconds : dueSlack nextDueSeconds : nextDue trackerVID }
1410
1446
  ... on QMServiceDataTrackerStateDouble { ${serviceDataCommonFields} dueSlackKM : dueSlack nextDueKM : nextDue trackerVID }
@@ -1574,7 +1610,7 @@ var references = `
1574
1610
  serviceData {
1575
1611
  __typename
1576
1612
  ... on QMServiceDataOneshot { ${serviceDataCommonFields} due dueSlackInDays }
1577
- ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period intervalType due dueSlackInDays }
1613
+ ... on QMServiceDataPeriodic { ${serviceDataCommonFields} startDate lastServiceDate period periodCount intervalType due dueSlackInDays }
1578
1614
  ... on QMServiceDataWarranty { ${serviceDataCommonFields} purchaseDate warrantyInMonths due dueSlackInDays }
1579
1615
  ... on QMServiceDataTrackerStateInt { ${serviceDataCommonFields} dueSlackSeconds : dueSlack nextDueSeconds : nextDue trackerVID }
1580
1616
  ... on QMServiceDataTrackerStateDouble { ${serviceDataCommonFields} dueSlackKM : dueSlack nextDueKM : nextDue trackerVID }
@@ -1651,6 +1687,7 @@ var servicePlans = `
1651
1687
  ${mServiceCommonFields}
1652
1688
  dueSlackInDays
1653
1689
  period
1690
+ periodCount
1654
1691
  intervalType
1655
1692
  deleted
1656
1693
  }
@@ -2062,6 +2099,23 @@ var unplug = `subscription unplug($opVersion: String) {
2062
2099
  }
2063
2100
  }`;
2064
2101
 
2102
+ // src/definitions/subscriptions/alarm.ts
2103
+ var alarm = `subscription alarm($opVersion: String) {
2104
+ otrackers_infoanybulk(subscribe: true, includeInitial: true, fields:[ALARM], opVersion: $opVersion) {
2105
+ type
2106
+ total
2107
+ deleteId
2108
+ deleteVersion
2109
+ data {
2110
+ id: vID
2111
+ opVersion
2112
+ field
2113
+ value
2114
+ stamp
2115
+ }
2116
+ }
2117
+ }`;
2118
+
2065
2119
  // src/definitions/subscriptions/temperature.ts
2066
2120
  var temperature = `subscription temperature($opVersion: String) {
2067
2121
  otrackers_infoanybulk(subscribe: true, includeInitial: true, fields:[TEMPERATURE], opVersion: $opVersion) {
@@ -2078,6 +2132,38 @@ var temperature = `subscription temperature($opVersion: String) {
2078
2132
  }
2079
2133
  }`;
2080
2134
 
2135
+ // src/definitions/subscriptions/temperaturedecimal.ts
2136
+ var temperaturedecimal = `subscription temperaturedecimal($opVersion: String) {
2137
+ otrackers_infoanybulk(subscribe: true, includeInitial: true, fields:[TEMPERATURE_DECIMAL], opVersion: $opVersion) {
2138
+ type
2139
+ total
2140
+ deleteId
2141
+ deleteVersion
2142
+ data {
2143
+ id: vID
2144
+ opVersion
2145
+ value
2146
+ stamp
2147
+ }
2148
+ }
2149
+ }`;
2150
+
2151
+ // src/definitions/subscriptions/humiditydecimal.ts
2152
+ var humiditydecimal = `subscription humiditydecimal($opVersion: String) {
2153
+ otrackers_infoanybulk(subscribe: true, includeInitial: true, fields:[HUMIDITY_DECIMAL], opVersion: $opVersion) {
2154
+ type
2155
+ total
2156
+ deleteId
2157
+ deleteVersion
2158
+ data {
2159
+ id: vID
2160
+ opVersion
2161
+ value
2162
+ stamp
2163
+ }
2164
+ }
2165
+ }`;
2166
+
2081
2167
  // src/definitions/subscriptions/meshscanner.ts
2082
2168
  var meshscanner = `subscription temperature($opVersion: String) {
2083
2169
  otrackers_infoanybulk(subscribe: true, includeInitial: true, fields:[MESH_GATE_ON], opVersion: $opVersion) {
@@ -2318,34 +2404,121 @@ var trips = `subscription trips($opVersion: String) {
2318
2404
  }
2319
2405
  }`;
2320
2406
 
2321
- // src/definitions/subscriptions/messages.ts
2322
- var messages = `
2323
- subscription Messages($version:Int!) {
2324
- message_getweb(version: $version) {
2407
+ // src/definitions/subscriptions/tasks.ts
2408
+ var tasks = `subscription tasks($version: Int!) {
2409
+ mtask_get(version:$version, subscribe: true) {
2325
2410
  ${mCommonFields}
2326
2411
  data {
2327
- id
2328
- multiId
2329
- version
2330
- createdAt
2331
- from { id fullName mobilePhoneNumber mobileCountryCode email language }
2332
- to { id fullName mobilePhoneNumber mobileCountryCode email language }
2333
- title
2334
- content
2335
- shortContent
2336
- attachmentUrl
2337
- type
2338
- status
2339
- transportTypes
2340
- emailStatus { success errorMessage }
2341
- smsStatus { success errorMessage }
2342
- additionalInfo
2343
- emailTemplate
2344
- deleted
2412
+ ${commonFields}
2413
+ templateId
2414
+ templateVersion
2415
+ title
2416
+ status
2417
+ accessRoles
2418
+ fieldValues { key value }
2419
+ documents { id name url mimeType fileName createdDate }
2420
+ targetReferenceId
2421
+ deleted
2345
2422
  }
2346
- }
2347
2423
  }
2348
- `;
2424
+ }`;
2425
+
2426
+ // src/definitions/subscriptions/taskTemplates.ts
2427
+ var taskTemplates = `subscription taskTemplates($version: Int!) {
2428
+ mtasktemplate_get(version:$version, subscribe: true) {
2429
+ ${mCommonFields}
2430
+ data {
2431
+ ${commonFields}
2432
+ groupIds
2433
+ name
2434
+ description
2435
+ createAccessRoles
2436
+ processingAccessRoles
2437
+ finishAccessRoles
2438
+ design
2439
+ fields {
2440
+ key
2441
+ label
2442
+ type
2443
+ required
2444
+ linkedStatus
2445
+ groupKey
2446
+ options { key label }
2447
+ }
2448
+ statuses {
2449
+ key
2450
+ label
2451
+ color
2452
+ icon
2453
+ isTerminal
2454
+ isDefault
2455
+ }
2456
+ deleted
2457
+ }
2458
+ }
2459
+ }`;
2460
+
2461
+ // src/definitions/opsubscriptions/contained.ts
2462
+ var contained = `subscription contained($opVersion: String) {
2463
+ contained(opversion: $opVersion) {
2464
+ type
2465
+ data {
2466
+ id
2467
+ receiverId
2468
+ start
2469
+ deleted
2470
+ opVersion
2471
+ }
2472
+ deleteId
2473
+ }
2474
+ }`;
2475
+
2476
+ // src/definitions/opsubscriptions/stateLinks.ts
2477
+ var stateLinks = `subscription stateLink($opVersion: String) {
2478
+ stateLink(opversion: $opVersion) {
2479
+ type
2480
+ data {
2481
+ id
2482
+ receiverId
2483
+ transmitterId
2484
+ stamp
2485
+ lastUpdated
2486
+ rssi
2487
+ opVersion
2488
+ closed
2489
+ }
2490
+ deleteId
2491
+ deleteVersion
2492
+ }
2493
+ }`;
2494
+
2495
+ // src/definitions/opsubscriptions/trips.ts
2496
+ var trips2 = `subscription stateTrips($opVersion: String) {
2497
+ stateTrips(opversion: $opVersion) {
2498
+ type
2499
+ data {
2500
+ id
2501
+ trips {
2502
+ startGPS {
2503
+ stamp
2504
+ longitude
2505
+ latitude
2506
+ }
2507
+ endGPS {
2508
+ stamp
2509
+ longitude
2510
+ latitude
2511
+ }
2512
+ distance
2513
+ completed
2514
+ }
2515
+ deleted
2516
+ opVersion
2517
+ }
2518
+ deleteId
2519
+ deleteVersion
2520
+ }
2521
+ }`;
2349
2522
 
2350
2523
  // src/definitions/requiredMirrors/systemSettings.ts
2351
2524
  var systemSettings = `subscription systemsetting($version: Int!) {
@@ -2428,6 +2601,35 @@ var roles = `subscription roles($version: Int!) {
2428
2601
  // src/definitions/tempSubscriptions/index.ts
2429
2602
  var TempSubscriptions = {};
2430
2603
 
2604
+ // src/definitions/messagesubscriptions/messages.ts
2605
+ var messages = `
2606
+ subscription Messages($version:Int!) {
2607
+ getweb(version: $version) {
2608
+ ${mCommonFields}
2609
+ data {
2610
+ id
2611
+ multiId
2612
+ version
2613
+ createdAt
2614
+ from { id fullName mobilePhoneNumber mobileCountryCode email language }
2615
+ to { id fullName mobilePhoneNumber mobileCountryCode email language }
2616
+ title
2617
+ content
2618
+ shortContent
2619
+ attachmentUrl
2620
+ type
2621
+ status
2622
+ transportTypes
2623
+ emailStatus { success errorMessage }
2624
+ smsStatus { success errorMessage }
2625
+ additionalInfo
2626
+ emailTemplate
2627
+ deleted
2628
+ }
2629
+ }
2630
+ }
2631
+ `;
2632
+
2431
2633
  // src/definitions/mirrors.ts
2432
2634
  var Subscriptions = {
2433
2635
  references,
@@ -2447,7 +2649,10 @@ var Subscriptions = {
2447
2649
  voltage,
2448
2650
  internalvoltage,
2449
2651
  unplug,
2652
+ alarm,
2450
2653
  temperature,
2654
+ temperaturedecimal,
2655
+ humiditydecimal,
2451
2656
  meshscanner,
2452
2657
  meshdisconnectslasthour,
2453
2658
  activecounter,
@@ -2460,7 +2665,13 @@ var Subscriptions = {
2460
2665
  activesteps,
2461
2666
  referenceGeoLinks,
2462
2667
  trips,
2463
- messages
2668
+ tasks,
2669
+ taskTemplates
2670
+ };
2671
+ var OpSubscriptions = {
2672
+ contained,
2673
+ stateLinks,
2674
+ trips3: trips2
2464
2675
  };
2465
2676
  var RequiredMirrors = {
2466
2677
  systemSettings,