@hello.nrfcloud.com/nrfcloud-api-helpers 6.0.466 → 6.0.467

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 (41) hide show
  1. package/npm/src/api/DeviceShadow.js +32 -0
  2. package/npm/src/api/FetchError.js +9 -0
  3. package/npm/src/api/bulkOps.d.ts +5 -3
  4. package/npm/src/api/bulkOps.js +22 -0
  5. package/npm/src/api/cancelFOTAJob.d.ts +1 -1
  6. package/npm/src/api/cancelFOTAJob.js +15 -0
  7. package/npm/src/api/createAccountDevice.d.ts +4 -10
  8. package/npm/src/api/createAccountDevice.js +25 -0
  9. package/npm/src/api/createFOTAJob.d.ts +4 -3
  10. package/npm/src/api/createFOTAJob.js +32 -0
  11. package/npm/src/api/deleteAccountDevice.js +9 -0
  12. package/npm/src/api/devices.d.ts +47 -27
  13. package/npm/src/api/devices.js +98 -0
  14. package/npm/src/api/export.js +18 -0
  15. package/npm/src/api/getAccountInfo.d.ts +9 -2
  16. package/npm/src/api/getAccountInfo.js +20 -0
  17. package/npm/src/api/getCurrentMonthlyCosts.d.ts +1 -1
  18. package/npm/src/api/getCurrentMonthlyCosts.js +22 -0
  19. package/npm/src/api/getDeviceShadow.d.ts +21 -18
  20. package/npm/src/api/getDeviceShadow.js +42 -0
  21. package/npm/src/api/getFOTABundles.d.ts +11 -3
  22. package/npm/src/api/getFOTABundles.js +101 -0
  23. package/npm/src/api/getFOTAJob.d.ts +23 -3
  24. package/npm/src/api/getFOTAJob.js +114 -0
  25. package/npm/src/api/getLocationHistory.d.ts +24 -5
  26. package/npm/src/api/getLocationHistory.js +118 -0
  27. package/npm/src/api/groundFix.d.ts +8 -4
  28. package/npm/src/api/groundFix.js +38 -0
  29. package/npm/src/api/serviceToken.d.ts +2 -2
  30. package/npm/src/api/serviceToken.js +20 -0
  31. package/npm/src/api/slashless.js +1 -0
  32. package/npm/src/api/validatedFetch.d.ts +6 -4
  33. package/npm/src/api/validatedFetch.js +58 -0
  34. package/npm/src/settings/export.js +5 -0
  35. package/npm/src/settings/getAllAccounts.js +9 -0
  36. package/npm/src/settings/getAllAccountsSettings.js +13 -0
  37. package/npm/src/settings/groupByAccount.js +16 -0
  38. package/npm/src/settings/scope.js +6 -0
  39. package/npm/src/settings/settings.d.ts +7 -13
  40. package/npm/src/settings/settings.js +83 -0
  41. package/package.json +2 -2
@@ -16,35 +16,29 @@ export declare const getSettings: ({ ssm, stackName, account, }: {
16
16
  ssm: SSMClient;
17
17
  stackName: string;
18
18
  account: string;
19
- }) => (() => Promise<Settings>);
19
+ }) => () => Promise<Settings>;
20
20
  export declare const getAPISettings: ({ ssm, stackName, account, }: {
21
21
  ssm: SSMClient;
22
22
  stackName: string;
23
23
  account: string;
24
- }) => (() => Promise<Pick<Settings, "apiKey" | "apiEndpoint">>);
24
+ }) => () => Promise<Pick<Settings, "apiEndpoint" | "apiKey">>;
25
25
  export declare const putSettings: ({ ssm, stackName, account, }: {
26
26
  ssm: SSMClient;
27
27
  stackName: string;
28
28
  account: string;
29
- }) => ((settings: Partial<Settings>) => Promise<void>);
29
+ }) => (settings: Partial<Settings>) => Promise<void>;
30
30
  export declare const putSetting: ({ ssm, stackName, account, }: {
31
31
  ssm: SSMClient;
32
32
  stackName: string;
33
33
  account: string;
34
- }) => ((property: keyof Settings, value: string, deleteBeforeUpdate: boolean) => ReturnType<({ property, value, deleteBeforeUpdate, }: {
35
- property: string;
36
- value: string;
37
- deleteBeforeUpdate?: boolean;
38
- }) => Promise<{
34
+ }) => (property: keyof Settings, value: string, deleteBeforeUpdate: boolean) => Promise<{
39
35
  name: string;
40
- }>>);
36
+ }>;
41
37
  export declare const deleteSettings: ({ ssm, stackName, account, }: {
42
38
  ssm: SSMClient;
43
39
  stackName: string;
44
40
  account: string;
45
- }) => ((property: string) => ReturnType<({ property }: {
46
- property: string;
47
- }) => Promise<{
41
+ }) => (property: string) => Promise<{
48
42
  name: string;
49
- }>>);
43
+ }>;
50
44
  export declare const validateSettings: (p: Record<string, string>) => Settings;
