export type CustomDeviceId = string; export type Latitude = number; export type Longitude = number; export type Accuracy = number; export type Altitude = number; export type Speed = number; export type Heading = number; export type GpsRequest = {lat: Latitude, lon: Longitude, acc?: Accuracy | undefined, alt?: Altitude | undefined, spd?: Speed | undefined, hdg?: Heading | undefined} | {[key: string]: unknown}; export type NmeaSentence = string; export type CreateApiLocationGnssArgs = {'x-custom-device-id'?: CustomDeviceId | undefined, body: GpsRequest | NmeaSentence}; export type CreateApiLocationGnssOptions = {baseUrl?: string | undefined, OrganizationAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * RecordGnssCoordinates * * POST /location/gnss * * Also accepts auth: JSON Web Token */ export const createApiLocationGnss = async (args: CreateApiLocationGnssArgs, options?: CreateApiLocationGnssOptions) => { const {baseUrl = "https://api.nrfcloud.com/v1", fetch: fetchFn = fetch, OrganizationAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['x-custom-device-id'] != null) headers.set("x-custom-device-id", String(args['x-custom-device-id'])) if (OrganizationAuthToken !== undefined) headers.set('authorization', `Bearer ${OrganizationAuthToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/location/gnss${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };