@hello.nrfcloud.com/nrfcloud-api-helpers 6.0.462 → 6.0.464

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 (73) hide show
  1. package/{dist → npm/src}/api/bulkOps.d.ts +2 -2
  2. package/{dist → npm/src}/api/cancelFOTAJob.d.ts +2 -2
  3. package/{dist → npm/src}/api/createFOTAJob.d.ts +2 -2
  4. package/{dist → npm/src}/api/devices.d.ts +3 -3
  5. package/npm/src/api/export.d.ts +18 -0
  6. package/{dist → npm/src}/api/getAccountInfo.d.ts +2 -2
  7. package/{dist → npm/src}/api/getCurrentMonthlyCosts.d.ts +2 -2
  8. package/{dist → npm/src}/api/getDeviceShadow.d.ts +2 -2
  9. package/{dist → npm/src}/api/getFOTABundles.d.ts +3 -3
  10. package/{dist → npm/src}/api/getFOTAJob.d.ts +3 -3
  11. package/{dist → npm/src}/api/getLocationHistory.d.ts +2 -2
  12. package/{dist → npm/src}/api/groundFix.d.ts +2 -2
  13. package/{dist → npm/src}/api/serviceToken.d.ts +2 -2
  14. package/{dist → npm/src}/api/validatedFetch.d.ts +1 -1
  15. package/npm/src/settings/export.d.ts +5 -0
  16. package/{dist → npm/src}/settings/getAllAccountsSettings.d.ts +1 -1
  17. package/package.json +19 -19
  18. package/dist/api/DeviceShadow.js +0 -23
  19. package/dist/api/DeviceShadow.spec.js +0 -45
  20. package/dist/api/FetchError.js +0 -11
  21. package/dist/api/bulkOps.js +0 -20
  22. package/dist/api/cancelFOTAJob.js +0 -14
  23. package/dist/api/createAccountDevice.js +0 -20
  24. package/dist/api/createFOTAJob.js +0 -29
  25. package/dist/api/deleteAccountDevice.js +0 -9
  26. package/dist/api/devices.js +0 -93
  27. package/dist/api/getAccountInfo.js +0 -21
  28. package/dist/api/getAccountInfo.spec.js +0 -25
  29. package/dist/api/getCurrentMonthlyCosts.js +0 -15
  30. package/dist/api/getCurrentMonthlyCosts.spec.js +0 -17
  31. package/dist/api/getDeviceShadow.js +0 -33
  32. package/dist/api/getDeviceShadow.spec.js +0 -28
  33. package/dist/api/getFOTABundle.spec.js +0 -94
  34. package/dist/api/getFOTABundles.js +0 -73
  35. package/dist/api/getFOTAJob.js +0 -81
  36. package/dist/api/getLocationHistory.js +0 -97
  37. package/dist/api/getLocationHistory.spec.js +0 -35
  38. package/dist/api/groundFix.js +0 -34
  39. package/dist/api/index.d.ts +0 -18
  40. package/dist/api/index.js +0 -18
  41. package/dist/api/serviceToken.js +0 -16
  42. package/dist/api/slashless.js +0 -1
  43. package/dist/api/slashless.spec.js +0 -6
  44. package/dist/api/test-data/account.json +0 -63
  45. package/dist/api/test-data/location.json +0 -26
  46. package/dist/api/validatedFetch.js +0 -57
  47. package/dist/api/validatedFetch.spec.js +0 -132
  48. package/dist/settings/getAllAccounts.js +0 -9
  49. package/dist/settings/getAllAccountsSettings.js +0 -14
  50. package/dist/settings/groupByAccount.js +0 -14
  51. package/dist/settings/groupByAccount.spec.js +0 -20
  52. package/dist/settings/index.d.ts +0 -5
  53. package/dist/settings/index.js +0 -5
  54. package/dist/settings/scope.js +0 -7
  55. package/dist/settings/settings.js +0 -88
  56. /package/{dist → npm/src}/api/DeviceShadow.d.ts +0 -0
  57. /package/{dist → npm/src}/api/DeviceShadow.spec.d.ts +0 -0
  58. /package/{dist → npm/src}/api/FetchError.d.ts +0 -0
  59. /package/{dist → npm/src}/api/createAccountDevice.d.ts +0 -0
  60. /package/{dist → npm/src}/api/deleteAccountDevice.d.ts +0 -0
  61. /package/{dist → npm/src}/api/getAccountInfo.spec.d.ts +0 -0
  62. /package/{dist → npm/src}/api/getCurrentMonthlyCosts.spec.d.ts +0 -0
  63. /package/{dist → npm/src}/api/getDeviceShadow.spec.d.ts +0 -0
  64. /package/{dist → npm/src}/api/getFOTABundle.spec.d.ts +0 -0
  65. /package/{dist → npm/src}/api/getLocationHistory.spec.d.ts +0 -0
  66. /package/{dist → npm/src}/api/slashless.d.ts +0 -0
  67. /package/{dist → npm/src}/api/slashless.spec.d.ts +0 -0
  68. /package/{dist → npm/src}/api/validatedFetch.spec.d.ts +0 -0
  69. /package/{dist → npm/src}/settings/getAllAccounts.d.ts +0 -0
  70. /package/{dist → npm/src}/settings/groupByAccount.d.ts +0 -0
  71. /package/{dist → npm/src}/settings/groupByAccount.spec.d.ts +0 -0
  72. /package/{dist → npm/src}/settings/scope.d.ts +0 -0
  73. /package/{dist → npm/src}/settings/settings.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import { type ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import { type ValidationError } from './validatedFetch.ts';
4
4
  /**
5
5
  * @link https://api.nrfcloud.com/v1/#tag/Bulk-Ops-Requests/operation/FetchBulkOpsRequest
6
6
  */
@@ -1,5 +1,5 @@
1
- import type { FetchError } from './FetchError.js';
2
- import type { ValidationError } from './validatedFetch.js';
1
+ import type { FetchError } from './FetchError.ts';
2
+ import type { ValidationError } from './validatedFetch.ts';
3
3
  export declare const cancelFOTAJob: ({ apiKey, endpoint, }: {
4
4
  apiKey: string;
5
5
  endpoint: URL;
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import type { ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import type { ValidationError } from './validatedFetch.ts';
4
4
  export declare const CreateFOTAJobType: import("@sinclair/typebox").TObject<{
5
5
  jobId: import("@sinclair/typebox").TString;
6
6
  }>;
@@ -1,7 +1,7 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import { DeviceShadow } from './DeviceShadow.js';
3
- import type { FetchError } from './FetchError.js';
4
- import { type ValidationError } from './validatedFetch.js';
2
+ import { DeviceShadow } from './DeviceShadow.ts';
3
+ import type { FetchError } from './FetchError.ts';
4
+ import { type ValidationError } from './validatedFetch.ts';
5
5
  declare const Devices: import("@sinclair/typebox").TObject<{
6
6
  total: import("@sinclair/typebox").TInteger;
7
7
  items: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
@@ -0,0 +1,18 @@
1
+ export * from './bulkOps.ts';
2
+ export * from './cancelFOTAJob.ts';
3
+ export * from './createAccountDevice.ts';
4
+ export * from './createFOTAJob.ts';
5
+ export * from './deleteAccountDevice.ts';
6
+ export * from './devices.ts';
7
+ export * from './DeviceShadow.ts';
8
+ export * from './FetchError.ts';
9
+ export * from './getAccountInfo.ts';
10
+ export * from './getCurrentMonthlyCosts.ts';
11
+ export * from './getDeviceShadow.ts';
12
+ export * from './getFOTABundles.ts';
13
+ export * from './getFOTAJob.ts';
14
+ export * from './getLocationHistory.ts';
15
+ export * from './groundFix.ts';
16
+ export * from './serviceToken.ts';
17
+ export * from './slashless.ts';
18
+ export * from './validatedFetch.ts';
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import type { ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import type { ValidationError } from './validatedFetch.ts';
4
4
  declare const AccountInfoType: import("@sinclair/typebox").TObject<{
5
5
  mqttEndpoint: import("@sinclair/typebox").TString;
6
6
  mqttTopicPrefix: import("@sinclair/typebox").TString;
@@ -1,5 +1,5 @@
1
- import type { FetchError } from './FetchError.js';
2
- import type { ValidationError } from './validatedFetch.js';
1
+ import type { FetchError } from './FetchError.ts';
2
+ import type { ValidationError } from './validatedFetch.ts';
3
3
  export declare const getCurrentMonthlyCosts: ({ apiKey, endpoint, }: {
4
4
  apiKey: string;
5
5
  endpoint: URL;
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import type { ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import type { ValidationError } from './validatedFetch.ts';
4
4
  declare const DeviceShadows: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
5
5
  id: import("@sinclair/typebox").TString;
6
6
  $meta: import("@sinclair/typebox").TObject<{
@@ -1,7 +1,7 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import { FwType } from './devices.js';
3
- import type { FetchError } from './FetchError.js';
4
- import type { ValidationError } from './validatedFetch.js';
2
+ import { FwType } from './devices.ts';
3
+ import type { FetchError } from './FetchError.ts';
4
+ import type { ValidationError } from './validatedFetch.ts';
5
5
  export declare const FOTABundle: import("@sinclair/typebox").TObject<{
6
6
  bundleId: import("@sinclair/typebox").TString;
7
7
  lastModified: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -1,7 +1,7 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import { FwType } from './devices.js';
3
- import type { FetchError } from './FetchError.js';
4
- import type { ValidationError } from './validatedFetch.js';
2
+ import { FwType } from './devices.ts';
3
+ import type { FetchError } from './FetchError.ts';
4
+ import type { ValidationError } from './validatedFetch.ts';
5
5
  export declare enum FOTAJobStatus {
6
6
  CREATED = "CREATED",
7
7
  IN_PROGRESS = "IN_PROGRESS",
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import type { ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import type { ValidationError } from './validatedFetch.ts';
4
4
  export declare enum LocationHistoryServiceType {
5
5
  ANCHOR = "ANCHOR",
6
6
  GNSS = "GNSS",
@@ -1,6 +1,6 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.js';
3
- import { type ValidationError } from './validatedFetch.js';
2
+ import type { FetchError } from './FetchError.ts';
3
+ import { type ValidationError } from './validatedFetch.ts';
4
4
  export declare const lat: import("@sinclair/typebox").TNumber;
5
5
  export declare const lng: import("@sinclair/typebox").TNumber;
6
6
  export declare const accuracy: import("@sinclair/typebox").TNumber;
@@ -1,5 +1,5 @@
1
- import type { FetchError } from './FetchError.js';
2
- import { type ValidationError } from './validatedFetch.js';
1
+ import type { FetchError } from './FetchError.ts';
2
+ import { type ValidationError } from './validatedFetch.ts';
3
3
  /**
4
4
  * @link https://api.nrfcloud.com/v1/#tag/Account/operation/GetServiceToken
5
5
  */
@@ -1,6 +1,6 @@
1
1
  import { type Static, type TSchema } from '@sinclair/typebox';
2
2
  import type { ValueError } from '@sinclair/typebox/compiler';
3
- import type { FetchError } from './FetchError.js';
3
+ import type { FetchError } from './FetchError.ts';
4
4
  export declare class ValidationError extends Error {
5
5
  errors: ValueError[];
6
6
  readonly isValidationError = true;
@@ -0,0 +1,5 @@
1
+ export * from './getAllAccounts.ts';
2
+ export * from './getAllAccountsSettings.ts';
3
+ export * from './groupByAccount.ts';
4
+ export * from './scope.ts';
5
+ export * from './settings.ts';
@@ -1,5 +1,5 @@
1
1
  import type { SSMClient } from '@aws-sdk/client-ssm';
2
- import { type Settings } from './settings.js';
2
+ import { type Settings } from './settings.ts';
3
3
  /**
4
4
  * Returns settings for all accounts
5
5
  */
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/nrfcloud-api-helpers",
3
- "version": "6.0.462",
3
+ "version": "6.0.464",
4
4
  "description": "Helper functions for integrating nRF Cloud APIs in AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {
7
7
  "import": {
8
- "types": "./dist/*/index.d.ts",
9
- "default": "./dist/*/index.js"
8
+ "types": "./npm/*/export.d.ts",
9
+ "default": "./npm/*/export.js"
10
10
  }
11
11
  }
12
12
  },
13
13
  "type": "module",
14
14
  "scripts": {
15
- "test": "tsx --no-warnings --test ./src/**/*.spec.ts",
15
+ "test": "node --no-warnings --experimental-transform-types --test \"!(node_modules|e2e-tests|integration-tests)/**/*.spec.ts\"",
16
16
  "prepare": "husky",
17
- "prepublishOnly": "npx tsc --noEmit false --outDir ./dist -d"
17
+ "prepublishOnly": "node --experimental-strip-types ./.npm/compile.ts && npx tsc -P ./.npm/tsconfig.npm.json --outDir ./npm"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -32,15 +32,15 @@
32
32
  "author": "Nordic Semiconductor ASA | nordicsemi.no",
33
33
  "license": "BSD-3-Clause",
34
34
  "devDependencies": {
35
- "@bifravst/eslint-config-typescript": "6.1.20",
35
+ "@bifravst/eslint-config-typescript": "6.4.4",
36
36
  "@bifravst/prettier-config": "1.1.17",
37
- "@commitlint/config-conventional": "19.8.1",
37
+ "@commitlint/config-conventional": "20.3.1",
38
+ "@swc/core": "1.15.8",
38
39
  "@types/aws-lambda": "8.10.159",
39
- "@types/node": "22.19.1",
40
- "commitlint": "19.8.1",
41
- "husky": "9.1.7",
42
- "tsmatchers": "5.0.3",
43
- "tsx": "4.20.4"
40
+ "@types/node": "25.0.9",
41
+ "@typescript/native-preview": "7.0.0-dev.20260119.1",
42
+ "commitlint": "20.3.1",
43
+ "husky": "9.1.7"
44
44
  },
45
45
  "lint-staged": {
46
46
  "*.ts": [
@@ -52,7 +52,7 @@
52
52
  ]
53
53
  },
54
54
  "engines": {
55
- "node": ">=22",
55
+ "node": ">=24",
56
56
  "npm": ">=10"
57
57
  },
58
58
  "release": {
@@ -77,17 +77,17 @@
77
77
  "access": "public"
78
78
  },
79
79
  "files": [
80
- "dist",
80
+ "npm",
81
81
  "LICENSE",
82
82
  "README.md"
83
83
  ],
84
84
  "prettier": "@bifravst/prettier-config",
85
85
  "peerDependencies": {
86
- "@aws-sdk/client-dynamodb": "^3.946.0",
87
- "@aws-sdk/client-ssm": "^3.946.0",
88
- "@aws-sdk/util-dynamodb": "^3.946.0",
89
- "@bifravst/aws-ssm-settings-helpers": "^1.2.255",
86
+ "@aws-sdk/client-dynamodb": "^3.971.0",
87
+ "@aws-sdk/client-ssm": "^3.971.0",
88
+ "@aws-sdk/util-dynamodb": "^3.971.0",
89
+ "@bifravst/aws-ssm-settings-helpers": "^1.2.257",
90
90
  "@hello.nrfcloud.com/proto": "^15.4.93",
91
- "@sinclair/typebox": "^0.34.41"
91
+ "@sinclair/typebox": "^0.34.47"
92
92
  }
93
93
  }
@@ -1,23 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- /**
3
- * @link https://api.nrfcloud.com/v1/#tag/All-Devices/operation/ListDevices
4
- */
5
- export const DeviceShadow = Type.Object({
6
- id: Type.String(),
7
- $meta: Type.Object({
8
- createdAt: Type.String({
9
- minLength: 1,
10
- examples: ['2019-08-24T14:15:22Z'],
11
- }),
12
- updatedAt: Type.Optional(Type.String({
13
- minLength: 1,
14
- examples: ['2019-08-24T14:15:22Z'],
15
- })),
16
- }),
17
- state: Type.Optional(Type.Object({
18
- reported: Type.Optional(Type.Record(Type.String({ minLength: 1 }), Type.Any())),
19
- desired: Type.Optional(Type.Record(Type.String({ minLength: 1 }), Type.Any())),
20
- version: Type.Number(),
21
- metadata: Type.Record(Type.String({ minLength: 1 }), Type.Any()),
22
- })),
23
- });
@@ -1,45 +0,0 @@
1
- import { validateWithTypeBox } from '@hello.nrfcloud.com/proto';
2
- import assert from 'node:assert/strict';
3
- import { describe, it } from 'node:test';
4
- import { DeviceShadow } from './DeviceShadow.js';
5
- void describe('DeviceShadow type', () => {
6
- void it('should document the device shadow object', () => {
7
- const res = validateWithTypeBox(DeviceShadow)({
8
- id: 'some-device',
9
- state: {
10
- version: 42,
11
- reported: {
12
- dev: {
13
- v: {
14
- imei: '358299840016535',
15
- iccid: '89450421180216254864',
16
- modV: 'mfw_nrf91x1_2.0.0-77.beta',
17
- brdV: 'thingy91x_nrf9161',
18
- appV: '0.0.0-development',
19
- },
20
- ts: 1697102116821,
21
- },
22
- },
23
- metadata: {
24
- dev: {
25
- v: {
26
- imei: { timestamp: 1697102116821 },
27
- iccid: { timestamp: 1697102116821 },
28
- modV: { timestamp: 1697102116821 },
29
- brdV: { timestamp: 1697102116821 },
30
- appV: { timestamp: 1697102116821 },
31
- },
32
- ts: {
33
- timestamp: 1697102116821,
34
- },
35
- },
36
- },
37
- },
38
- $meta: {
39
- updatedAt: '2023-04-20T07:29:46.467Z',
40
- createdAt: '2023-04-19T11:49:07.370Z',
41
- },
42
- });
43
- assert.equal('errors' in res, false);
44
- });
45
- });
@@ -1,11 +0,0 @@
1
- export class FetchError extends Error {
2
- statusCode;
3
- constructor(statusCode, message) {
4
- super(message);
5
- this.statusCode = statusCode;
6
- this.name = 'FetchError';
7
- }
8
- }
9
- export const toFetchError = async (response) => new FetchError(response.status, parseInt(response.headers.get('content-length') ?? '0', 10) > 0
10
- ? await response.text()
11
- : 'No content returned from server');
@@ -1,20 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { validatedFetch } from './validatedFetch.js';
3
- /**
4
- * @link https://api.nrfcloud.com/v1/#tag/Bulk-Ops-Requests/operation/FetchBulkOpsRequest
5
- */
6
- export const BulkOpsRequestType = Type.Object({
7
- bulkOpsRequestId: Type.String(), // e.g. '01EZZJVDQJPWT7V4FWNVDHNMM5'
8
- status: Type.Union([
9
- Type.Literal('PENDING'),
10
- Type.Literal('IN_PROGRESS'),
11
- Type.Literal('FAILED'),
12
- Type.Literal('SUCCEEDED'),
13
- ]),
14
- });
15
- export const bulkOpsRequests = ({ apiKey, endpoint, }, fetchImplementation) => async (bulkOpsId) => {
16
- const vf = validatedFetch({ endpoint, apiKey }, fetchImplementation);
17
- return vf({
18
- resource: `bulk-ops-requests/${encodeURIComponent(bulkOpsId)}`,
19
- }, BulkOpsRequestType);
20
- };
@@ -1,14 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { validatedFetch } from './validatedFetch.js';
3
- export const cancelFOTAJob = ({ apiKey, endpoint, }, fetchImplementation) => async (jobId) => {
4
- const maybeSuccess = await validatedFetch({
5
- endpoint,
6
- apiKey,
7
- }, fetchImplementation)({
8
- resource: `fota-jobs/${jobId}/cancel`,
9
- method: 'PUT',
10
- }, Type.Any());
11
- if ('error' in maybeSuccess)
12
- return maybeSuccess;
13
- return { success: true };
14
- };
@@ -1,20 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { validatedFetch } from './validatedFetch.js';
3
- /**
4
- * @link https://api.nrfcloud.com/v1/#tag/Account-Devices/operation/CreateAccountDevice
5
- */
6
- const CertificateCredentials = Type.Object({
7
- clientCert: Type.String(),
8
- privateKey: Type.String(),
9
- });
10
- export const createAccountDevice = async ({ apiKey, endpoint, }) => {
11
- const vf = validatedFetch({ endpoint, apiKey });
12
- const maybeResult = await vf({ resource: 'devices/account', method: 'POST' }, CertificateCredentials);
13
- if ('error' in maybeResult) {
14
- throw maybeResult.error;
15
- }
16
- return {
17
- clientCert: maybeResult.result.clientCert,
18
- privateKey: maybeResult.result.privateKey,
19
- };
20
- };
@@ -1,29 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { JSONPayload, validatedFetch } from './validatedFetch.js';
3
- export const CreateFOTAJobType = Type.Object({
4
- jobId: Type.String({
5
- minLength: 1,
6
- title: 'ID',
7
- description: 'Universally unique identifier',
8
- examples: ['bc631093-7f7c-4c1b-aa63-a68c759bcd5c'],
9
- }),
10
- }, {
11
- title: 'FOTA Job',
12
- description: 'See https://api.nrfcloud.com/#tag/FOTA-Jobs/operation/CreateFOTAJob',
13
- });
14
- export const createFOTAJob = ({ apiKey, endpoint, }, fetchImplementation) => async ({ deviceId, bundleId, }) => {
15
- const maybeJob = await validatedFetch({
16
- endpoint,
17
- apiKey,
18
- }, fetchImplementation)({
19
- resource: 'fota-jobs',
20
- payload: JSONPayload({
21
- bundleId,
22
- autoApply: true,
23
- deviceIdentifiers: [deviceId],
24
- }),
25
- }, CreateFOTAJobType);
26
- if ('error' in maybeJob)
27
- return maybeJob;
28
- return maybeJob;
29
- };
@@ -1,9 +0,0 @@
1
- import { slashless } from './slashless.js';
2
- export const deleteAccountDevice = async ({ apiKey, endpoint, }) => {
3
- await fetch(`${slashless(endpoint)}/v1/devices/account`, {
4
- method: 'DELETE',
5
- headers: {
6
- Authorization: `Bearer ${apiKey}`,
7
- },
8
- });
9
- };
@@ -1,93 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { DeviceShadow } from './DeviceShadow.js';
3
- import { toFetchError } from './FetchError.js';
4
- import { slashless } from './slashless.js';
5
- import { validatedFetch } from './validatedFetch.js';
6
- const Page = (Item) => Type.Object({
7
- total: Type.Integer(),
8
- items: Type.Array(Item),
9
- });
10
- const Devices = Page(DeviceShadow);
11
- /**
12
- * @link https://api.nrfcloud.com/v1/#tag/IP-Devices/operation/ProvisionDevices
13
- */
14
- const ProvisionDevice = Type.Object({
15
- bulkOpsRequestId: Type.String(),
16
- });
17
- /**
18
- * firmware types supported by a device for FOTA
19
- */
20
- export var FwType;
21
- (function (FwType) {
22
- FwType["APP"] = "APP";
23
- FwType["MODEM"] = "MODEM";
24
- FwType["BOOT"] = "BOOT";
25
- FwType["SOFTDEVICE"] = "SOFTDEVICE";
26
- FwType["BOOTLOADER"] = "BOOTLOADER";
27
- FwType["MDM_FULL"] = "MDM_FULL";
28
- })(FwType || (FwType = {}));
29
- export const devices = ({ endpoint, apiKey, }, fetchImplementation) => {
30
- const headers = {
31
- Authorization: `Bearer ${apiKey}`,
32
- Accept: 'application/json; charset=utf-8',
33
- };
34
- const vf = validatedFetch({ endpoint, apiKey }, fetchImplementation);
35
- return {
36
- // FIXME: implement pagination
37
- list: async () => vf({
38
- resource: `devices?${new URLSearchParams({
39
- pageLimit: '100',
40
- deviceNameFuzzy: 'oob-',
41
- }).toString()}`,
42
- }, Devices),
43
- get: async (id) => vf({ resource: `devices/${encodeURIComponent(id)}` }, DeviceShadow),
44
- updateState: async (id, state) => fetch(`${slashless(endpoint)}/v1/devices/${encodeURIComponent(id)}/state`, {
45
- headers: {
46
- ...headers,
47
- 'Content-Type': 'application/json',
48
- },
49
- method: 'PATCH',
50
- body: JSON.stringify(state),
51
- }).then(async (res) => {
52
- if (res.status >= 400)
53
- return { error: await toFetchError(res) };
54
- return { success: true };
55
- }),
56
- register: async (devices) => {
57
- const bulkRegistrationPayload = devices
58
- .map(({ deviceId, subType, tags, fwTypes, certPem }) => {
59
- const deviceFwTypes = fwTypes ?? Object.values(FwType);
60
- return [
61
- [
62
- deviceId,
63
- subType ?? '',
64
- (tags ?? []).join('|'),
65
- deviceFwTypes.join('|'),
66
- `"${certPem}"`,
67
- ],
68
- ];
69
- })
70
- .map((cols) => cols.join(','))
71
- .join('\n');
72
- const maybeResult = await vf({
73
- resource: 'devices',
74
- payload: {
75
- body: bulkRegistrationPayload,
76
- type: 'application/octet-stream',
77
- },
78
- }, ProvisionDevice);
79
- if ('error' in maybeResult)
80
- return maybeResult;
81
- return { bulkOpsRequestId: maybeResult.result.bulkOpsRequestId };
82
- },
83
- remove: async (deviceId) => {
84
- const maybeResult = await vf({
85
- method: 'DELETE',
86
- resource: `devices/${deviceId}`,
87
- }, Type.Any());
88
- if ('error' in maybeResult)
89
- return maybeResult;
90
- return { success: true };
91
- },
92
- };
93
- };
@@ -1,21 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { validatedFetch } from './validatedFetch.js';
3
- const AccountInfoType = Type.Object({
4
- mqttEndpoint: Type.String(), // e.g. 'mqtt.nrfcloud.com'
5
- mqttTopicPrefix: Type.String(), // e.g. 'prod/a0673464-e4e1-4b87-bffd-6941a012067b/',
6
- team: Type.Object({
7
- tenantId: Type.String(), // e.g. 'bbfe6b73-a46a-43ad-94bd-8e4b4a7847ce',
8
- name: Type.String(), // e.g. 'hello.nrfcloud.com'
9
- }),
10
- });
11
- export const getAccountInfo = async ({ apiKey, endpoint, }, fetchImplementation) => {
12
- const maybeAccount = await validatedFetch({
13
- endpoint,
14
- apiKey,
15
- }, fetchImplementation)({
16
- resource: 'account',
17
- }, AccountInfoType);
18
- if ('error' in maybeAccount)
19
- return maybeAccount;
20
- return maybeAccount;
21
- };
@@ -1,25 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { describe, it } from 'node:test';
3
- import { check, objectMatching } from 'tsmatchers';
4
- import { getAccountInfo } from './getAccountInfo.js';
5
- import APIresponse from './test-data/account.json' assert { type: 'json' };
6
- void describe('getAccountInfo()', () => {
7
- void it('return the account info', async () => {
8
- const res = await getAccountInfo({
9
- endpoint: new URL('https://example.com/'),
10
- apiKey: 'some-key',
11
- }, () => Promise.resolve({
12
- ok: true,
13
- json: async () => Promise.resolve(APIresponse),
14
- }));
15
- assert.equal('error' in res, false);
16
- check('result' in res && res.result).is(objectMatching({
17
- mqttEndpoint: 'mqtt.nrfcloud.com',
18
- mqttTopicPrefix: 'prod/b8b26bc5-2814-4063-b4fa-83ecddb2fec7/',
19
- team: {
20
- tenantId: 'b8b26bc5-2814-4063-b4fa-83ecddb2fec7',
21
- name: 'XXX',
22
- },
23
- }));
24
- });
25
- });
@@ -1,15 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { validatedFetch } from './validatedFetch.js';
3
- export const getCurrentMonthlyCosts = ({ apiKey, endpoint, }, fetchImplementation) => async () => {
4
- const vf = validatedFetch({ endpoint, apiKey }, fetchImplementation);
5
- const maybeResult = await vf({ resource: 'account' }, Type.Object({
6
- plan: Type.Object({
7
- currentMonthTotalCost: Type.Number(), // e.g. 2.73
8
- }),
9
- }));
10
- if ('error' in maybeResult) {
11
- return maybeResult;
12
- }
13
- const currentMonthTotalCost = maybeResult.result.plan.currentMonthTotalCost;
14
- return { currentMonthTotalCost };
15
- };
@@ -1,17 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { describe, it } from 'node:test';
3
- import { getCurrentMonthlyCosts } from './getCurrentMonthlyCosts.js';
4
- import APIresponse from './test-data/account.json' assert { type: 'json' };
5
- void describe('getCurrentMonthlyCosts()', () => {
6
- void it("return the current month's total cost for an account", async () => {
7
- const res = await getCurrentMonthlyCosts({
8
- endpoint: new URL('https://example.com/'),
9
- apiKey: 'some-key',
10
- }, () => Promise.resolve({
11
- ok: true,
12
- json: async () => Promise.resolve(APIresponse),
13
- }))();
14
- assert.equal('error' in res, false);
15
- assert.equal('currentMonthTotalCost' in res && res.currentMonthTotalCost, 24.03);
16
- });
17
- });
@@ -1,33 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { DeviceShadow } from './DeviceShadow.js';
3
- import { validatedFetch } from './validatedFetch.js';
4
- const DeviceShadows = Type.Array(DeviceShadow);
5
- /**
6
- * @see https://api.nrfcloud.com/v1#tag/All-Devices/operation/ListDevices
7
- */
8
- const ListDevices = Type.Object({
9
- items: DeviceShadows,
10
- total: Type.Optional(Type.Number({ minimum: 0 })),
11
- pageNextToken: Type.Optional(Type.String({ minLength: 1 })),
12
- });
13
- export const getDeviceShadow = ({ endpoint, apiKey, }, fetchImplementation) => {
14
- const vf = validatedFetch({ endpoint, apiKey }, fetchImplementation);
15
- return async (devices) => {
16
- const params = {
17
- includeState: true,
18
- includeStateMeta: true,
19
- pageLimit: 100,
20
- deviceIds: devices.join(','),
21
- };
22
- const queryString = Object.entries(params)
23
- .sort((a, b) => a[0].localeCompare(b[0]))
24
- .map((kv) => kv.map(encodeURIComponent).join('='))
25
- .join('&');
26
- const url = `devices?${queryString}`;
27
- const maybeResult = await vf({ resource: url }, ListDevices);
28
- if ('error' in maybeResult) {
29
- return { error: maybeResult.error };
30
- }
31
- return { shadows: maybeResult.result.items };
32
- };
33
- };