@omirion/orbit-sdk 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1107,7 +1107,9 @@ var ValidationError = class extends OrbitError {
1107
1107
  this.fieldErrors = options.fieldErrors ?? [];
1108
1108
  }
1109
1109
  };
1110
- var BundleExistsError = class extends OrbitError {
1110
+ var ConflictError = class extends OrbitError {
1111
+ };
1112
+ var BundleExistsError = class extends ConflictError {
1111
1113
  };
1112
1114
  var DeviceRpcError = class extends OrbitError {
1113
1115
  };
@@ -1125,12 +1127,6 @@ var RateLimitError = class extends OrbitError {
1125
1127
  function extractErrorFields(body) {
1126
1128
  if (!body || typeof body !== "object") return {};
1127
1129
  const record = body;
1128
- if (typeof record.error === "string") {
1129
- return {
1130
- code: record.error,
1131
- message: typeof record.message === "string" ? record.message : record.error
1132
- };
1133
- }
1134
1130
  if (Array.isArray(record.errors) && record.errors.length > 0) {
1135
1131
  const first = record.errors[0];
1136
1132
  return {
@@ -1182,7 +1178,7 @@ function normalizeError(status, body, response) {
1182
1178
  case 404:
1183
1179
  return new ResourceNotFoundError(msg, base);
1184
1180
  case 409:
1185
- return new BundleExistsError(msg, base);
1181
+ return code === "E_BUNDLE_ALREADY_EXISTS" ? new BundleExistsError(msg, base) : new ConflictError(msg, base);
1186
1182
  case 422:
1187
1183
  return new ValidationError(msg, { ...base, fieldErrors: extractFieldErrors(body) });
1188
1184
  case 429:
@@ -1297,28 +1293,53 @@ var OrbitClient = class {
1297
1293
  this.#retryBaseDelayMs = options.retryBaseDelayMs ?? 500;
1298
1294
  const client2 = this.#client;
1299
1295
  const run = this.#run.bind(this);
1300
- this.me = () => run(() => getIdentity({ client: client2, throwOnError: false }));
1296
+ this.me = () => run(() => getIdentity({ client: client2, throwOnError: false })).then(
1297
+ (result) => result.data
1298
+ );
1301
1299
  this.projects = {
1302
1300
  list: (params = {}) => run(() => listProjects({ client: client2, query: params, throwOnError: false })),
1303
1301
  iterate: (params = {}) => paginate(async (cursor) => {
1304
1302
  const page = await run(
1305
- () => listProjects({ client: client2, query: { ...params, cursor }, throwOnError: false })
1303
+ () => listProjects({
1304
+ client: client2,
1305
+ query: { ...params, cursor },
1306
+ throwOnError: false
1307
+ })
1306
1308
  );
1307
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1309
+ return {
1310
+ data: page.data,
1311
+ nextCursor: page.meta.nextCursor,
1312
+ hasMore: page.meta.hasMore
1313
+ };
1308
1314
  }),
1309
- get: (id) => run(() => getProject({ client: client2, path: { id }, throwOnError: false })),
1315
+ get: (id) => run(() => getProject({ client: client2, path: { id }, throwOnError: false })).then(
1316
+ (result) => result.data
1317
+ ),
1310
1318
  appToken: {
1311
1319
  create: (projectId) => run(
1312
- () => createProjectAppToken({ client: client2, path: { id: projectId }, throwOnError: false })
1313
- ),
1320
+ () => createProjectAppToken({
1321
+ client: client2,
1322
+ path: { id: projectId },
1323
+ throwOnError: false
1324
+ })
1325
+ ).then((result) => result.data),
1314
1326
  rotate: (projectId) => run(
1315
- () => rotateProjectAppToken({ client: client2, path: { id: projectId }, throwOnError: false })
1316
- )
1327
+ () => rotateProjectAppToken({
1328
+ client: client2,
1329
+ path: { id: projectId },
1330
+ throwOnError: false
1331
+ })
1332
+ ).then((result) => result.data)
1317
1333
  }
1318
1334
  };
1319
1335
  this.deviceTypes = {
1320
1336
  list: (projectId, params = {}) => run(
1321
- () => listDeviceTypes({ client: client2, path: { projectId }, query: params, throwOnError: false })
1337
+ () => listDeviceTypes({
1338
+ client: client2,
1339
+ path: { projectId },
1340
+ query: params,
1341
+ throwOnError: false
1342
+ })
1322
1343
  ),
1323
1344
  iterate: (projectId, params = {}) => paginate(async (cursor) => {
1324
1345
  const page = await run(
@@ -1329,36 +1350,70 @@ var OrbitClient = class {
1329
1350
  throwOnError: false
1330
1351
  })
1331
1352
  );
1332
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1353
+ return {
1354
+ data: page.data,
1355
+ nextCursor: page.meta.nextCursor,
1356
+ hasMore: page.meta.hasMore
1357
+ };
1333
1358
  }),
1334
1359
  get: (projectId, slug) => run(
1335
- () => getDeviceType({ client: client2, path: { projectId, slug }, throwOnError: false })
1336
- ),
1360
+ () => getDeviceType({
1361
+ client: client2,
1362
+ path: { projectId, slug },
1363
+ throwOnError: false
1364
+ })
1365
+ ).then((result) => result.data),
1337
1366
  create: (projectId, body) => run(
1338
- () => createDeviceType({ client: client2, path: { projectId }, body, throwOnError: false })
1339
- ),
1367
+ () => createDeviceType({
1368
+ client: client2,
1369
+ path: { projectId },
1370
+ body,
1371
+ throwOnError: false
1372
+ })
1373
+ ).then((result) => result.data),
1340
1374
  update: (projectId, slug, body) => run(
1341
- () => updateDeviceType({ client: client2, path: { projectId, slug }, body, throwOnError: false })
1342
- ),
1375
+ () => updateDeviceType({
1376
+ client: client2,
1377
+ path: { projectId, slug },
1378
+ body,
1379
+ throwOnError: false
1380
+ })
1381
+ ).then((result) => result.data),
1343
1382
  delete: async (projectId, slug) => {
1344
1383
  await run(
1345
- () => deleteDeviceType({ client: client2, path: { projectId, slug }, throwOnError: false })
1384
+ () => deleteDeviceType({
1385
+ client: client2,
1386
+ path: { projectId, slug },
1387
+ throwOnError: false
1388
+ })
1346
1389
  );
1347
1390
  }
1348
1391
  };
1349
1392
  this.devices = {
1350
1393
  list: (params = {}) => run(() => listDevices({ client: client2, query: params, throwOnError: false })),
1351
- get: (id) => run(() => getDevice({ client: client2, path: { id }, throwOnError: false })),
1394
+ get: (id) => run(() => getDevice({ client: client2, path: { id }, throwOnError: false })).then(
1395
+ (result) => result.data
1396
+ ),
1352
1397
  iterate: (params = {}) => paginate(async (cursor) => {
1353
1398
  const page = await run(
1354
- () => listDevices({ client: client2, query: { ...params, cursor }, throwOnError: false })
1399
+ () => listDevices({
1400
+ client: client2,
1401
+ query: { ...params, cursor },
1402
+ throwOnError: false
1403
+ })
1355
1404
  );
1356
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1405
+ return {
1406
+ data: page.data,
1407
+ nextCursor: page.meta.nextCursor,
1408
+ hasMore: page.meta.hasMore
1409
+ };
1357
1410
  }),
1358
1411
  delete: async (id) => {
1359
1412
  await run(() => deleteDevice({ client: client2, path: { id }, throwOnError: false }));
1360
1413
  },
1361
- resetToken: (id) => run(() => resetDeviceToken({ client: client2, path: { id }, throwOnError: false }))
1414
+ resetToken: (id) => run(
1415
+ () => resetDeviceToken({ client: client2, path: { id }, throwOnError: false })
1416
+ ).then((result) => result.data)
1362
1417
  };
1363
1418
  this.admissions = {
1364
1419
  list: (params = {}) => run(
@@ -1366,34 +1421,68 @@ var OrbitClient = class {
1366
1421
  ),
1367
1422
  iterate: (params = {}) => paginate(async (cursor) => {
1368
1423
  const page = await run(
1369
- () => listAdmissions({ client: client2, query: { ...params, cursor }, throwOnError: false })
1424
+ () => listAdmissions({
1425
+ client: client2,
1426
+ query: { ...params, cursor },
1427
+ throwOnError: false
1428
+ })
1370
1429
  );
1371
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1430
+ return {
1431
+ data: page.data,
1432
+ nextCursor: page.meta.nextCursor,
1433
+ hasMore: page.meta.hasMore
1434
+ };
1372
1435
  }),
1373
- get: (id) => run(() => getAdmission({ client: client2, path: { id }, throwOnError: false })),
1436
+ get: (id) => run(
1437
+ () => getAdmission({ client: client2, path: { id }, throwOnError: false })
1438
+ ).then((result) => result.data),
1374
1439
  accept: (id, params) => run(
1375
- () => acceptAdmission({ client: client2, path: { id }, body: params, throwOnError: false })
1376
- ),
1377
- reject: (id) => run(() => rejectAdmission({ client: client2, path: { id }, throwOnError: false })),
1378
- dismiss: (id) => run(() => dismissAdmission({ client: client2, path: { id }, throwOnError: false }))
1440
+ () => acceptAdmission({
1441
+ client: client2,
1442
+ path: { id },
1443
+ body: params,
1444
+ throwOnError: false
1445
+ })
1446
+ ).then((result) => result.data),
1447
+ reject: (id) => run(
1448
+ () => rejectAdmission({ client: client2, path: { id }, throwOnError: false })
1449
+ ).then((result) => result.data),
1450
+ dismiss: (id) => run(
1451
+ () => dismissAdmission({ client: client2, path: { id }, throwOnError: false })
1452
+ ).then((result) => result.data)
1379
1453
  };
1380
1454
  this.telemetry = {
1381
1455
  latest: (deviceId) => run(
1382
- () => getLatestTelemetry({ client: client2, path: { id: deviceId }, throwOnError: false })
1383
- ),
1456
+ () => getLatestTelemetry({
1457
+ client: client2,
1458
+ path: { id: deviceId },
1459
+ throwOnError: false
1460
+ })
1461
+ ).then((result) => result.data),
1384
1462
  history: (deviceId, params = {}) => run(
1385
- () => getTelemetryHistory({ client: client2, path: { id: deviceId }, query: params, throwOnError: false })
1463
+ () => getTelemetryHistory({
1464
+ client: client2,
1465
+ path: { id: deviceId },
1466
+ query: params,
1467
+ throwOnError: false
1468
+ })
1386
1469
  ).then((result) => result.data),
1387
1470
  manifest: (deviceId) => run(
1388
- () => getTelemetryManifest({ client: client2, path: { id: deviceId }, throwOnError: false })
1389
- )
1471
+ () => getTelemetryManifest({
1472
+ client: client2,
1473
+ path: { id: deviceId },
1474
+ throwOnError: false
1475
+ })
1476
+ ).then((result) => result.data)
1390
1477
  };