@@ -0,0 +1,83 @@
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) throw new Error(`No nRF Cloud API key configured!`);
23
+ return {
24
+ apiEndpoint: apiEndpoint === undefined ? defaultApiEndpoint : new URL(apiEndpoint),
25
+ apiKey
26
+ };
27
+ };
28
+ };
29
+ export const putSettings = ({ ssm, stackName, account })=>{
30
+ const settingsWriter = putSSMSettings(ssm)({
31
+ stackName,
32
+ scope: NRFCLOUD_ACCOUNT_SCOPE,
33
+ context: nrfCloudAccount(account)
34
+ });
35
+ return async (settings)=>{
36
+ await Promise.all(Object.entries(settings).map(async ([k, v])=>settingsWriter({
37
+ property: k,
38
+ value: v.toString()
39
+ })));
40
+ };
41
+ };
42
+ export const putSetting = ({ ssm, stackName, account })=>{
43
+ const settingsWriter = putSSMSettings(ssm)({
44
+ stackName,
45
+ scope: NRFCLOUD_ACCOUNT_SCOPE,
46
+ context: nrfCloudAccount(account)
47
+ });
48
+ return async (property, value, deleteBeforeUpdate)=>settingsWriter({
49
+ property,
50
+ value,
51
+ deleteBeforeUpdate
52
+ });
53
+ };
54
+ export const deleteSettings = ({ ssm, stackName, account })=>{
55
+ const settingsDeleter = deleteSSMSettings(ssm)({
56
+ stackName,
57
+ scope: NRFCLOUD_ACCOUNT_SCOPE,
58
+ context: nrfCloudAccount(account)
59
+ });
60
+ return async (property)=>settingsDeleter({
61
+ property
62
+ });
63
+ };
64
+ export const validateSettings = (p)=>{
65
+ const { apiEndpoint, apiKey, accountDeviceClientCert, accountDevicePrivateKey, mqttEndpoint, accountDeviceClientId, mqttTopicPrefix, coapEndpoint, coapPort } = p;
66
+ if (apiKey === undefined) throw new Error(`No nRF Cloud API key configured!`);
67
+ if (accountDeviceClientCert === undefined) throw new Error(`No nRF Cloud account device clientCert configured!`);
68
+ if (accountDevicePrivateKey === undefined) throw new Error(`No nRF Cloud account device privateKey configured!`);
69
+ if (accountDeviceClientId === undefined) throw new Error(`No nRF Cloud Account Device client ID configured!`);
70
+ if (mqttTopicPrefix === undefined) throw new Error(`No nRF Cloud MQTT topic prefix configured!`);
71
+ if (mqttEndpoint === undefined) throw new Error(`No nRF Cloud MQTT endpoint configured!`);
72
+ return {
73
+ apiEndpoint: apiEndpoint === undefined ? defaultApiEndpoint : new URL(apiEndpoint),
74
+ apiKey,
75
+ mqttEndpoint,
76
+ accountDeviceClientCert,
77
+ accountDevicePrivateKey,
78
+ accountDeviceClientId,
79
+ mqttTopicPrefix,
80
+ coapEndpoint: coapEndpoint === undefined ? defaultCoAPEndpoint : new URL(coapEndpoint),
81
+ coapPort: parseInt(coapPort ?? `5684`, 10)
82
+ };
83
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/nrfcloud-api-helpers",
3
- "version": "6.0.466",
3
+ "version": "6.0.467",
4
4
  "description": "Helper functions for integrating nRF Cloud APIs in AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "test": "node --no-warnings --experimental-transform-types --test \"!(node_modules|e2e-tests|integration-tests)/**/*.spec.ts\"",
16
16
  "prepare": "husky",
17
- "prepublishOnly": "node --experimental-strip-types ./.npm/compile.ts && npx tsc -P ./.npm/tsconfig.npm.json --outDir ./npm"
17
+ "prepublishOnly": "node --experimental-strip-types ./.npm/compile.ts && npx tsgo -P ./.npm/tsconfig.npm.json --outDir ./npm"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",