Skip to content

Commit f08a3b9

Browse files
authored
feat: support unlogged api (#478)
1 parent 4bf5e67 commit f08a3b9

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/auto-drive/src/api/handler.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { getDownloadServiceUrl, getNetworkUrl } from './networks'
33
import { AuthProvider, AutoDriveApiHandler, ConnectionOptions } from './types'
44

55
const createSendRequest =
6-
(baseUrl: string, provider: AuthProvider, apiKey: string) =>
6+
(baseUrl: string, provider: AuthProvider | null, apiKey: string | null) =>
77
async (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => {
88
const headers = new Headers({
99
...Object.fromEntries(request.headers?.entries() || []),
10-
'x-auth-provider': provider,
11-
Authorization: `Bearer ${apiKey}`,
10+
...(provider ? { 'x-auth-provider': provider } : {}),
11+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
1212
'x-auto-sdk-version': version,
1313
'User-Agent': `AutoDrive/${version}`,
1414
})
@@ -36,9 +36,6 @@ export const createApiRequestHandler = ({
3636
if (!downloadBaseUrl) {
3737
throw new Error('No download base URL provided')
3838
}
39-
if (!apiKey) {
40-
throw new Error('No API key provided')
41-
}
4239

4340
const api = {
4441
sendAPIRequest: createSendRequest(baseUrl, provider, apiKey),

packages/auto-drive/src/api/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ export type AuthProvider = ApiKeyAuthProvider | 'oauth'
294294

295295
export type ConnectionOptions =
296296
| {
297-
provider?: AuthProvider
298-
apiKey?: string
297+
provider?: AuthProvider | null
298+
apiKey: string | null
299299
apiUrl?: null
300300
downloadServiceUrl?: null
301301
network: AutoDriveNetwork
302302
}
303303
| {
304-
provider?: AuthProvider
305-
apiKey?: string
304+
provider?: AuthProvider | null
305+
apiKey: string | null
306306
apiUrl: string
307307
downloadServiceUrl?: string
308308
network?: null

0 commit comments

Comments
 (0)