@hello.nrfcloud.com/nrfcloud-api-helpers 6.0.463 → 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 +18 -18
  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,132 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import assert from 'node:assert/strict';
3
- import { describe, it, mock } from 'node:test';
4
- import { FetchError } from './FetchError.js';
5
- import { JSONPayload, validatedFetch } from './validatedFetch.js';
6
- void describe('validatedFetch()', () => {
7
- void it('should call an nRF Cloud API endpoint and validate the response', async () => {
8
- const mockFetch = mock.fn(() => ({
9
- ok: true,
10
- json: async () => Promise.resolve({
11
- foo: 'bar',
12
- }),
13
- }));
14
- const vf = validatedFetch({
15
- endpoint: new URL('https://example.com/'),
16
- apiKey: 'some-key',
17
- }, mockFetch);
18
- const schema = Type.Object({ foo: Type.Literal('bar') });
19
- const res = await vf({ resource: 'foo' }, schema);
20
- assert.equal('error' in res, false);
21
- assert.equal('result' in res, true);
22
- assert.deepEqual('result' in res && res.result, { foo: 'bar' });
23
- assert.deepEqual(mockFetch.mock.calls[0]?.arguments, [
24
- `https://example.com/v1/foo`,
25
- {
26
- headers: {
27
- Accept: 'application/json; charset=utf-8',
28
- Authorization: 'Bearer some-key',
29
- },
30
- },
31
- ]);
32
- });
33
- void it('should return the fetch exception', async () => {
34
- const err = new Error(`Some error`);
35
- const vf = validatedFetch({
36
- endpoint: new URL('https://example.com/'),
37
- apiKey: 'some-key',
38
- }, () => Promise.reject(err));
39
- assert.deepEqual(await vf({ resource: 'some-resource' }, Type.Object({})), {
40
- error: err,
41
- });
42
- });
43
- void it('should send POST request if body is given', async () => {
44
- const mockFetch = mock.fn(() => ({
45
- ok: true,
46
- json: async () => Promise.resolve({}),
47
- }));
48
- const vf = validatedFetch({
49
- endpoint: new URL('https://example.com/'),
50
- apiKey: 'some-key',
51
- }, mockFetch);
52
- await vf({
53
- resource: 'foo',
54
- payload: {
55
- type: 'application/octet-stream',
56
- body: 'some data',
57
- },
58
- }, Type.Object({}));
59
- assert.deepEqual(mockFetch.mock.calls[0]?.arguments, [
60
- `https://example.com/v1/foo`,
61
- {
62
- method: 'POST',
63
- body: 'some data',
64
- headers: {
65
- Accept: 'application/json; charset=utf-8',
66
- Authorization: 'Bearer some-key',
67
- 'Content-Type': 'application/octet-stream',
68
- },
69
- },
70
- ]);
71
- });
72
- void it('should allow to specify the method', async () => {
73
- const mockFetch = mock.fn(() => ({
74
- ok: true,
75
- json: async () => Promise.resolve({}),
76
- }));
77
- const vf = validatedFetch({
78
- endpoint: new URL('https://example.com/'),
79
- apiKey: 'some-key',
80
- }, mockFetch);
81
- await vf({
82
- resource: 'foo',
83
- method: 'POST',
84
- }, Type.Object({}));
85
- assert.deepEqual(mockFetch.mock.calls[0]?.arguments, [
86
- `https://example.com/v1/foo`,
87
- {
88
- method: 'POST',
89
- headers: {
90
- Accept: 'application/json; charset=utf-8',
91
- Authorization: 'Bearer some-key',
92
- },
93
- },
94
- ]);
95
- });
96
- void it('should return an error if the response is not OK', async () => {
97
- const mockFetch = mock.fn(() => ({
98
- ok: false,
99
- status: 400,
100
- text: async () => Promise.resolve('Bad Request'),
101
- headers: new Map([[`content-length`, 'Bad Request'.length.toString()]]),
102
- }));
103
- const vf = validatedFetch({
104
- endpoint: new URL('https://example.com/'),
105
- apiKey: 'some-key',
106
- }, mockFetch);
107
- const res = await vf({ resource: 'foo' }, Type.Object({}));
108
- assert.equal('error' in res, true);
109
- assert.equal('result' in res, false);
110
- assert.deepEqual('error' in res && res.error, new FetchError(400, 'Bad Request'));
111
- });
112
- void it('should return undefined if response is empty', async () => {
113
- const mockFetch = mock.fn(() => ({
114
- ok: true,
115
- status: 204,
116
- text: async () => '',
117
- headers: new Map([[`content-length`, '0']]),
118
- }));
119
- const vf = validatedFetch({
120
- endpoint: new URL('https://example.com/'),
121
- apiKey: 'some-key',
122
- }, mockFetch);
123
- const res = await vf({ resource: 'foo' }, Type.Undefined());
124
- assert.deepEqual('result' in res && res.result, undefined, 'Result should be undefined');
125
- });
126
- });
127
- void describe('JSONPayload()', () => {
128
- void it('should convert a an object to a payload definition to be used in validatedFetch', () => assert.deepEqual(JSONPayload({ foo: 'bar' }), {
129
- type: 'application/json',
130
- body: JSON.stringify({ foo: 'bar' }),
131
- }));
132
- });
@@ -1,9 +0,0 @@
1
- import { get } from '@bifravst/aws-ssm-settings-helpers';
2
- import { NRFCLOUD_ACCOUNT_SCOPE } from './scope.js';
3
- export const getAllAccounts = async ({ ssm, stackName, }) => [
4
- ...getAccountsFromAllSettings(await get(ssm)({
5
- stackName,
6
- scope: NRFCLOUD_ACCOUNT_SCOPE,
7
- })()),
8
- ];
9
- export const getAccountsFromAllSettings = (settings) => new Set(Object.keys(settings).map((key) => key.split('/')[0]));
@@ -1,14 +0,0 @@
1
- import { get } from '@bifravst/aws-ssm-settings-helpers';
2
- import { groupByAccount } from './groupByAccount.js';
3
- import { NRFCLOUD_ACCOUNT_SCOPE } from './scope.js';
4
- import { validateSettings } from './settings.js';
5
- /**
6
- * Returns settings for all accounts
7
- */
8
- export const getAllAccountsSettings = async ({ ssm, stackName, }) => Object.entries(groupByAccount(await get(ssm)({
9
- stackName,
10
- scope: NRFCLOUD_ACCOUNT_SCOPE,
11
- })())).reduce((allSettings, [account, settings]) => ({
12
- ...allSettings,
13
- [account]: validateSettings(settings),
14
- }), {});
@@ -1,14 +0,0 @@
1
- import { getAccountsFromAllSettings } from './getAllAccounts.js';
2
- export const groupByAccount = (allSettings) => {
3
- const accounts = getAccountsFromAllSettings(allSettings);
4
- return [...accounts].reduce((allAccountSettings, account) => ({
5
- ...allAccountSettings,
6
- [account]: Object.entries(allSettings)
7
- .filter(([k]) => k.startsWith(`${account}/`))
8
- .map(([k, v]) => [
9
- k.replace(new RegExp(`^${account}/`), ''),
10
- v,
11
- ])
12
- .reduce((s, [k, v]) => ({ ...s, [k]: v }), {}),
13
- }), {});
14
- };
@@ -1,20 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { describe, it } from 'node:test';
3
- import { groupByAccount } from './groupByAccount.js';
4
- void describe('groupByAccount()', () => {
5
- void it('should group settings by account', () => assert.deepEqual(groupByAccount({
6
- 'elite/accountDeviceClientId': 'account-4db55163-7593-4d63-9679-d16fbc2d464f',
7
- 'elite/healthCheckModel': 'PCA20035+solar',
8
- 'acme/mqttEndpoint': 'mqtt.nrfcloud.com',
9
- 'acme/teamId': 'f4ba6ede-7867-43eb-a495-7e0de108f52e',
10
- }), {
11
- acme: {
12
- mqttEndpoint: 'mqtt.nrfcloud.com',
13
- teamId: 'f4ba6ede-7867-43eb-a495-7e0de108f52e',
14
- },
15
- elite: {
16
- accountDeviceClientId: 'account-4db55163-7593-4d63-9679-d16fbc2d464f',
17
- healthCheckModel: 'PCA20035+solar',
18
- },
19
- }));
20
- });
@@ -1,5 +0,0 @@
1
- export * from './getAllAccounts.js';
2
- export * from './getAllAccountsSettings.js';
3
- export * from './groupByAccount.js';
4
- export * from './scope.js';
5
- export * from './settings.js';
@@ -1,5 +0,0 @@
1
- export * from './getAllAccounts.js';
2
- export * from './getAllAccountsSettings.js';
3
- export * from './groupByAccount.js';
4
- export * from './scope.js';
5
- export * from './settings.js';
@@ -1,7 +0,0 @@
1
- export const NRFCLOUD_ACCOUNT_SCOPE = 'thirdParty';
2
- const nameRx = /^[a-zA-Z0-9_.-]+$/;
3
- export const nrfCloudAccount = (account) => {
4
- if (!nameRx.test(account))
5
- throw new Error(`Invalid account name: ${account}`);
6
- return account;
7
- };
@@ -1,88 +0,0 @@
1
- import { remove as deleteSSMSettings, get as getSSMSettings, put as putSSMSettings, } from '@bifravst/aws-ssm-settings-helpers';
2
- import { NRFCLOUD_ACCOUNT_SCOPE, nrfCloudAccount } from './scope.js';
3
- export const defaultApiEndpoint = new URL('https://api.nrfcloud.com');
4
- export const defaultCoAPEndpoint = new URL('coaps://coap.nrfcloud.com');
5
- export const getSettings = ({ ssm, stackName, account, }) => {
6
- const settingsReader = getSSMSettings(ssm)({
7
- stackName,
8
- scope: NRFCLOUD_ACCOUNT_SCOPE,
9
- context: nrfCloudAccount(account),
10
- });
11
- return async () => validateSettings(await settingsReader());
12
- };
13
- export const getAPISettings = ({ ssm, stackName, account, }) => {
14
- const settingsReader = getSSMSettings(ssm)({
15
- stackName,
16
- scope: NRFCLOUD_ACCOUNT_SCOPE,
17
- context: nrfCloudAccount(account),
18
- });
19
- return async () => {
20
- const p = await settingsReader();
21
- const { apiEndpoint, apiKey } = p;
22
- if (apiKey === undefined)
23
- throw new Error(`No nRF Cloud API key configured!`);
24
- return {
25
- apiEndpoint: apiEndpoint === undefined ? defaultApiEndpoint : new URL(apiEndpoint),
26
- apiKey,
27
- };
28
- };
29
- };
30
- export const putSettings = ({ ssm, stackName, account, }) => {
31
- const settingsWriter = putSSMSettings(ssm)({
32
- stackName,
33
- scope: NRFCLOUD_ACCOUNT_SCOPE,
34
- context: nrfCloudAccount(account),
35
- });
36
- return async (settings) => {
37
- await Promise.all(Object.entries(settings).map(async ([k, v]) => settingsWriter({
38
- property: k,
39
- value: v.toString(),
40
- })));
41
- };
42
- };
43
- export const putSetting = ({ ssm, stackName, account, }) => {
44
- const settingsWriter = putSSMSettings(ssm)({
45
- stackName,
46
- scope: NRFCLOUD_ACCOUNT_SCOPE,
47
- context: nrfCloudAccount(account),
48
- });
49
- return async (property, value, deleteBeforeUpdate) => settingsWriter({
50
- property,
51
- value,
52
- deleteBeforeUpdate,
53
- });
54
- };
55
- export const deleteSettings = ({ ssm, stackName, account, }) => {
56
- const settingsDeleter = deleteSSMSettings(ssm)({
57
- stackName,
58
- scope: NRFCLOUD_ACCOUNT_SCOPE,
59
- context: nrfCloudAccount(account),
60
- });
61
- return async (property) => settingsDeleter({ property });
62
- };
63
- export const validateSettings = (p) => {
64
- const { apiEndpoint, apiKey, accountDeviceClientCert, accountDevicePrivateKey, mqttEndpoint, accountDeviceClientId, mqttTopicPrefix, coapEndpoint, coapPort, } = p;
65
- if (apiKey === undefined)
66
- throw new Error(`No nRF Cloud API key configured!`);
67
- if (accountDeviceClientCert === undefined)
68
- throw new Error(`No nRF Cloud account device clientCert configured!`);
69
- if (accountDevicePrivateKey === undefined)
70
- throw new Error(`No nRF Cloud account device privateKey configured!`);
71
- if (accountDeviceClientId === undefined)
72
- throw new Error(`No nRF Cloud Account Device client ID configured!`);
73
- if (mqttTopicPrefix === undefined)
74
- throw new Error(`No nRF Cloud MQTT topic prefix configured!`);
75
- if (mqttEndpoint === undefined)
76
- throw new Error(`No nRF Cloud MQTT endpoint configured!`);
77
- return {
78
- apiEndpoint: apiEndpoint === undefined ? defaultApiEndpoint : new URL(apiEndpoint),
79
- apiKey,
80
- mqttEndpoint,
81
- accountDeviceClientCert,
82
- accountDevicePrivateKey,
83
- accountDeviceClientId,
84
- mqttTopicPrefix,
85
- coapEndpoint: coapEndpoint === undefined ? defaultCoAPEndpoint : new URL(coapEndpoint),
86
- coapPort: parseInt(coapPort ?? `5684`, 10),
87
- };
88
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes