opencode-google-auth 0.0.7 → 0.0.9
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/package.json +1 -1
- package/src/main.ts +26 -2
- package/src/services/session.ts +1 -0
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -19,6 +19,7 @@ const fetchModelsDev = Effect.gen(function* () {
|
|
|
19
19
|
|
|
20
20
|
const customFetch = Effect.fn(function* (input: FetchInput, init: FetchInit) {
|
|
21
21
|
const config = yield* ProviderConfig
|
|
22
|
+
const session = yield* Session
|
|
22
23
|
|
|
23
24
|
let lastResponse: Response | null = null
|
|
24
25
|
|
|
@@ -27,12 +28,35 @@ const customFetch = Effect.fn(function* (input: FetchInput, init: FetchInit) {
|
|
|
27
28
|
yield* Effect.log("Input", input)
|
|
28
29
|
yield* Effect.log("Init", init)
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
let finalInitObj: FetchInit
|
|
32
|
+
const [finalInput, finalInit0] = config.requestTransform?.(input, init) ?? [
|
|
31
33
|
input,
|
|
32
34
|
init,
|
|
33
35
|
]
|
|
36
|
+
if (finalInit0 !== undefined) {
|
|
37
|
+
finalInitObj = finalInit0
|
|
38
|
+
} else if (init !== undefined) {
|
|
39
|
+
finalInitObj = init
|
|
40
|
+
} else {
|
|
41
|
+
finalInitObj = {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const accessToken = yield* session.getAccessToken
|
|
45
|
+
|
|
46
|
+
const authHeaders: Record<string, string> = {}
|
|
47
|
+
if (finalInitObj.headers) {
|
|
48
|
+
for (const [key, value] of Object.entries(finalInitObj.headers)) {
|
|
49
|
+
authHeaders[key] = value as string
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
authHeaders.Authorization = `Bearer ${accessToken}`
|
|
53
|
+
|
|
54
|
+
const authInit: FetchInit = {
|
|
55
|
+
...finalInitObj,
|
|
56
|
+
headers: authHeaders,
|
|
57
|
+
}
|
|
34
58
|
|
|
35
|
-
const response = yield* Effect.promise(() => fetch(finalInput,
|
|
59
|
+
const response = yield* Effect.promise(() => fetch(finalInput, authInit))
|
|
36
60
|
|
|
37
61
|
// On 429 or 403, try next endpoint
|
|
38
62
|
if (response.status === 429 || response.status === 403) {
|