Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit a65a7b6

Browse files
committed
style: reformat source
1 parent 6e6a0eb commit a65a7b6

File tree

9 files changed

+136
-143
lines changed

9 files changed

+136
-143
lines changed

cli/commands/create-ca-intermediate.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export const createCAIntermediateCommand = ({
3232

3333
const dpsConnString = await ioTHubDPSConnectionString()
3434

35-
const dpsClient = ProvisioningServiceClient.fromConnectionString(
36-
dpsConnString,
37-
)
35+
const dpsClient =
36+
ProvisioningServiceClient.fromConnectionString(dpsConnString)
3837

3938
const enrollmentGroupId = `nrfassettracker-${id}`
4039

@@ -82,6 +81,5 @@ export const createCAIntermediateCommand = ({
8281
'node cli create-device-cert',
8382
)
8483
},
85-
help:
86-
'Creates a CA intermediate certificate registers it with an IoT Device Provisioning Service enrollment group',
84+
help: 'Creates a CA intermediate certificate registers it with an IoT Device Provisioning Service enrollment group',
8785
})

cli/commands/create-ca-root.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ export const createCARootCommand = ({
5454
resourceGroup,
5555
dpsName,
5656
)
57-
const {
58-
properties,
59-
} = await armDpsClient.dpsCertificate.generateVerificationCode(
60-
certificateName,
61-
etag as string,
62-
resourceGroup,
63-
dpsName,
64-
)
57+
const { properties } =
58+
await armDpsClient.dpsCertificate.generateVerificationCode(
59+
certificateName,
60+
etag as string,
61+
resourceGroup,
62+
dpsName,
63+
)
6564

6665
if (properties?.verificationCode === undefined) {
6766
throw new Error(`Failed to generate verification code`)
@@ -84,6 +83,5 @@ export const createCARootCommand = ({
8483
'node cli proof-ca-root-possession',
8584
)
8685
},
87-
help:
88-
'Creates a CA root certificate and registers it with the IoT Device Provisioning Service',
86+
help: 'Creates a CA root certificate and registers it with the IoT Device Provisioning Service',
8987
})

cli/commands/proof-ca-possession.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@ export const proofCARootPossessionCommand = ({
5555
'node cli create-ca-intermediate',
5656
)
5757
},
58-
help:
59-
'Verifies the root CA certificate which is registered with the Device Provisioning System',
58+
help: 'Verifies the root CA certificate which is registered with the Device Provisioning System',
6059
})

cli/iot/generateDeviceCertificate.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ export const generateDeviceCertificate = async ({
3838
deviceId,
3939
})
4040

41-
const [
42-
intermediatePrivateKey,
43-
intermediateCert,
44-
rootCert,
45-
] = await Promise.all([
46-
fs.readFile(caIntermediateFiles.privateKey, 'utf-8'),
47-
fs.readFile(caIntermediateFiles.cert, 'utf-8'),
48-
fs.readFile(caRootFiles.cert, 'utf-8'),
49-
])
41+
const [intermediatePrivateKey, intermediateCert, rootCert] =
42+
await Promise.all([
43+
fs.readFile(caIntermediateFiles.privateKey, 'utf-8'),
44+
fs.readFile(caIntermediateFiles.cert, 'utf-8'),
45+
fs.readFile(caRootFiles.cert, 'utf-8'),
46+
])
5047

