@hello.nrfcloud.com/nrfcloud-api-helpers 1.2.1 → 1.3.1
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/bulkOps.d.ts +17 -0
- package/dist/api/bulkOps.js +20 -0
- package/dist/api/groundFix.d.ts +25 -0
- package/dist/api/groundFix.js +21 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/serviceToken.d.ts +10 -0
- package/dist/api/serviceToken.js +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Static } from '@sinclair/typebox';
|
|
2
|
+
import { ValidationError } from './validatedFetch.js';
|
|
3
|
+
/**
|
|
4
|
+
* @link https://api.nrfcloud.com/v1/#tag/Bulk-Ops-Requests/operation/FetchBulkOpsRequest
|
|
5
|
+
*/
|
|
6
|
+
export declare const BulkOpsRequestType: import("@sinclair/typebox").TObject<{
|
|
7
|
+
bulkOpsRequestId: import("@sinclair/typebox").TString;
|
|
8
|
+
status: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"PENDING">, import("@sinclair/typebox").TLiteral<"IN_PROGRESS">, import("@sinclair/typebox").TLiteral<"FAILED">, import("@sinclair/typebox").TLiteral<"SUCCEEDED">]>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const bulkOpsRequests: ({ apiKey, endpoint, }: {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
endpoint: URL;
|
|
13
|
+
}, fetchImplementation?: typeof fetch) => (bulkOpsId: string) => Promise<{
|
|
14
|
+
error: Error | ValidationError;
|
|
15
|
+
} | {
|
|
16
|
+
result: Static<typeof BulkOpsRequestType>;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { ValidationError, 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
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Static } from '@sinclair/typebox';
|
|
2
|
+
import { ValidationError } from './validatedFetch.js';
|
|
3
|
+
/**
|
|
4
|
+
* @link https://api.nrfcloud.com/v1/#tag/Ground-Fix
|
|
5
|
+
*/
|
|
6
|
+
export declare const GroundFixType: import("@sinclair/typebox").TObject<{
|
|
7
|
+
lat: import("@sinclair/typebox").TNumber;
|
|
8
|
+
lon: import("@sinclair/typebox").TNumber;
|
|
9
|
+
uncertainty: import("@sinclair/typebox").TNumber;
|
|
10
|
+
fulfilledWith: import("@sinclair/typebox").TLiteral<"SCELL">;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const groundFix: ({ apiKey, endpoint, }: {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
endpoint: URL;
|
|
15
|
+
}, fetchImplementation?: typeof fetch) => (cell: {
|
|
16
|
+
mcc: string;
|
|
17
|
+
mnc: string;
|
|
18
|
+
eci: number;
|
|
19
|
+
tac: number;
|
|
20
|
+
rsrp: number;
|
|
21
|
+
}) => Promise<{
|
|
22
|
+
error: Error | ValidationError;
|
|
23
|
+
} | {
|
|
24
|
+
result: Static<typeof GroundFixType>;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { accuracy as TAccuracy, lat as TLat, lng as TLng, } from '@hello.nrfcloud.com/proto/hello';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { JSONPayload, ValidationError, validatedFetch, } from './validatedFetch.js';
|
|
4
|
+
/**
|
|
5
|
+
* @link https://api.nrfcloud.com/v1/#tag/Ground-Fix
|
|
6
|
+
*/
|
|
7
|
+
export const GroundFixType = Type.Object({
|
|
8
|
+
lat: TLat, // 63.41999531
|
|
9
|
+
lon: TLng, // 10.42999506
|
|
10
|
+
uncertainty: TAccuracy, // 2420
|
|
11
|
+
fulfilledWith: Type.Literal('SCELL'),
|
|
12
|
+
});
|
|
13
|
+
export const groundFix = ({ apiKey, endpoint, }, fetchImplementation) => async (cell) => {
|
|
14
|
+
const vf = validatedFetch({ endpoint, apiKey }, fetchImplementation);
|
|
15
|
+
return vf({
|
|
16
|
+
resource: 'location/ground-fix',
|
|
17
|
+
payload: JSONPayload({
|
|
18
|
+
lte: [cell],
|
|
19
|
+
}),
|
|
20
|
+
}, GroundFixType);
|
|
21
|
+
};
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @link https://api.nrfcloud.com/v1/#tag/Account/operation/GetServiceToken
|
|
3
|
+
*/
|
|
4
|
+
export declare const ServiceToken: import("@sinclair/typebox").TObject<{
|
|
5
|
+
token: import("@sinclair/typebox").TString;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const serviceToken: (fetchImplementation?: typeof fetch, onError?: (error: Error) => void) => ((args: {
|
|
8
|
+
apiEndpoint: URL;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
}) => Promise<string>);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { validatedFetch } from './validatedFetch.js';
|
|
3
|
+
/**
|
|
4
|
+
* @link https://api.nrfcloud.com/v1/#tag/Account/operation/GetServiceToken
|
|
5
|
+
*/
|
|
6
|
+
export const ServiceToken = Type.Object({
|
|
7
|
+
token: Type.String(),
|
|
8
|
+
});
|
|
9
|
+
export const serviceToken = (fetchImplementation, onError) => async ({ apiEndpoint, apiKey }) => {
|
|
10
|
+
const vf = validatedFetch({ endpoint: apiEndpoint, apiKey }, fetchImplementation);
|
|
11
|
+
const maybeResult = await vf({ resource: 'account/service-token' }, ServiceToken);
|
|
12
|
+
if ('error' in maybeResult) {
|
|
13
|
+
onError?.(maybeResult.error);
|
|
14
|
+
throw maybeResult.error;
|
|
15
|
+
}
|
|
16
|
+
return maybeResult.result.token;
|
|
17
|
+
};
|