1391
1478
  this.firmware = {
1392
1479
  upload: (params) => run(
1393
1480
  () => uploadFirmware({ client: client2, body: params, throwOnError: false })
1394
- ).then((result) => result.bundle),
1481
+ ).then((result) => result.data),
1395
1482
  deleteBundle: async (id) => {
1396
- await run(() => deleteFirmwareBundle({ client: client2, path: { id }, throwOnError: false }));
1483
+ await run(
1484
+ () => deleteFirmwareBundle({ client: client2, path: { id }, throwOnError: false })
1485
+ );
1397
1486
  },
1398
1487
  bundles: {
1399
1488
  list: (params = {}) => run(
@@ -1401,22 +1490,44 @@ var OrbitClient = class {
1401
1490
  ),
1402
1491
  iterate: (params = {}) => paginate(async (cursor) => {
1403
1492
  const page = await run(
1404
- () => listFirmwareBundles({ client: client2, query: { ...params, cursor }, throwOnError: false })
1493
+ () => listFirmwareBundles({
1494
+ client: client2,
1495
+ query: { ...params, cursor },
1496
+ throwOnError: false
1497
+ })
1405
1498
  );
1406
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1499
+ return {
1500
+ data: page.data,
1501
+ nextCursor: page.meta.nextCursor,
1502
+ hasMore: page.meta.hasMore
1503
+ };
1407
1504
  }),
1408
- get: (id) => run(() => getFirmwareBundle({ client: client2, path: { id }, throwOnError: false }))
1505
+ get: (id) => run(
1506
+ () => getFirmwareBundle({ client: client2, path: { id }, throwOnError: false })
1507
+ ).then((result) => result.data)
1409
1508
  },
1410
1509
  deployments: {
1411
1510
  trigger: (params) => run(
1412
- () => triggerFirmwareDeployment({ client: client2, body: params, throwOnError: false })
1413
- ).then((result) => result.deployments),
1511
+ () => triggerFirmwareDeployment({
1512
+ client: client2,
1513
+ body: params,
1514
+ throwOnError: false
1515
+ })
1516
+ ).then((result) => result.data),
1414
1517
  list: (params = {}) => run(
1415
- () => listFirmwareDeployments({ client: client2, query: params, throwOnError: false })
1518
+ () => listFirmwareDeployments({
1519
+ client: client2,
1520
+ query: params,
1521
+ throwOnError: false
1522
+ })
1416
1523
  ),
1417
1524
  iterate: (params = {}) => paginate(async (cursor) => {
1418
1525
  const page = await run(
1419
- () => listFirmwareDeployments({ client: client2, query: { ...params, cursor }, throwOnError: false })
1526
+ () => listFirmwareDeployments({
1527
+ client: client2,
1528
+ query: { ...params, cursor },
1529
+ throwOnError: false
1530
+ })
1420
1531
  );
1421
1532
  return {
1422
1533
  data: page.data,
@@ -1425,39 +1536,64 @@ var OrbitClient = class {
1425
1536
  };
1426
1537
  }),
1427
1538
  get: (id) => run(
1428
- () => getFirmwareDeployment({ client: client2, path: { id }, throwOnError: false })
1429
- ),
1539
+ () => getFirmwareDeployment({
1540
+ client: client2,
1541
+ path: { id },
1542
+ throwOnError: false
1543
+ })
1544
+ ).then((result) => result.data),
1430
1545
  cancel: (id, params = {}) => run(
1431
- () => cancelFirmwareDeployment({ client: client2, path: { id }, body: params, throwOnError: false })
1432
- ),
1546
+ () => cancelFirmwareDeployment({
1547
+ client: client2,
1548
+ path: { id },
1549
+ body: params,
1550
+ throwOnError: false
1551
+ })
1552
+ ).then((result) => result.data),
1433
1553
  rollback: (id, params = {}) => run(
1434
- () => rollbackFirmwareDeployment({ client: client2, path: { id }, body: params, throwOnError: false })
1435
- )
1554
+ () => rollbackFirmwareDeployment({
1555
+ client: client2,
1556
+ path: { id },
1557
+ body: params,
1558
+ throwOnError: false
1559
+ })
1560
+ ).then((result) => result.data)
1436
1561
  }
