Skip to content

Commit 21b6694

Browse files
committed
chore: change casing of lib folder
1 parent d68e1c5 commit 21b6694

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

samples/gauge/Lib/navigraph.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { DataStore } from "@microsoft/msfs-sdk"
2+
import { initializeApp, NavigraphApp, Scope } from "@navigraph/app"
3+
import { getAuth } from "@navigraph/auth"
4+
import { getChartsAPI } from "@navigraph/charts"
5+
import { getPackagesAPI } from "@navigraph/packages"
6+
7+
const config: NavigraphApp = {
8+
clientId: process.env.CLIENT_ID,
9+
clientSecret: process.env.CLIENT_SECRET,
10+
scopes: [Scope.FMSDATA],
11+
}
12+
13+
if (!config.clientId || config.clientId.includes("<")) {
14+
alert("Please add your client credentials in lib/navigraph.ts.")
15+
}
16+
17+
initializeApp(config)
18+
19+
// Wait 1s before accessing datastorage
20+
// This is a potential workaround for the issue where datastorage does not deliver credentials on startup.
21+
const dataStoreInit = new Promise(resolve => setTimeout(resolve, 1000))
22+
23+
const isNavigraphClient = config.clientId.includes("navigraph")
24+
const clientPrefix = isNavigraphClient ? "NG" : config.clientId.toUpperCase().replace("-", "_") + "_NG"
25+
26+
export const AUTH_STORAGE_KEYS = {
27+
accessToken: `${clientPrefix}_ACCESS_TOKEN`,
28+
refreshToken: `${clientPrefix}_REFRESH_TOKEN`,
29+
} as const
30+
31+
export const auth = getAuth({
32+
storage: {
33+
getItem: key => dataStoreInit.then(() => DataStore.get(key)?.toString() ?? null),
34+
setItem: (key, value) => DataStore.set(key, value),
35+
},
36+
keys: AUTH_STORAGE_KEYS,
37+
})
38+
39+
export const charts = getChartsAPI()
40+
41+
export const packages = getPackagesAPI()

0 commit comments

Comments
 (0)