5148
await run({
5249
command: 'openssl',

geolocateCellFromUnwiredLabs/resolveFromAPI.ts

+84-86
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,100 @@ import { parse } from 'url'
22
import { request as nodeRequest } from 'https'
33
import { left, right, Either } from 'fp-ts/lib/Either'
44

5-
export const resolveFromAPI = ({
6-
apiKey,
7-
endpoint,
8-
}: {
9-
apiKey: string
10-
endpoint: string
11-
}) => async (cell: {
12-
area: number
13-
mccmnc: number
14-
cell: number
15-
}): Promise<Either<Error, { lat: number; lng: number; accuracy: number }>> => {
16-
try {
17-
const { hostname, path } = parse(endpoint)
5+
export const resolveFromAPI =
6+
({ apiKey, endpoint }: { apiKey: string; endpoint: string }) =>
7+
async (cell: {
8+
area: number
9+
mccmnc: number
10+
cell: number
11+
}): Promise<
12+
Either<Error, { lat: number; lng: number; accuracy: number }>
13+
> => {
14+
try {
15+
const { hostname, path } = parse(endpoint)
1816

19-
// See https://eu1.unwiredlabs.com/docs-html/index.html#response
20-
const {
21-
status,
22-
lat,
23-
lon,
24-
accuracy,
25-
}: {
26-
status: 'ok' | 'error'
27-
message?: string
28-
balance: number
29-
balance_slots?: number
30-
lat: number
31-
lon: number
32-
accuracy: number
33-
aged?: boolean
34-
fallback?: 'ipf' | 'lacf' | 'scf'
35-
// address: string (not requested)
36-
// address_details?: string (not requested)
37-
} = await new Promise((resolve, reject) => {
38-
const options = {
39-
host: hostname,
40-
path: `${path?.replace(/\/*$/, '') ?? ''}/v2/process.php`,
41-
method: 'POST',
42-
agent: false,
43-
}
17+
// See https://eu1.unwiredlabs.com/docs-html/index.html#response
18+
const {
19+
status,
20+
lat,
21+
lon,
22+
accuracy,
23+
}: {
24+
status: 'ok' | 'error'
25+
message?: string
26+
balance: number
27+
balance_slots?: number
28+
lat: number
29+
lon: number
30+
accuracy: number
31+
aged?: boolean
32+
fallback?: 'ipf' | 'lacf' | 'scf'
33+
// address: string (not requested)
34+
// address_details?: string (not requested)
35+
} = await new Promise((resolve, reject) => {
36+
const options = {
37+
host: hostname,
38+
path: `${path?.replace(/\/*$/, '') ?? ''}/v2/process.php`,
39+
method: 'POST',
40+
agent: false,
41+
}
4442

45-
const req = nodeRequest(options, (res) => {
46-
console.debug(
47-
JSON.stringify({
48-
response: {
49-
statusCode: res.statusCode,
50-
headers: res.headers,
51-
},
52-
}),
53-
)
54-
res.on('data', (d) => {
55-
const responseBody = JSON.parse(d.toString())
43+
const req = nodeRequest(options, (res) => {
5644
console.debug(
5745
JSON.stringify({
58-
responseBody,
46+
response: {
47+
statusCode: res.statusCode,
48+
headers: res.headers,
49+
},
5950
}),
6051
)
61-
if (res.statusCode === undefined) {
62-
return reject(new Error('No response received!'))
63-
}
64-
if (res.statusCode >= 400) {
65-
reject(new Error(responseBody.description))
66-
}
67-
resolve(responseBody)
52+
res.on('data', (d) => {
53+
const responseBody = JSON.parse(d.toString())
54+
console.debug(
55+
JSON.stringify({
56+
responseBody,
57+
}),
58+
)
59+
if (res.statusCode === undefined) {
60+
return reject(new Error('No response received!'))
61+
}
62+
if (res.statusCode >= 400) {
63+
reject(new Error(responseBody.description))
64+
}
65+
resolve(responseBody)
66+
})
6867
})
69-
})
7068

71-
req.on('error', (e) => {
72-
reject(new Error(e.message))
73-
})
69+
req.on('error', (e) => {
70+
reject(new Error(e.message))
71+
})
7472

75-
const payload = JSON.stringify({
76-
token: apiKey,
77-
radio: 'lte',
78-
mcc: Math.floor(cell.mccmnc / 100),
79-
mnc: cell.mccmnc % 100,
80-
cells: [
81-
{
82-
lac: cell.area,
83-
cid: cell.cell,
84-
},
85-
],
73+
const payload = JSON.stringify({
74+
token: apiKey,
75+
radio: 'lte',
76+
mcc: Math.floor(cell.mccmnc / 100),
77+
mnc: cell.mccmnc % 100,
78+
cells: [
79+
{
80+
lac: cell.area,
81+
cid: cell.cell,
82+
},
83+
],
84+
})
85+
console.log(payload.replace(apiKey, '***'))
86+
req.write(payload)
87+
req.end()
8688
})
87-
console.log(payload.replace(apiKey, '***'))
88-
req.write(payload)
89-
req.end()
90-
})
9189

92-
if (status === 'ok' && lat && lon) {
93-
return right({
94-
lat,
95-
lng: lon,
96-
accuracy,
97-
})
90+
if (status === 'ok' && lat && lon) {
91+
return right({
92+
lat,
93+
lng: lon,
94+
accuracy,
95+
})
96+
}
97+
return left(new Error(`Failed to resolve.`))
98+
} catch (err) {
99+
return left(err)
98100
}
99-
return left(new Error(`Failed to resolve.`))
100-
} catch (err) {
101-
return left(err)
102101
}
103-
}

lib/fromEnv.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export const fromEnv = <T extends Record<string, string>>(def: T) => (
2-
env: NodeJS.ProcessEnv,
3-
): Record<keyof T, string> =>
4-
Object.entries(def).reduce((res, [defKey, envKey]) => {
5-
const v = env[envKey]
6-
if (v === undefined || v.length === 0)
7-
throw new Error(`${envKey} is not defined in environment!`)
8-
return { ...res, [defKey]: v }
9-
}, {} as Record<keyof T, string>)
1+
export const fromEnv =
2+
<T extends Record<string, string>>(def: T) =>
3+
(env: NodeJS.ProcessEnv): Record<keyof T, string> =>
4+
Object.entries(def).reduce((res, [defKey, envKey]) => {
5+
const v = env[envKey]
6+
if (v === undefined || v.length === 0)
7+
throw new Error(`${envKey} is not defined in environment!`)
8+
return { ...res, [defKey]: v }
9+
}, {} as Record<keyof T, string>)

lib/http.ts

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import { Context } from '@azure/functions'
22
import { log } from './log'
33

4-
export const result = (context: Context) => (
5-
result: unknown,
6-
status = 200,
7-
): {
8-
headers: Record<string, string>
9-
status: number
10-
body: unknown
11-
} => {
12-
const response = {
13-
headers: {
14-
'Content-Type': 'application/json; charset=uft-8',
15-
},
16-
status,
17-
body: result,
4+
export const result =
5+
(context: Context) =>
6+
(
7+
result: unknown,
8+
status = 200,
9+
): {
10+
headers: Record<string, string>
11+
status: number
12+
body: unknown
13+
} => {
14+
const response = {
15+
headers: {
16+
'Content-Type': 'application/json; charset=uft-8',
17+
},
18+
status,
19+
body: result,
20+
}
21+
log(context)({ result })
22+
return response
1823
}
19-
log(context)({ result })
20-
return response
21-
}

lib/log.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Context } from '@azure/functions'
22

3-
export const log = (context: Context) => (...args: any[]) =>
4-
context.log(...args.map(arg => JSON.stringify(arg, null, 2)))
3+
export const log =
4+
(context: Context) =>
5+
(...args: any[]): void =>
6+
context.log(...args.map((arg) => JSON.stringify(arg, null, 2)))

storeDeviceUpgrade/storeDeviceUpgrade.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const blobServiceClient = new BlobServiceClient(
2222
`https://${fotaStorageAccountName}.blob.core.windows.net`,
2323
sharedKeyCredential,
2424
)
25-
const containerClient = blobServiceClient.getContainerClient(
26-
fotaStorageContainer,
27-
)
25+
const containerClient =
26+
blobServiceClient.getContainerClient(fotaStorageContainer)
2827

2928
const storeDeviceUpgrade: AzureFunction = async (
3029
context: Context,

0 commit comments

Comments
 (0)