1437
1562
  };
1438
1563
  this.commands = {
1439
1564
  exec: (deviceId, command) => run(
1440
- () => execDeviceCommand({ client: client2, path: { id: deviceId }, body: command, throwOnError: false })
1441
- ),
1565
+ () => execDeviceCommand({
1566
+ client: client2,
1567
+ path: { id: deviceId },
1568
+ body: command,
1569
+ throwOnError: false
1570
+ })
1571
+ ).then((result) => result.data),
1442
1572
  get: (deviceId, invocationId) => run(
1443
1573
  () => getDeviceCommandInvocation({
1444
1574
  client: client2,
1445
1575
  path: { id: deviceId, invocationId },
1446
1576
  throwOnError: false
1447
1577
  })
1448
- ),
1578
+ ).then((result) => result.data),
1449
1579
  manifest: (deviceId) => run(
1450
- () => getDeviceCommands({ client: client2, path: { id: deviceId }, throwOnError: false })
1451
- )
1580
+ () => getDeviceCommands({
1581
+ client: client2,
1582
+ path: { id: deviceId },
1583
+ throwOnError: false
1584
+ })
1585
+ ).then((result) => result.data)
1452
1586
  };
1453
1587
  this.usb = {
1454
- list: (deviceId) => run(() => listExportable(client2, deviceId)).then(
1455
- (result) => result.exports
1456
- ),
1457
- ticket: (params) => run(() => createTicket(client2, params))
1588
+ list: (deviceId) => run(() => listExportable(client2, deviceId)).then((result) => result.data),
1589
+ ticket: (params) => run(() => createTicket(client2, params)).then(
1590
+ (result) => result.data
1591
+ )
1458
1592
  };
