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

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 (63) hide show
  1. package/npm/api/DeviceShadow.js +32 -0
  2. package/npm/api/FetchError.js +9 -0
  3. package/npm/{src/api → api}/bulkOps.d.ts +5 -3
  4. package/npm/api/bulkOps.js +22 -0
  5. package/npm/{src/api → api}/cancelFOTAJob.d.ts +1 -1
  6. package/npm/api/cancelFOTAJob.js +15 -0
  7. package/npm/api/createAccountDevice.d.ts +7 -0
  8. package/npm/api/createAccountDevice.js +25 -0
  9. package/npm/{src/api → api}/createFOTAJob.d.ts +4 -3
  10. package/npm/api/createFOTAJob.js +32 -0
  11. package/npm/api/deleteAccountDevice.js +9 -0
  12. package/npm/api/devices.d.ts +98 -0
  13. package/npm/api/devices.js +98 -0
  14. package/npm/api/export.js +18 -0
  15. package/npm/{src/api → api}/getAccountInfo.d.ts +9 -2
  16. package/npm/api/getAccountInfo.js +20 -0
  17. package/npm/{src/api → api}/getCurrentMonthlyCosts.d.ts +1 -1
  18. package/npm/api/getCurrentMonthlyCosts.js +22 -0
  19. package/npm/api/getDeviceShadow.d.ts +28 -0
  20. package/npm/api/getDeviceShadow.js +42 -0
  21. package/npm/{src/api → api}/getFOTABundles.d.ts +11 -3
  22. package/npm/api/getFOTABundles.js +101 -0
  23. package/npm/{src/api → api}/getFOTAJob.d.ts +23 -3
  24. package/npm/api/getFOTAJob.js +114 -0
  25. package/npm/{src/api → api}/getLocationHistory.d.ts +24 -5
  26. package/npm/api/getLocationHistory.js +118 -0
  27. package/npm/{src/api → api}/groundFix.d.ts +8 -4
  28. package/npm/api/groundFix.js +38 -0
  29. package/npm/{src/api → api}/serviceToken.d.ts +2 -2
  30. package/npm/api/serviceToken.js +20 -0
  31. package/npm/api/slashless.js +1 -0
  32. package/npm/{src/api → api}/validatedFetch.d.ts +6 -4
  33. package/npm/api/validatedFetch.js +58 -0
  34. package/npm/settings/export.js +5 -0
  35. package/npm/settings/getAllAccounts.js +9 -0
  36. package/npm/settings/getAllAccountsSettings.js +13 -0
  37. package/npm/settings/groupByAccount.js +16 -0
  38. package/npm/settings/scope.js +6 -0
  39. package/npm/{src/settings → settings}/settings.d.ts +7 -13
  40. package/npm/settings/settings.js +83 -0
  41. package/package.json +2 -2
  42. package/npm/src/api/createAccountDevice.d.ts +0 -13
  43. package/npm/src/api/devices.d.ts +0 -78
  44. package/npm/src/api/getDeviceShadow.d.ts +0 -25
  45. /package/npm/{src/api → api}/DeviceShadow.d.ts +0 -0
  46. /package/npm/{src/api → api}/DeviceShadow.spec.d.ts +0 -0
  47. /package/npm/{src/api → api}/FetchError.d.ts +0 -0
  48. /package/npm/{src/api → api}/deleteAccountDevice.d.ts +0 -0
  49. /package/npm/{src/api → api}/export.d.ts +0 -0
  50. /package/npm/{src/api → api}/getAccountInfo.spec.d.ts +0 -0
  51. /package/npm/{src/api → api}/getCurrentMonthlyCosts.spec.d.ts +0 -0
  52. /package/npm/{src/api → api}/getDeviceShadow.spec.d.ts +0 -0
  53. /package/npm/{src/api → api}/getFOTABundle.spec.d.ts +0 -0
  54. /package/npm/{src/api → api}/getLocationHistory.spec.d.ts +0 -0
  55. /package/npm/{src/api → api}/slashless.d.ts +0 -0
  56. /package/npm/{src/api → api}/slashless.spec.d.ts +0 -0
  57. /package/npm/{src/api → api}/validatedFetch.spec.d.ts +0 -0
  58. /package/npm/{src/settings → settings}/export.d.ts +0 -0
  59. /package/npm/{src/settings → settings}/getAllAccounts.d.ts +0 -0
  60. /package/npm/{src/settings → settings}/getAllAccountsSettings.d.ts +0 -0
  61. /package/npm/{src/settings → settings}/groupByAccount.d.ts +0 -0
  62. /package/npm/{src/settings → settings}/groupByAccount.spec.d.ts +0 -0
  63. /package/npm/{src/settings → settings}/scope.d.ts +0 -0
