@hello.nrfcloud.com/nrfcloud-api-helpers 5.2.37 → 5.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/api/devices.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Static } from '@sinclair/typebox';
|
|
2
|
-
import { type ValidationError } from './validatedFetch.js';
|
|
3
2
|
import { DeviceShadow } from './DeviceShadow.js';
|
|
4
3
|
import type { FetchError } from './FetchError.js';
|
|
4
|
+
import { type ValidationError } from './validatedFetch.js';
|
|
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<{
|
|
@@ -69,5 +69,10 @@ export declare const devices: ({ endpoint, apiKey, }: {
|
|
|
69
69
|
} | {
|
|
70
70
|
bulkOpsRequestId: string;
|
|
71
71
|
}>;
|
|
72
|
+
remove: (deviceId: string) => Promise<{
|
|
73
|
+
error: FetchError | ValidationError;
|
|
74
|
+
} | {
|
|
75
|
+
success: boolean;
|
|
76
|
+
}>;
|
|
72
77
|
};
|
|
73
78
|
export {};
|
package/dist/api/devices.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
|
-
import { slashless } from './slashless.js';
|
|
3
|
-
import { validatedFetch } from './validatedFetch.js';
|
|
4
2
|
import { DeviceShadow } from './DeviceShadow.js';
|
|
5
3
|
import { toFetchError } from './FetchError.js';
|
|
4
|
+
import { slashless } from './slashless.js';
|
|
5
|
+
import { validatedFetch } from './validatedFetch.js';
|
|
6
6
|
const Page = (Item) => Type.Object({
|
|
7
7
|
total: Type.Integer(),
|
|
8
8
|
items: Type.Array(Item),
|
|
@@ -80,5 +80,14 @@ export const devices = ({ endpoint, apiKey, }, fetchImplementation) => {
|
|
|
80
80
|
return maybeResult;
|
|
81
81
|
return { bulkOpsRequestId: maybeResult.result.bulkOpsRequestId };
|
|
82
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
|
+
},
|
|
83
92
|
};
|
|
84
93
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Static, type
|
|
1
|
+
import { type Static, type TSchema } from '@sinclair/typebox';
|
|
2
2
|
import type { ValueError } from '@sinclair/typebox/compiler';
|
|
3
3
|
import type { FetchError } from './FetchError.js';
|
|
4
4
|
export declare class ValidationError extends Error {
|
|
@@ -9,7 +9,7 @@ export declare class ValidationError extends Error {
|
|
|
9
9
|
export declare const validatedFetch: ({ endpoint, apiKey }: {
|
|
10
10
|
apiKey: string;
|
|
11
11
|
endpoint: URL;
|
|
12
|
-
}, fetchImplementation?: typeof fetch) => <Schema extends
|
|
12
|
+
}, fetchImplementation?: typeof fetch) => <Schema extends TSchema>(params: ({
|
|
13
13
|
resource: string;
|
|
14
14
|
} | {
|
|
15
15
|
resource: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {} from '@sinclair/typebox';
|
|
2
|
-
import { slashless } from './slashless.js';
|
|
3
1
|
import { validateWithTypeBox } from '@hello.nrfcloud.com/proto';
|
|
2
|
+
import {} from '@sinclair/typebox';
|
|
4
3
|
import { toFetchError } from './FetchError.js';
|
|
4
|
+
import { slashless } from './slashless.js';
|
|
5
5
|
export class ValidationError extends Error {
|
|
6
6
|
errors;
|
|
7
7
|
isValidationError = true;
|
|
@@ -23,6 +23,8 @@ const fetchData = (fetchImplementation) => async (...args) => {
|
|
|
23
23
|
const response = await (fetchImplementation ?? fetch)(...args);
|
|
24
24
|
if (!response.ok)
|
|
25
25
|
throw await toFetchError(response);
|
|
26
|
+
if (response.headers?.get('content-length') === '0')
|
|
27
|
+
return undefined;
|
|
26
28
|
return response.json();
|
|
27
29
|
};
|
|
28
30
|
export const validatedFetch = ({ endpoint, apiKey }, fetchImplementation) => async (params, schema) => {
|
|
@@ -109,6 +109,20 @@ void describe('validatedFetch()', () => {
|
|
|
109
109
|
assert.equal('result' in res, false);
|
|
110
110
|
assert.deepEqual('error' in res && res.error, new FetchError(400, 'Bad Request'));
|
|
111
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
|
+
});
|
|
112
126
|
});
|
|
113
127
|
void describe('JSONPayload()', () => {
|
|
114
128
|
void it('should convert a an object to a payload definition to be used in validatedFetch', () => assert.deepEqual(JSONPayload({ foo: 'bar' }), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hello.nrfcloud.com/nrfcloud-api-helpers",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Helper functions for integrating nRF Cloud APIs in AWS lambdas written in TypeScript.",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": {
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@aws-sdk/client-dynamodb": "^3.614.0",
|
|
86
86
|
"@aws-sdk/client-ssm": "^3.614.0",
|
|
87
87
|
"@aws-sdk/util-dynamodb": "^3.614.0",
|
|
88
|
-
"@bifravst/aws-ssm-settings-helpers": "^1.1.
|
|
88
|
+
"@bifravst/aws-ssm-settings-helpers": "^1.1.43",
|
|
89
89
|
"@hello.nrfcloud.com/proto": "^14.1.7",
|
|
90
90
|
"@sinclair/typebox": "^0.32.34"
|
|
91
91
|
}
|