1459
1593
  this.terminal = {
1460
- ticket: (params) => run(() => createTicket2(client2, params))
1594
+ ticket: (params) => run(() => createTicket2(client2, params)).then(
1595
+ (result) => result.data
1596
+ )
1461
1597
  };
1462
1598
  this.webhooks = {
1463
1599
  list: (params = {}) => run(
@@ -1465,22 +1601,42 @@ var OrbitClient = class {
1465
1601
  ),
1466
1602
  iterate: (params = {}) => paginate(async (cursor) => {
1467
1603
  const page = await run(
1468
- () => listWebhooks({ client: client2, query: { ...params, cursor }, throwOnError: false })
1604
+ () => listWebhooks({
1605
+ client: client2,
1606
+ query: { ...params, cursor },
1607
+ throwOnError: false
1608
+ })
1469
1609
  );
1470
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1610
+ return {
1611
+ data: page.data,
1612
+ nextCursor: page.meta.nextCursor,
1613
+ hasMore: page.meta.hasMore
1614
+ };
1471
1615
  }),
1472
1616
  create: (params) => run(
1473
1617
  () => createWebhook({ client: client2, body: params, throwOnError: false })
1474
- ),
1475
- get: (id) => run(() => getWebhook({ client: client2, path: { id }, throwOnError: false })),
1618
+ ).then((result) => result.data),
1619
+ get: (id) => run(
1620
+ () => getWebhook({ client: client2, path: { id }, throwOnError: false })
1621
+ ).then((result) => result.data),
1476
1622
  update: (id, params) => run(
1477
- () => updateWebhook({ client: client2, path: { id }, body: params, throwOnError: false })
1478
- ),
1623
+ () => updateWebhook({
1624
+ client: client2,
1625
+ path: { id },
1626
+ body: params,
1627
+ throwOnError: false
1628
+ })
1629
+ ).then((result) => result.data),
1479
1630
  delete: async (id) => {
1480
1631
  await run(() => deleteWebhook({ client: client2, path: { id }, throwOnError: false }));
1481
1632
  },