@@ -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.468",
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 && mv npm/src/* npm"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -1,13 +0,0 @@
1
- import { type Static } from '@sinclair/typebox';
2
- /**
3
- * @link https://api.nrfcloud.com/v1/#tag/Account-Devices/operation/CreateAccountDevice
4
- */
5
- declare const CertificateCredentials: import("@sinclair/typebox").TObject<{
6
- clientCert: import("@sinclair/typebox").TString;
7
- privateKey: import("@sinclair/typebox").TString;
8
- }>;
9
- export declare const createAccountDevice: ({ apiKey, endpoint, }: {
10
- apiKey: string;
11
- endpoint: URL;
12
- }) => Promise<Static<typeof CertificateCredentials>>;
13
- export {};
@@ -1,78 +0,0 @@
1
- import { type Static } from '@sinclair/typebox';
2
- import { DeviceShadow } from './DeviceShadow.ts';
3
- import type { FetchError } from './FetchError.ts';
4
- import { type ValidationError } from './validatedFetch.ts';
5
- declare const Devices: import("@sinclair/typebox").TObject<{
6
- total: import("@sinclair/typebox").TInteger;
7
- items: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
8
- id: import("@sinclair/typebox").TString;
9
- $meta: import("@sinclair/typebox").TObject<{
10
- createdAt: import("@sinclair/typebox").TString;
11
- updatedAt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
12
- }>;
13
- state: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
14
- reported: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
15
- desired: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
16
- version: import("@sinclair/typebox").TNumber;
17
- metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>;
18
- }>>;
19
- }>>;
20
- }>;
21
- /**
22
- * firmware types supported by a device for FOTA
23
- */
24
- export declare enum FwType {
25
- APP = "APP",
26
- MODEM = "MODEM",
27
- BOOT = "BOOT",
28
- SOFTDEVICE = "SOFTDEVICE",
29
- BOOTLOADER = "BOOTLOADER",
30
- MDM_FULL = "MDM_FULL"
31
- }
32
- export declare const devices: ({ endpoint, apiKey, }: {
33
- endpoint: URL;
34
- apiKey: string;
35
- }, fetchImplementation?: typeof fetch) => {
36
- list: () => Promise<{
37
- error: FetchError | ValidationError;
38
- } | {
39
- result: Static<typeof Devices>;
40
- }>;
41
- get: (id: string) => Promise<{
42
- error: FetchError | ValidationError;
43
- } | {
44
- result: Static<typeof DeviceShadow>;
45
- }>;
46
- updateState: (id: string, state: {
47
- desired?: Record<string, any>;
48
- reported?: Record<string, any>;
49
- }) => Promise<{
50
- error: FetchError | ValidationError;
51
- } | {
52
- success: boolean;
53
- }>;
54
- register: (devices: {
55
- deviceId: string;
56
- certPem: string;
57
- subType?: string;
58
- tags?: string[];
59
- /**
60
- * A list of pipe-delimited firmware types that each device supports for FOTA (e.g., APP|MODEM)
61
- *
62
- * Defaults to all supported (APP|MODEM|BOOT|SOFTDEVICE|BOOTLOADER|MDM_FULL)
63
- *
64
- * @default 'APP|MODEM|BOOT|SOFTDEVICE|BOOTLOADER|MDM_FULL'
65
- */
66
- fwTypes?: FwType[];
67
- }[]) => Promise<{
68
- error: FetchError | ValidationError;
69
- } | {
70
- bulkOpsRequestId: string;
71
- }>;
72
- remove: (deviceId: string) => Promise<{
73
- error: FetchError | ValidationError;
74
- } | {
75
- success: boolean;
76
- }>;
77
- };
78
- export {};
@@ -1,25 +0,0 @@
1
- import { type Static } from '@sinclair/typebox';
2
- import type { FetchError } from './FetchError.ts';
3
- import type { ValidationError } from './validatedFetch.ts';
4
- declare const DeviceShadows: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
5
- id: import("@sinclair/typebox").TString;
6
- $meta: import("@sinclair/typebox").TObject<{
7
- createdAt: import("@sinclair/typebox").TString;
8
- updatedAt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
9
- }>;
10
- state: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
11
- reported: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
12
- desired: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
13
- version: import("@sinclair/typebox").TNumber;
14
- metadata: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>;
15
- }>>;
16
- }>>;
17
- export declare const getDeviceShadow: ({ endpoint, apiKey, }: {
18
- endpoint: URL;
19
- apiKey: string;
20
- }, fetchImplementation?: typeof fetch) => ((devices: string[]) => Promise<{
21
- shadows: Static<typeof DeviceShadows>;
22
- } | {
23
- error: FetchError | ValidationError;
24
- }>);
25
- export {};
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