Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
export { enableConsoleLogger, setLogger } from './internal/logger'
export type { Logger } from './internal/logger/logger'
export { createClient, createAdvancedClient } from './scw/client'
export { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from './scw/constants'
export type { Client } from './scw/client'
export type { Profile } from './scw/client-ini-profile'
export type { Settings } from './scw/client-settings'
Expand Down
22 changes: 19 additions & 3 deletions packages/client/src/scw/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ import {
import type { RequestInterceptor } from '../internal/interceptors/types'
import { assertValidAuthenticationSecrets } from './client-ini-profile'
import type { AuthenticationSecrets } from './client-ini-profile'

const SESSION_HEADER_KEY = 'x-session-token'
const AUTH_HEADER_KEY = 'x-auth-token'
import { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from './constants'

interface TokenAccessor {
(): Promise<string | undefined>
}

interface AddSessionHeader {
request: Request
getAsyncToken: () => Promise<string | undefined>
}
/**
* Add an JWT Session Header to a request through an interceptor.
*
* @param request - The request to modify
* @param getJwt - The session value
* @returns The Request interceptor
*
*/
export const addSessionHeader = async ({
request,
getAsyncToken,
}: AddSessionHeader) =>
addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getAsyncToken)({ request })

/**
* Authenticates with a session token.
*
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/scw/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pkg from '../../package.json'

export const { version } = pkg

export const userAgent = `scaleway-sdk-js/${version}`

export const SESSION_HEADER_KEY = 'x-session-token'
export const AUTH_HEADER_KEY = 'x-auth-token'
1 change: 1 addition & 0 deletions packages/client/src/scw/locality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export type Zone =
| 'nl-ams-3'
| 'pl-waw-1'
| 'pl-waw-2'
| 'pl-waw-3'
| (string & {})
/* eslint-enable @typescript-eslint/ban-types */
Loading