1482
1633
  deliveries: (id, params = {}) => run(
1483
- () => listWebhookDeliveries({ client: client2, path: { id }, query: params, throwOnError: false })
1634
+ () => listWebhookDeliveries({
1635
+ client: client2,
1636
+ path: { id },
1637
+ query: params,
1638
+ throwOnError: false
1639
+ })
1484
1640
  ),
1485
1641
  iterateDeliveries: (id, params = {}) => paginate(async (cursor) => {
1486
1642
  const page = await run(
@@ -1491,7 +1647,11 @@ var OrbitClient = class {
1491
1647
  throwOnError: false
1492
1648
  })
1493
1649
  );
1494
- return { data: page.data, nextCursor: page.meta.nextCursor, hasMore: page.meta.hasMore };
1650
+ return {
1651
+ data: page.data,
1652
+ nextCursor: page.meta.nextCursor,
1653
+ hasMore: page.meta.hasMore
1654
+ };
1495
1655
  })
1496
1656
  };
1497
1657
  }
@@ -1656,6 +1816,6 @@ __export(generated_exports, {
1656
1816
  uploadFirmware: () => uploadFirmware
1657
1817
  });
1658
1818
 
1659
- export { AuthenticationError, BadRequestError, BundleExistsError, DeviceRpcError, InsufficientScopeError, NetworkError, OrbitClient, OrbitError, RateLimitError, ResourceNotFoundError, ServerError, ValidationError, WEBHOOK_REPLAY_TOLERANCE_SECONDS, decodeSample, decodeSamples, normalizeError, paginate, parseRetryAfterSeconds, parseWebhookEvent, generated_exports as raw, signWebhookPayload, verifyWebhookSignature };
1819
+ export { AuthenticationError, BadRequestError, BundleExistsError, ConflictError, DeviceRpcError, InsufficientScopeError, NetworkError, OrbitClient, OrbitError, RateLimitError, ResourceNotFoundError, ServerError, ValidationError, WEBHOOK_REPLAY_TOLERANCE_SECONDS, decodeSample, decodeSamples, normalizeError, paginate, parseRetryAfterSeconds, parseWebhookEvent, generated_exports as raw, signWebhookPayload, verifyWebhookSignature };
1660
1820
  //# sourceMappingURL=index.js.map
1661
1821
  //# sourceMappingURL=index.js.map